Variables in a computer program have different life times:
|
|
int x; // global variable |
Effect:
|
ARM assembler directives to reserve uninitialized memory cells:
.skip n // Reserve n bytes of memory |
Examples:
x: .skip 4 // Reserve n bytes of memory y: .skip 2 // Reserve n bytes of memory |
Important:
|
Examples of C global variable definitions:
int a; short b; byte c; |
The equivalent construct in ARM assembler:
.data // Variables are reserved in the .data section a: .skip 4 // Reserve 4 bytes and id this mem addr with "a" b: .skip 2 // Reserve 2 bytes and id this mem addr with "b" c: .skip 1 // Reserve 1 bytes and id this mem addr with "c" |
Comment:
|
Example global variables definitions:
.data a: .skip 4 // Reserve 4 bytes b: .skip 2 // Reserve 2 bytes c: .skip 1 // Reserve 1 byte |
Effect: the variables are reserved inside the .data section:
DEMO: /home/cs255001/demo/asm/1-directives/skip01.s
int x = 4; |
Effect:
|
.byte Value - reserves 1 byte of memory and store the 8 bits 2's complementary code for Value in the memory cell .2byte Value - reserves 2 bytes of memory and store the 16 bits 2's complementary code for Value in the memory cells .4byte Value - reserves 4 bytes of memory and store the 32 bits 2's complementary code for Value in the memory cells .float Value - reserves 4 bytes of memory and store the 32 bits IEEE 754 code for Value in the memory cells .asciz "..." - reserves strlen bytes of memory and store the ASCII codes for all the characters in the memory cells |
Examples of initialized variable definitions:
byte a = 15;
short b = 15;
int c = 15;
float d = 5.0;
char[] e = "ABC"; // C style array
|
Their ARM assembler equivalent (= how the C compiler will translate the variable definitions)
a: .byte 15 b: .2byte 15 c: .4byte 15 d: .float 5 e: .asciz "ABC" |
The effect of the reservation made by the .byte, .2byte, .4byte, .float and .asciz directives:
.data a: .byte 15 b: .2byte 15 c: .4byte 15 d: .float 5 e: .asciz "ABC" |
Results: the following memory values are allocated inside the .data section:
DEMO: /home/cs255001/demo/asm/1-directives/init-var.s
Notice how the variables are stored starting at memory address 0x1878c(16) (Hex)
Notice that the label (symbolic name) a is equal to the binary number 0x1878c(16) (Hex):