Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 4. Convert X= (Y-Z) – (U-V); into MIPS assembly. Assume that the memory addresses of X, Y, Z, U, V are 4, 8, 12, 16, 20 offset from R10. Allocate X, Y, Z, U, V to registers R2, R3, R4, R5, R6. Convert this assembly code to machine level code. [10 points]
- lw $R3, 8($R10) #Load Y lw $R4, 12($R10) #Load Z lw $R5, 16($R10) #Load U lw $R6, 20($R10) #Load V
- sub $R7, $R3, $R4 #Subtract Z from Y and store in R7 sub $R8, $R5, $R6 #Subtract V from U and store in R8 sub $R2, $R7, $ R8 #Subtract R8 from R7 and store in X sw $R2, 4($R10) #Store X result
- 100011 01010 00011 0000000000001000
- 100011 01010 00100 0000000000001100
- 100011 01010 00101 0000000000010000
- 100011 01010 00110 0000000000010100
- 000000 00011 00100 00111 00000 100010
- 000000 00101 00110 01000 00000 100010
- 000000 00010 00111 01000 00000 100010
- 101011 01010 00010 0000000000000100
- 5. Write MIPS assembly equivalent of if(X ≥ Y) X = X+X else X = X-Y;. Assume memory address offsets 4, 12 from R8 for X, Y. Use registers R10, R11 for X, Y. [10 points]
- lw $R10, 4($R8) #Load X lw $R11, 12($R8) #Load Y
- slt $R12, $R10, $R11 #Sets R12 to 1 is X is smaller than Y bne $R12, $R0, $L1 #branch if R12 != 0
- add $R10, $R10, $R10 #X = X+X j $L2 #jump over L1
- $L1: sub $R10, $R10, $R11 #X = X-Y
- $L2: sw $R10, 4($R8) #Stores X result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement