Hi, Well... As in the post down the page explains, I'm learning ASM through a combination of simple c programs dropped to ASM and a book. And I've just made my first simple C program (After reading a few tuts yesterday) and dropped it to ASM. I've noticed a lot of junk in the ASM that's dropped, but I've found the <main> and decided that is the only part I actually need to look at. If not, oh well.. I figure the otherparts are the C headers or whatever.
Anyway, I have a few questions that hopefully one of you might be able to clear up for me.
So, I'll post the two sources of the programs
ASM Code:
Code:
0804832c <main>:
/* A simple loop program that runs through 1000 times.
Compile using gcc - loop -g -Wall loop.c and then dump to ASM (GAS x86)
using objdump loop -s */
int main ()
{
804832c: 55 push %ebp
804832d: 89 e5 mov %esp,%ebp
804832f: 83 ec 18 sub $0x18,%esp
8048332: 83 e4 f0 and $0xfffffff0,%esp
8048335: b8 00 00 00 00 mov $0x0,%eax
804833a: 83 c0 0f add $0xf,%eax
804833d: 83 c0 0f add $0xf,%eax
8048340: c1 e8 04 shr $0x4,%eax
8048343: c1 e0 04 shl $0x4,%eax
8048346: 29 c4 sub %eax,%esp
int i;
int j;
j = 0;
8048348: c7 45 fc 00 00 00 00 movl $0x0,0xfffffffc(%ebp)
for (i =0; i < 1000; i++){
804834f: c7 45 f8 00 00 00 00 movl $0x0,0xfffffff8(%ebp)
8048356: eb 12 jmp 804836a <main+0x3e>
j = i + 1 + j;
8048358: 8b 45 fc mov 0xfffffffc(%ebp),%eax
804835b: 03 45 f8 add 0xfffffff8(%ebp),%eax
804835e: 83 c0 01 add $0x1,%eax
8048361: 89 45 fc mov %eax,0xfffffffc(%ebp)
8048364: 8d 45 f8 lea 0xfffffff8(%ebp),%eax
8048367: 83 00 01 addl $0x1,(%eax)
804836a: 81 7d f8 e7 03 00 00 cmpl $0x3e7,0xfffffff8(%ebp)
8048371: 7e e5 jle 8048358 <main+0x2c>
}
return 0;
8048373: b8 00 00 00 00 mov $0x0,%eax
}
C Code (Comment on it if it's not very good, it probably isn't)
Code:
/* A simple loop program that runs through 1000 times.
Compile using gcc - loop -g -Wall loop.c and then dump to ASM (GAS x86)
using objdump loop -S */
int main ()
{
int i;
int j;
j = 0;
for (i =0; i < 1000; i++){
j = i + 1 + j;
}
return 0;
}
Ok, so my questions are these:
1. Where are the variables (i and j) declared?
2. Where can I find a list of *good* definitions of addl, mov and the rest of the (opcodes)?
3. When writing my own program in only ASM, do I need to manually assign a location in memory (0xffffff8 or whatever) my self, or would the assembler take care of this? If I do, how do I know what's free? (I don't think I would need to do it myself, as the memory locations change each time I run a program, correct?)
4. Where would I look for the meanings of (%ebp) and the like. I'd just google this but I'm not quite sure what they're called.
Yeah, I know. My book probably will go through all the things like this. But I'd rather get the hang of a few basics before reading a book. I just find it easier to do it like that.
Also, is there any simple tutorials (I mean simple, too.... Just the basics of ASM like loops and what not) out there for GNU Linux x86 asm that you would recommend?
Thanks for looking at this and (hopefully) answering some of my questions.
P.S. As always, comment on my code if you think it's wrong.
Bookmarks