成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

六-體系結(jié)構(gòu)Architecture-創(chuàng)新互聯(lián)

六-體系結(jié)構(gòu) Architecture

在這里插入圖片描述

站在用戶的角度思考問題,與客戶深入溝通,找到龍游網(wǎng)站設(shè)計與龍游網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、國際域名空間、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋龍游地區(qū)。

chapter 6 Architecture

MIPS Instruction Set — ECS Networking (pacific.edu)

6.1 Introduction

Four design principles:

  1. simplicity favors regularity

  2. make the common case fast

  3. smaller is faster

  4. good design demands good compromises

6.2 Assembly Language 匯編語言

MIPS Architecture - Microprocessor without interlocked piped stages architecture 簡單易學(xué),但不太實用

6.2.1 Instructions指令

add a, b, c

addmnemonic助記符

adestination operand目標(biāo)操作數(shù)

b,csource operands操作數(shù)

簡單設(shè)計:simplicity favors regularity

多條指令

a = b + c - dadd t, b, c sub a, t, d

加速常見情況:make the common case fast

編碼長度:

RISC(Reduced instruction set computer)

精簡指令集,擁有少量簡單的指令

CISC(Complex instruction set computers)

復(fù)雜指令集

6.2.2 Operands操作數(shù):Registers, Memory, and Constants

操作數(shù)的來源:寄存器/內(nèi)存
請?zhí)砑訄D片描述

寄存器

MIPS32有32個32位寄存器;比存儲器快1000倍

越小越快:Smaller is faster

  • $0 always contains the value 0 because this constant is so frequently used in computer programs.

  • 保存寄存器

  • 臨時變量寄存器

常數(shù)-立即數(shù) 存儲在指令里

存儲器-大但是慢

RISC的指令,只能作用在常數(shù)/寄存器上;MISC還能直接作用到寄存器中

字尋址存儲器:每32位數(shù)據(jù)字對應(yīng)一個唯一的32位地址
請?zhí)砑訄D片描述

MIPS實際使用的是字節(jié)尋址

6.3 Machine Language機器語言

三種匯編指令

6.3.1 R-Type Instructions 寄存器類型 6.3.2 I-Type Instructions 立即數(shù)類型 6.3.3 J-Type Instructions 跳轉(zhuǎn)類型

地址不是32位的嗎?j類型里addr是26位的??

請?zhí)砑訄D片描述

請?zhí)砑訄D片描述
請?zhí)砑訄D片描述

6.3.4 Interpreting Machine Language Code

機器→匯編

6.3.5 The Power of the Stored Program 存儲程序 - 通用計算能力 6.4 Programming編程 6.4.1 Arithmetic/Logical Instructions 算數(shù)/邏輯指令

1 邏輯按位操作:

  • and: 用于掩碼操作(Masking)

  • or: 用于組合操作(Combining)

  • nor: 或非,用于反相操作(Inverting)

請?zhí)砑訄D片描述

2 移位指令

3對立即數(shù)操作:

  • andi, ori, xori 0擴展

間接加載高位立即數(shù): lui

32-bit constants using load upper immediate (lui) and ori:

請?zhí)砑訄D片描述

4偽指令

  • nop: 不對處理器執(zhí)行產(chǎn)生影響,僅占用一條指令的時間空間,僅將PC推進到下一條指令

  • mv: 在寄存器之間傳遞數(shù)據(jù) mv $s0 $s7 → or $s0 $0 $s7

  • li: 加載立即數(shù)到目標(biāo)寄存器:先判斷位數(shù),在決定多條執(zhí)行指令

5 乘除法:用lo, hi存儲結(jié)果

  • 32*32乘法,得64位結(jié)果

    mult $s0, $s1

    結(jié)果保存在{hi, lo}

  • 32位除法,得32位商與余數(shù)

    div $s0, $s1

    商保存在lo, 余數(shù)保存在hi

  • 從lo/hi讀數(shù)

