MIPS assembly: how to declare integer values ​​in a .data section?

I am trying to raise my legs in MIPS assembly language using the MARS simulator .

My main problem now is how to initialize a set of memory cells so that I can access them later through assembly language instructions?

For example, I want to initialize addresses 0x1001000 - 0x10001003 with values ​​0x99, 0x87, 0x23, 0x45. I think this can be done in the data declaration (.data) section of my build program, but I'm not sure about the syntax. Is it possible?

Alternatively, in the .data section, how do I specify the storage of integer values ​​in some memory location (I don’t care where, but I just want to reference them somewhere). So I'm looking for the C-equivalent of "int x = 20, y = 30, z = 90;" I know how to do this with MIPS instructions, but is it possible to declare something like this in the .data section of the MIPS build program?

+4
source share
3 answers

Usually you do not initialize certain memory cells; each section (including .data) is positioned during the connection, and relocations are allowed, and then

To navigate the data entry, you select a name and put name: in front of it so that you can later refer to it by name. You specify a data block with .size value . For instance:

 .data x: .word 20 y: .word 30 z: .word 90 

Then you can use shortcuts in your assembly:

 .text lw $t0, x 
+6
source

you can see more here: MIPS assembly overview and here: MIPS dataseg

0
source

so if I declared x: .word 701 y: .word 701 then.text bge y, x, endin as the main part of the program, the condition will accept an integer variables x and y, which allows you to complete the end method?

I believe this is wrong if you specify x or y inside your mips program, you will only return the base address of x and y. For example, if you typed

 addi $t0,y,8 

Would give you $ t0 = 10000010 (assuming the address y starts with 10000000)

The correct way to compare 2 values ​​from 2 words with x and y marks would look like

 .data x: .word 701 y: .word 701 .text main: lw $t0,x #loads $t0 with 701 lw $t1,y #loads $t1 with 701 bge $t0,$t1,end #compares $t0 and $t1, if equal, jump to address [end] end: #the code segment for end label 
0
source

Source: https://habr.com/ru/post/1306645/


All Articles