Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. 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]
  2.  
  3. lw $R3, 8($R10) #Load Y lw $R4, 12($R10) #Load Z lw $R5, 16($R10) #Load U lw $R6, 20($R10) #Load V
  4.  
  5. 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
  6.  
  7. 100011 01010 00011 0000000000001000
  8. 100011 01010 00100 0000000000001100
  9. 100011 01010 00101 0000000000010000
  10. 100011 01010 00110 0000000000010100
  11. 000000 00011 00100 00111 00000 100010
  12. 000000 00101 00110 01000 00000 100010
  13.  
  14. 000000 00010 00111 01000 00000 100010
  15. 101011 01010 00010 0000000000000100
  16.  
  17. 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]
  18.  
  19. lw $R10, 4($R8) #Load X lw $R11, 12($R8) #Load Y
  20.  
  21. slt $R12, $R10, $R11 #Sets R12 to 1 is X is smaller than Y bne $R12, $R0, $L1 #branch if R12 != 0
  22.  
  23. add $R10, $R10, $R10 #X = X+X j $L2 #jump over L1
  24.  
  25. $L1: sub $R10, $R10, $R11 #X = X-Y
  26.  
  27. $L2: sw $R10, 4($R8) #Stores X result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement