I have a simple C program that I assume generate simple assembly code
this is my C program
char *a="ba";
char x;
void main(){x=a[0];}
There is nothing especial about the generated assembly except
these lines
# test.c:4: void main(){x=a[0];}
movq a(%rip), %rax # a, a.0_1
movzbl (%rax), %eax # *a.0_1, _2
# test.c:4: void main(){x=a[0];}
movb %al, x(%rip) # _2, x
so I am in the middle of my program assembly and all the sudden quad word worth of address is moved happens to be from rax to rip, so rip is instruction pointer so I like to know what is inside rax at following line
movq a(%rip), %rax # a, a.0_1
does it hold my a[0], if it does that this makes sense because this line test.c:4: void main(){x=a[0];} movb %al, x(%rip) # _2, x so this mean my rax hold every element inside char *a and least significant type will be a[0] but I dont understood how come rax start holding my char *a I did not assign it then who assigned my char *a to rax register so I am assuming al there will be a[0] and a[1] will be at 8th to 15th byte of rax register. And what about this line movzbl (%rax), %eax # *a.0_1, _2 whats doing here
this is almost full assembly with disassembler directives
.text
.globl a
.section .rodata
.LC0:
.string "ba"
.section .data.rel.local,"aw"
.align 8
.type a, @object
.size a, 8
a:
.quad .LC0
.globl x
.bss
.type x, @object
.size x, 1
x:
.zero 1
.text
.globl main
.type main, @function
main:
pushq %rbp #
movq %rsp, %rbp #,
# test.c:4: void main(){x=a[0];}
movq a(%rip), %rax # a, a.0_1
movzbl (%rax), %eax # *a.0_1, _2
# test.c:4: void main(){x=a[0];}
movb %al, x(%rip) # _2, x
# test.c:4: void main(){x=a[0];}
nop
popq %rbp #
ret