- #1
ladesidude
- 4
- 0
Hi all,
I have this small function in C++
void myfunc(int a, int b) {
int c = 1;
int d = 2;
c += b;
d += a;
return;
}
the assembly code and my comments follow:
subl $8, %esp ;; subtract 8 from %esp, what we are doing here is decrementing the stack pointer by 8 and then writing the value at the new top of stack address, used for allocating space for local variables.
movl $1, -4(%ebp) ;; copy 1 (which is the values stored in y) at the location using %ebp as the base address with an offset -4, the register is a pointer, the displacement specified how far from the pointer
movl $2, -8(%ebp) ;; copy 2 (which is the value stored in z) at the location using %ebp as the base address with an offset -8, the register is a pointer, the displacement specified how far from the pointer
movl 12(%ebp), %edx ;; copy what is at %ebp + offset 12 into %edx, what this means that the last instruction pushed to the stack is copied to %edx
leal -4(%ebp), %eax ;; this is a variant of movl and instead of copying the data at %ebp + offset -4, its storing the effective address into the destination
addl %edx, (%eax)
movl 8(%ebp), %edx
leal -8(%ebp), %eax
addl %edx, (%eax)
Am I correct in the comments of the lines, if not can someone please help me, also I am confused on leal. Thanks a bunch
I have this small function in C++
void myfunc(int a, int b) {
int c = 1;
int d = 2;
c += b;
d += a;
return;
}
the assembly code and my comments follow:
subl $8, %esp ;; subtract 8 from %esp, what we are doing here is decrementing the stack pointer by 8 and then writing the value at the new top of stack address, used for allocating space for local variables.
movl $1, -4(%ebp) ;; copy 1 (which is the values stored in y) at the location using %ebp as the base address with an offset -4, the register is a pointer, the displacement specified how far from the pointer
movl $2, -8(%ebp) ;; copy 2 (which is the value stored in z) at the location using %ebp as the base address with an offset -8, the register is a pointer, the displacement specified how far from the pointer
movl 12(%ebp), %edx ;; copy what is at %ebp + offset 12 into %edx, what this means that the last instruction pushed to the stack is copied to %edx
leal -4(%ebp), %eax ;; this is a variant of movl and instead of copying the data at %ebp + offset -4, its storing the effective address into the destination
addl %edx, (%eax)
movl 8(%ebp), %edx
leal -8(%ebp), %eax
addl %edx, (%eax)
Am I correct in the comments of the lines, if not can someone please help me, also I am confused on leal. Thanks a bunch