-
.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:
Code:
;at the begining
.text
.align 4
.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...
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.
EDIT:
And another question in ASM:
I can't seem to figure out why I continually get a seg-fault for this prog:
Code:
.lor:
.string "Hello, World!\n"
.text
.align 4
.globl main
main:
pushl %ebp
movl %esp, %ebp
movl $10, %ebx
LOOP:
cmpl $0, %ebx
jne NE
jmp GO
NE:
pushl $.lor
call printf
popl %eax
decl %ebx
jmp LOOP
GO:
movl $0, %eax
leave
ret
Any explanations of just how things work at all could help, thanks.
-LC
-
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:
Code:
NE:
subl $4, %esp
pushl $.lor
call printf
addl $4, %esp
decl %ebx
jmp LOOP
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.
a better fix might be:
Code:
NE:
pushl $.lor
call printf
addl $4, %esp
decl %ebx
jmp LOOP
-LC