How would I go about indexing and declaring arrays in AT&T assembly?
Declaring do I do it like this:
array:
.zero 256
Creates array of 256, with values of zero.
Indexing it do I do it like this:
movq $array, %r14 //Set array to a register name
//Say that r11 has the number 5 stored
movq (%r14, %r11, 8), %r15 //This will make r15 at index 5 of array
movq %rbx ,%r15 //This will store value of rbx into r15
Is this how I do it? If not, how do I go about creating and indexing arrays in AT&T assembly?
Your assembly will store the address of the start of the array in r14
, move the value of the r11
th element of the array into r15
, then move the value in rbx
into r15
. It will not move any value into the array. If you want to move the address of the r11
th element into r15
then move the value in rbx
to the r11
th element of the array, you would need to use leaq (%r14, %r11, 8), %r15
to move the address of the r11
th element of the array into r15
, then use movq %rbx, (%r15)
to move the value in rbx
to the r11
th element of the array.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.