简体   繁体   中英

Check of homework: MIPS instructions that evaluate following expression

Assume that the array represented by the variable x is an array of signed integers beginning at address 0x10010000 and put the result of the expression into register $t0

x[5] + x[8]

I want to check how I've done on my answer, or where I've gone wrong? Thanks for any help / feedback.

lui  $t1, 0x10010000
ori  $t1, $t1, 0x00010100 
lui  $t2, 0x10010000
ori  $t2, $t2, 0x00001001
add $t0, $t1, $t2

There are several errors in your code:

  • lui does not allow an immediate of that size. You should use either the pseudoinstruction li $t1, 0x10010000 or two instructions to form the base address (eg a lui and an ori ). lui will set the high order 16-bits to the inmediate set in the instruction and the lower 16-bits will be set to zero, and ori can be used to set the lower 16-bits. However, in your example the lower 16-bits are zero therefore changing your instruction lui $t1, 0x10010000 to lui $t1, 0x1001 will do the trick.
  • You are not adding the contents but the addresses. You should use lw instruction, eg: lw $t2, 20($t1) to read the fifth element

1) I think the error is in the second and the fourth statement. The number 0x00010100 is 65792 in decimal. When you are trying to access fifth element in the array, the number should be 20 or 0b00010100 or 0x14. Similarly the fourth statement should 32 or 0x20. This answer assumes that size of integer is 4 bytes.

2) Also, you are just adding the addresses, not the data. You need to change your code to fetch the data from the locations given by the addresses in the $t1 and $t2 registers. Since, it is homework, I would not like to change the code for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM