.p2align 2 (ASM)
I was looking at some ASM code for some of my programs using the 'gcc -S' option to generate it and I noticed a few things that I have NO IDEA what they do, why they are there and if they have any effect on my programs.
Here is a list:
Any help would be appreciated, im not too concerned about the last two commands but more or less the aligns, what are they, and are they important, I would imagine they are relatively significant because they are there to begin with.
;at the begining
.p2align 2 ;what's this?!
;and I used to know what these were but I forgot
leave ;I think this does popl %ebp to get the original base pointer
ret ;and does this jump to where the program was called or after it or what, I forgot...
And another question in ASM:
I can't seem to figure out why I continually get a seg-fault for this prog:
Any explanations of just how things work at all could help, thanks.
.string "Hello, World!\n"
movl %esp, %ebp
movl $10, %ebx
cmpl $0, %ebx
movl $0, %eax
please never mind. I fixed the ASM probelm and I figured out what all that stuff meant, but I can't delete the thread. ::shrug::
The solution was:
Note it will leave a little bit of memory free at the end about 40 bytes, but its better and easier (maybe not faster) because the leave command automatically moves the esp and ebp back to where they were.
subl $4, %esp
addl $4, %esp
a better fix might be:
addl $4, %esp