6.4.2 Branching分支 Execute instructions out of sequence

分支發(fā)生:taken;不發(fā)生 not taken

Types of branches:

1 Conditional條件分支

branch if equal (beq)beq $s0, $s1, target
branch if not equal (bne)

2 Unconditional無條件分支 → 跳轉(zhuǎn)指令jump

jump (j) 跳轉(zhuǎn)
jump register (jr) 跳轉(zhuǎn)寄存器
jump and link (jal) 跳轉(zhuǎn)和鏈接

# MIPS assembly
 addi   $s0, $0, 4      # $s0 = 0 + 4 = 4
 addi $s1, $0, 1      # $s1 = 0 + 1 = 1
 sll  $s1, $s1, 2     # $s1 = 1<< 2 = 4
 beq  $s0, $s1, target  # branch is taken
 addi $s1, $s1, 1       # not executed
 sub  $s1, $s1, $s0     # not executed

target:      # label
 add  $s1, $s1, $s0    # $s1 = 4 + 4 = 8
6.4.3 Conditional Statements 條件

1 if

2 if/else

3 switch/case

6.4.4 Getting Loopy 循環(huán)

1 while

2 for

3 量值比較

6.4.5 Arrays 數(shù)組

1

搞清楚訪問數(shù)據(jù)的大小

char (2bytes)或 longlong (8bytes)

操作字節(jié):

100000 (32) lb rt, imm(rs) load byte [rt] = SignExt ([Address]7:0)
6.4.6 Function Calls 函數(shù)調(diào)用

約定:

調(diào)用函數(shù)caller

將參數(shù)傳遞給被調(diào)用者:存在$a0 ~ $a3

跳轉(zhuǎn)到被調(diào)用者

jal

被調(diào)用函數(shù)callee

執(zhí)行函數(shù)

返回(結(jié)果)到調(diào)用者:存在$v0 ~ $v1

返回到調(diào)用點

不能破壞調(diào)用者的寄存器或內(nèi)存

jr

jal指令:

  1. 將下一條指令的地址存儲到返回地址寄存器$ra中(存下被調(diào)用函數(shù)要返回到的調(diào)用點)

  2. 跳轉(zhuǎn)到目標(biāo)指令

001001 (9)jal labeljump and link 跳轉(zhuǎn)并鏈接$ra = PC + 4, PC = JTA

jr指令:

把rs的內(nèi)容返回PC,即PC跳到rs存的地址

001000 (8)jr rsjump register 跳轉(zhuǎn)到存在rs地址PC = [rs]
int main(){simple();
    ...
}

void simple() return;
MIPS assembly code

0x00400200 main:     jal simple #調(diào)用函數(shù)
0x00400204         ...
...
0x00401020 simple:   jr  $ra    #返回
3 棧

但是破壞了調(diào)用函數(shù)的寄存器,因而要把寄存器原來的值存到內(nèi)存中,當(dāng)被調(diào)用函數(shù)返回后,才能夠內(nèi)存中恢復(fù)原來寄存器的值??梢允褂煤筮M先出(LIFO)的“棧”數(shù)據(jù)結(jié)構(gòu)存儲臨時變量。

棧的擴展與縮小:

棧指針$sp開始于高內(nèi)存地址,通過地址遞減來擴展棧空間

請?zhí)砑訄D片描述

函數(shù)如何使用棧

在函數(shù)修改寄存器前,將寄存器保存在棧中,返回前從棧中恢復(fù)這些寄存器。

  1. 創(chuàng)建棧空間

  2. 存儲寄存器

  3. 使用寄存器執(zhí)行函數(shù)

  4. 從棧中恢復(fù)寄存器原始值

  5. 回收??臻g

棧幀stack frame:函數(shù)為自己分配的棧空間

# $s0 = result, $sp為棧頂

