0

What is .text and why sometimes the .text has an adress like .text 0x0100? Also why on other example the .data has also an adress like

.data 0x200: 
A:5 
.space: 8
Tanque
  • 83
  • 8
  • `.text` is a conventional directive for code sections. The address presumably specifies where you would like that section to be (not normally used). – Jester Mar 27 '22 at 21:29
  • so inside .text is all the code, so the .text could be like the main() in c? – Tanque Mar 27 '22 at 21:32
  • No, you will still have a `main` or `start` or whatever entry point inside `.text` along with all the other functions. – Jester Mar 27 '22 at 21:33
  • so I don´t understand what .text is, could you make a comparation with c so I can understand? – Tanque Mar 27 '22 at 21:34
  • C has no such concept. It's the place in memory for all of your code by default. Advanced users can create custom sections. – Jester Mar 27 '22 at 21:50
  • Imagine this code, what will be the adress of main,write,A and B?: .text 0x0000 main: lw $t3, A($0) add $s1, $t3, $t3 write: sw $s1, B($0) .data 0x2000 A: 5 .space 8 B: 0 When I try to run, the following error appears: 6 column 4: "8192" is not a valid data segment address – Tanque Mar 27 '22 at 21:53
  • 1
    assembly is specific to the tool (not mips), what tool/assembler/software are you using? – old_timer Mar 27 '22 at 22:18
  • 1
    Just add up the offsets. Obviously `main` is at `0x0000`. Since `write` is 2 instructions later, each being 4 bytes, that's at `0x0008`. Similarly `A` is at `0x2000` and `B` is at `0x2008`. – Jester Mar 27 '22 at 23:42
  • Related but not a duplicate: [difference between .text and .data](https://stackoverflow.com/q/56709240) (because it doesn't mention the `.data 0x200` syntax, which I assume sets the origin, the absolute memory address where this section will get linked, in some MIPS assemblers.) – Peter Cordes Mar 28 '22 at 00:34

1 Answers1

0

.data is the section where all your data is. For example your variables etc.

The .text section is where your code is. This is everything that should run in the program.

The data sections and text sections are sometimes given an address to allow a certain amount of space for the data section. For example if you place the text section at 0x500 and the data section at 0x300, then you have 200 bytes of space for your variables and data.