I'm trying to learn x86 assembly, by looking at the generated assembly from clang. For instance, I'd like to learn how an automatic array in C is initialized to all 0's.
int64_t my_array [3000] = {0};
It looks like the assembly is reserving 24000B on the stack ( 3000 * 64b / 8B/b ) then calling memset. From memset's man page, it's signature looks like:
void *
memset(void *b, int c, size_t len);
So I know that the second argument should be passed in %rsi is 0 (the value I want every byte set to), and the third argument (%rdx) to be $24000, but what about the first argument (%rdi)? The two relevant instructions from the generated assembly appear to be:
leaq -24016(%rbp), %rax
movq %rax, %rdi
but I don't understand why negative 24016 from the base pointer? Why store in %rax then immediately move to %rdi (maybe because I just didn't compile with optimizations)?
Either way, I'm not sure how to pass the address of the first byte of the array to memset. I'm on OSX too, so I've already had to offset my stack pointer by 8B to assemble.