5

I'm trying to learn MIPS assembly language by myself using MARS simulator.

For didactic reasons I'm limiting myself to not using pseudo-instructions.

While trying to get the address of some data into a register, I ran into a problem because I cannot use la.

I tried using lui in combination with ori, the same as if I was to load a 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 doable using specifically MARS, without pseudo-instructions? How?

Thanks in advance!

quetzalcoatl
  • 32,194
  • 8
  • 68
  • 107
Trinidad
  • 2,756
  • 2
  • 25
  • 43

3 Answers3

7

To answer the modified question "is this doable using specifically MARS, without pseudo-instructions?": From a quick scan of the MARS documentation, it appears not. MARS appears to be intentionally restricted for pedagogical purposes.

If you want to try this on a full MIPS simulator that will simulate the Linux OS running on MIPS and run code built with the gnu toolchain, take a look at the OVP Simulator. This is free and runs on Linux and Windows, but it's probably a lot more than you need.

markgz
  • 6,054
  • 1
  • 19
  • 41
  • You again! Thanks for the insight. :) Yeah I suspected it wasn't possible but just thought it was a major flaw for the designers to make pseudo-instructions do what you cannot achieve with actual instructions. I'll give OVP a try and wait a pair of days to see if someone comes up with a solution, if not the bounty is yours ;) – Trinidad Sep 28 '11 at 19:05
  • 1
    @Trinidad: I just tried it as well and you can't even do `li $t0, 2+2`, so I agree with markgz that it doesn't seem to be possible. – user786653 Sep 28 '11 at 20:29
3

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

    .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 address of the label "lab1" in the machine code.

markgz
  • 6,054
  • 1
  • 19
  • 41
2

Your ori instructions needs still another operand to work and as far as I looked over your code, "mem" is no existing label. Try this one:

.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 it doesn't work, MARS likely won't be able to get label content without pseudo instructions.