作業(yè)1—lab1指令集結構—計算機體系結構_第1頁
作業(yè)1—lab1指令集結構—計算機體系結構_第2頁
作業(yè)1—lab1指令集結構—計算機體系結構_第3頁
作業(yè)1—lab1指令集結構—計算機體系結構_第4頁
作業(yè)1—lab1指令集結構—計算機體系結構_第5頁
已閱讀5頁,還剩2頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、Lab1 作業(yè)學號:12281166 姓名:崔雪瑩 Exercise 1: What will be 32-bit hex code for the above two examples.1. LW R2, 100(R3) 指令為讀指令,讀R3寄存器內容為首址,偏移地址為100的內容字,存到R2寄存器里,格式 LW rt, Imm(rs)。編碼為:100011 00011 00010 00000000 01100100Bit313029282726252423222120191817161514131211109876543210Field6-Bit Op Coders Fieldrt Fie

2、ld16-bit Immediate field100011000110001000000000011001002. SW R5, 100(R6) 指令為寫指令,將R5內容寫入以R6寄存器內容為首址,偏移地址為100的地址,格式 SW rt, Imm(rs)。編碼為:101011 00110 00101 00000000 01100100Bit313029282726252423222120191817161514131211109876543210Field6-Bit Op Coders Fieldrt Field16-bit Immediate field10101100110001010

3、000000001100100Exercise 2: Find 32-bit code for OR R7, R18, R12 and SUB R5, R4, R31 1. OR R7, R18, R12 位或操作,格式 OpCode rd, rs, rt編碼為:000000 10010 01100 00111 00000 100101Bit313029282726252423222120191817161514131211109876543210Field0 0 0 0 0 0rs Fieldrt Fieldrd fieldShift AmountFunction Field00000010

4、0100110000111000001001012. SUB R5, R4, R31 減法,格式 OpCode rd, rs, rt編碼為:000000 00100 11111 00101 00000 100010Bit313029282726252423222120191817161514131211109876543210Field0 0 0 0 0 0rs Fieldrt Fieldrd fieldShift AmountFunction Field00000000100111110010100000100010Exercise 3: Find 32-bit code for BNEQ

5、R7, R8, -5. 0000101 00111 01000 11111111 11111011 If the PC value for branch instruction is 124 what will be new value of PC if the branch is taken 124+4-5*4=108 .-5的補碼為 1111 1111 1111 1011 Bit313029282726252423222120191817161514131211109876543210Field000100 for BEQ 000101 for BNEQrs Fieldrt FieldBr

6、anch offset in Number of Instructions00010100111010001111111111111011Exercise 5: What is the 32-code for ADDI R7, R8, 600? 001000 01000 00111 0000 0010 0101 1000 . There is no SUBI, why? 因為減法可以用ADDI Rt, Rs, Imm(負數(shù)),實現(xiàn)減法。因為減法要考慮借位,加法考慮溢出,溢出很好實現(xiàn),借位不易實現(xiàn),所以可以用加一個負數(shù)實現(xiàn)。 Bit31302928272625242322212019181716

7、1514131211109876543210FieldOp Coders Fieldrt Field16-bit Immediate field00100001000001110000001001011000Homework:Write a program to sort an array using bubble sort. Home work should be submitted as rollno.s in the folder onIndus/common. It will be tested in the next lab.冒泡程序:(從小到大)C程void main()int a

8、ge=9,5,12,5,20,11,66,44,22,12;int x =0 ;for(int i=0 ; i<10 ; i+)if(agei>agei+1)for(int j=i;j>0;j-)if(agej>agej+1)x = agej;agej = agej+1;agej+1=x;Assembly Code(程序不能加載中文,所以實驗是去掉中文注釋).globl main.dataage: .word 9,5,12,5,20,11,66,44,22,12.textmain:la $t2,age #t2為age0地址addi $t5,$zero,10 #數(shù)組長為1

9、0addi $t4,$zero,0 #循環(huán)loop1次數(shù)addi $t3,$zero,0 #循環(huán)loop2次數(shù)addi $t6,$zero,0#中間寄存器,用于交換loop1:lw $t0,0($t2)#t0存放ageiaddi $t2,$t2,4 #t2=t2+4 相當于i=i+1lw $t1,0($t2) #t1存放agei+1addi $t4,$t4,1 #loop1循環(huán)次數(shù)t4自加1bgt $t1,$t0,skip1 #如果agei+1大于agei,說明已經(jīng)i和i+1排好序#跳到skip1,否則說明agei+1需要排序add $t3,$t4,0#j=i,令子循環(huán)次數(shù)為已排好序的數(shù)的個數(shù)

10、loop2:la $t7,age #t7為age0地址sll $t6,$t3,2#t6=t3*4add $t8,$t7,$t6#t8為agej+1的地址lw $s0,0($t8)#s0存放agej+1lw $s1,-4($t8)#s1存放agejaddi$t3,$t3,-1# loop2循環(huán)次數(shù)t3自減1bgt $s0,$s1,skip1 #若agej+1大于agej,說明已經(jīng)以前的都排好序#退出子程序,跳skip1,否則說明繼續(xù)需要排序add $s3,$s1,0#交換agej+1和agejadd $s1,$s0,0add $s0,$s3,0sw $s0,0($t8)#寫入數(shù)據(jù)段sw $s1,-4($t8)skip2:bne $t3,$zero,loop2 #判斷j是否為0.#相等說明已經(jīng)比到最后一個數(shù),退出loop2skip1:bne $t4,$t5,loop1 #不等,繼續(xù)循環(huán),#否則說明已經(jīng)比到最后一個數(shù),程序結束li $v0,10 #return,程序結束syscall加載后

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論