diffofsums:
  //棧指針減少 3*4 位,用于存儲
  addi $sp, $sp, -12  # make space on stack
                      # to store 3 registers
  //保存現(xiàn)場
  sw   $s0, 8($sp)    # save $s0 on stack
  sw   $t0, 4($sp)    # save $t0 on stack
  sw   $t1, 0($sp)    # save $t1 on stack
  
  add  $t0, $a0, $a1  # $t0 = f + g
  add  $t1, $a2, $a3  # $t1 = h + i
  sub  $s0, $t0, $t1  # result = (f + g) - (h + i)
  add  $v0, $s0, $0   # put return value in $v0
  //恢復(fù)現(xiàn)場
  lw   $t1, 0($sp)    # restore $t1 from stack
  lw   $t0, 4($sp)    # restore $t0 from stack
  lw   $s0, 8($sp)    # restore $s0 from stack
  //恢復(fù)棧,棧平衡
  addi $sp, $sp, 12   # deallocate stack space
  //清除痕跡!->計算機安全
  jr   $ra            # return to caller

下圖展示了上述匯編代碼執(zhí)行時棧變化的示意圖

請?zhí)砑訄D片描述

4 受/不受保護的寄存器
  • 受保護寄存器(preserved):要么被調(diào)用函數(shù)不修改,若修改,則由被調(diào)用函數(shù)維護/ 保存(save)$s0 ~ $s7存有(調(diào)用函數(shù)的)局部變量,因此必須被調(diào)用函數(shù)保存
    $ra存有被調(diào)用函數(shù)要返回的地址,不能修改
    $sp棧指針,由被調(diào)用函數(shù)擴展與收縮,被調(diào)用函數(shù)保存
    $sp之上的??臻g:其他函數(shù)的棧幀,不能修改

  • 不受保護寄存器(nonpreserved):由調(diào)用函數(shù)維護/ 保存(save),可由被調(diào)用函數(shù)任意修改$t0 ~ $t9存放(調(diào)用函數(shù)的)臨時變量,可由被調(diào)用函數(shù)任意修改,由調(diào)用函數(shù)保存
    $a0 ~ $a3一般存調(diào)用函數(shù)要傳給被調(diào)用函數(shù)的參數(shù),一般會由被調(diào)用函數(shù)修改,由調(diào)用函數(shù)保存
    $v0 ~ $v1存有被調(diào)用函數(shù)的返回值,會由callee修改,由調(diào)用函數(shù)保存
    $sp之下的棧空間:callee自己分配的空間,有自己修改,由調(diào)用函數(shù)保存

被調(diào)用函數(shù)必須保存恢復(fù)任何要使用的受保護寄存器,可以隨意改變不受保護寄存器。

[外鏈圖片轉(zhuǎn)存失敗,源站可能有防盜鏈機制,建議將圖片保存下來直接上傳(img-xcsFeIDo-1669634365736)(image/image_aG9a8E36K4.png)]

5 遞歸函數(shù)調(diào)用
High-level code

int factorial(int n) {if (n<= 1)
    return 1;
  else
    return (n * factorial(n-1));
}
MIPS assembly code
// $a0
0x90 factorial: addi $sp, $sp, -8  # make room on stack

0x94            sw   $a0, 4($sp)   # store $a0
0x98            sw   $ra, 0($sp)   # store $ra

0x9C            addi $t0, $0, 2    # $t0 = 2
0xA0            slt  $t0, $a0, $t0 # n<= 1 ?
0xA4            beq  $t0, $0, else # no: go to else  
0xA8            addi $v0, $0, 1    # yes: return 1
0xAC            addi $sp, $sp, 8   # restore $sp
0xB0            jr   $ra           # return
0xB4      else: addi $a0, $a0, -1  # n = n - 1
0xB8            jal  factorial     # recursive call

0xBC            lw   $ra, 0($sp)   # restore $ra
0xC0            lw   $a0, 4($sp)   # restore $a0

