How to load a memory address without using pseudo instructions?

I am trying to learn the MIPS assembly language myself using the MARS simulator.

For didactic reasons, I limit myself to not using pseudo-instructions.

When I tried to get the address of some data into the register, I ran into a problem because I can not use la .

I tried using lui in conjunction with ori , just as if I were to download the number directly, to no avail:

  .data arr: .byte 0xa1 .byte 0xb2 .byte 0xc3 .byte 0xd4 .byte 0xe5 .byte 0xf6 .byte 0x7a .byte 0x8b .byte 0x9c .byte 0xad .text lui $s0, mem # <--- mars just gives me errors here :( ori $s0, mem # ?? ... 

Is this being done using, in particular, MARS, without pseudo-instructions? How?

Thanks in advance!

+4
source share
3 answers

To answer the modified question β€œis this feasible, using, in particular, MARS, without pseudo-instructions?”: From a quick scan of the MARS documentation, this does not look like this. MARS appears to be intentionally limited for pedagogical purposes.

If you want to try this on a full MIPS simulator that will simulate Linux OS running on MIPS and run code built using the gnu toolchain, see OVP Simulator . It is free and works on Linux and Windows, but it is probably a lot more than you need.

+5
source

You need to refer to the label in the data section in the lui and ori instructions. This works for gnu (as) assembler:

  .data lab1: .byte 0xa1 ... .text lui $s0, %hi(lab1) ori $s0, %lo(lab1) lw $s2, 0($s1) ... 

The% hi and% lo directives tell the linker what is going on so that it can put the label address "lab1" in machine code.

+2
source

Your ori instructions need another operand to work, and as far as I was looking at your code, "mem" does not exist an existing label. Try the following:

 .data 0x10000000 #or choose any other location #pointer section .word arr #... #pointed section arr: .byte #... only as tip, you can separate multiple values with comma #behind .byte so that you don't need multiple .byte directives #... .text #... lui $s0, 0x1000 lw $t0, 0($s0) #get the value of "arr" #... 

If this does not work, MARS will probably not be able to retrieve the contents of labels without pseudo-instructions.

+2
source

All Articles