Reputation: 161
I am trying to learn to get a better understanding with assembler
Could someone explain what .data, .word and .text means does in the following code??
I don't get what this is for and what it does in this case
.data
array:
.word 0x12121212, 0x23232323, 0x34343434, 0x4, 0x5
.text
add_array:
li x1, 0x10000000
add x3, x0, x0
lw x2, 0(x1)
add x3, x3, x2
lw x2, 4(x1)
add x3, x3, x2
lw x2, 8(x1)
add x3, x3, x2
lw x2, 12(x1)
add x3, x3, x2
lw x2, 16(x1)
add x3, x3, x2
Upvotes: 8
Views: 27497
Reputation: 27974
.data
The .data
directive starts series of variable declarations. This is sometimes called a “data segment”.
array:
.word 0x12121212, 0x23232323, 0x34343434, 0x4, 0x5
Here a variable named array
is being declared with five elements, each sized to the target CPU's word. A word typically denotes 16 bits (2 bytes) or 32 bits (4 bytes) of memory, depending of the specific CPU's convention. In other words, the .word
directive allocates memory.
.text
add_array:
The .text
directive starts the actual program code, sometimes called a “text segment” or “code segment”.
Please note different flavors of assembly terminology exist, depending on the CPU family you are working with.
Upvotes: 3
Reputation: 5242
.word
is essentially creating some space in memory to hold data. Each item following it is 4 bytes long. It's similar to creating an array:
Assembly
array:
.word 0x12121212, 0x23232323, 0x34343434, 0x4, 0x5
C
int array[] = {0x12121212, 0x23232323, 0x34343434, 0x4, 0x5};
.text
tells the assembler to switch to the text segment (where code goes), and .data
tells the assembler to switch to the data segment (where data goes).
Upvotes: 6