0xC4            addi $sp, $sp, 8   # restore $sp
0xC8            mul  $v0, $a0, $v0 # n * factorial(n-1)
0xCC            jr   $ra           # return
對齊:MIPS不支持跨邊界訪問

lw對齊4字節(jié)邊界

lb不需要對齊,因為本身就以字節(jié)為單位

lh對齊2字節(jié)邊界

6.5 Addressing Modes尋址模式

The first three modes (register-only, immediate, and base addressing) define modes of reading and writing operands. The last two (PC-relative and pseudo-direct addressing) define modes of writing the program counter, PC.

1 Register-Only Addressing 寄存器尋址

Register-only addressing uses registers for all source and destination operands. All R-type instructions use register-only addressing.

2 Immediate Addressing 立即數(shù)尋址

Immediate addressing uses the 16-bit immediate along with registers asoperands. Some** I-type instructions**, such as add immediate (addi) and load upper immediate (lui), use immediate addressing.

16位有符號數(shù):$ -2^{15} $~ 2 15 ? 1 2^{15}-1 215?1

對于大立即數(shù):用偽匯編指令

邏輯運算-零擴展

算數(shù)運算-符號擴展

3 Base Addressing 基地址尋址

Memory access instructions, such as load word (lw) and store word (sw),use base addressing. The effective address of the memory operand isfound by adding the base address in register rs to the sign-extended16-bit offset found in the immediate field.

基址+符號擴展的立即數(shù)

lw $s4, 72($s0)
地址 = $0 + 72

超大數(shù)組尋址:分步處理

4 PC-Relative Addressing PC相對地址

Conditional branch instructions use PC-relative addressing to specify the new value of the PC if the branch is taken. The signed offset in the immediate field is added to the PC to obtain the new PC; hence, the branch destination address is said to be relative to the current PC.

0x10          beq    $t0, $0, else
0x14          addi   $v0, $0, 1 
0x18          addi   $sp, $sp, i 
0x1C          jr      $ra
0x20      else:    addi   $a0, $a0, -1
0x24          jal    factorial

若要條很遠(yuǎn)很遠(yuǎn)的地方:中間設(shè)置跳板

5 Pseudo-Direct Addressing 偽直接尋址 6.6 Compiling, Assembling, and Loading

編譯、匯編、加載

6.6.1 The Memory Map 內(nèi)存映射

請?zhí)砑訄D片描述
請?zhí)砑訄D片描述

1 The Text Segment 代碼段 2 The Global Data Segment 全局?jǐn)?shù)據(jù)段 3 The Dynamic Data Segment 動態(tài)數(shù)據(jù)段 4 The Reserved Segments 保留段 6.6.2 Translating and Start a Program

轉(zhuǎn)換成二進制代碼(可執(zhí)行文件) 開始執(zhí)行程序

1 Compilation編譯 2 Assembling匯編

請?zhí)砑訄D片描述

3 Linking鏈接

請?zhí)砑訄D片描述

4 Loading裝入

請?zhí)砑訄D片描述

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧

當(dāng)前標(biāo)題:六-體系結(jié)構(gòu)Architecture-創(chuàng)新互聯(lián)
地址分享:http://jinyejixie.com/article22/gpccc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計、建站公司、網(wǎng)站設(shè)計、微信小程序、電子商務(wù)、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

微信小程序開發(fā)
曲水县| 昌吉市| 盐亭县| 高尔夫| 鄂托克前旗| 康定县| 兖州市| 永顺县| 唐海县| 舞钢市| 敦煌市| 留坝县| 青田县| 徐闻县| 得荣县| 平舆县| 福泉市| 墨竹工卡县| 红河县| 营山县| 麦盖提县| 治县。| 靖边县| 张掖市| 安多县| 南乐县| 壤塘县| 睢宁县| 江达县| 乌拉特后旗| 萍乡市| 克山县| 离岛区| 富川| 乌拉特中旗| 开江县| 区。| 邵阳市| 阿拉善盟| 泰州市| 郴州市|