|
|
| asm: calling C procs |
|
lucaz
Member #4,194
January 2004
|
Well, this is a homework question, but I need help! What I need to do is to read 1024 bytes from "filename.txt" using fopen, fread, and fclose using ASM. in C: Sure, I can use -S and take a look to the .s but it's very difficult to read... (for me) So, these are my ideas (ASM):
I know it sucks, but anyone can help me? |
|
kazzmir
Member #1,786
December 2001
|
I havent used x86 asm in a while, but I dont think you can just push strings onto the stack. You have to have a data section or something and give them labels, then move the labels into registers and push the registers onto the stack. For easy reference on how to do this, just use gcc -S |
|
lucaz
Member #4,194
January 2004
|
yes is true. |
|
Oscar Giner
Member #2,207
April 2002
|
C functions are prepended with a '_', so the correct function names are _fopen, _fread and _fclose. [edit] -- |
|
lucaz
Member #4,194
January 2004
|
Ok, if I change the string stuff, this is a good sketch? |
|
Kitty Cat
Member #2,815
October 2002
|
Quote: C functions are prepended with a '_' Not necesarilly. They aren't in Linux, but they are in some versions of MinGW. -- |
|
Oscar Giner
Member #2,207
April 2002
|
The xor is useless, you don't want to set eax to 0 for anything. Funaction arguments are pushed in reverse order, from right to left. Remove the pop after the call to fopen. I don't know what offset and length are. I've never seen them. But if it's homework... what is your teacher doing? Not teaching you, certainly Quote: but they are in some versions of MinGW. They're in all versions of MingW I've tryed. Also in MSVC and in the old TurboC. I though that was part of the standard. I don't know why this is not true in linux. -- |
|
Kitty Cat
Member #2,815
October 2002
|
Quote: They're in all versions of MingW I've tryed. Same here, but APEG prepends its asm functions with _ in MinGW and the C code refuses to recognize them for some people. Even removing the _ apparently doesn't do anything. :/ As for the xor, I see a lot of assembly code do that to set a register to 0. I just assumed it was more CPU efficient. -- |
|
Oscar Giner
Member #2,207
April 2002
|
Quote: As for the xor, I see a lot of assembly code do that to set a register to 0. I just assumed it was more CPU efficient.
Yes, xoring is faster than a 'mov eax, 0', but he doesn't need to set eax to 0 in the first place [edit] -- |
|
lucaz
Member #4,194
January 2004
|
cookies! |
|
Lucas pepe
Member #5,568
March 2005
|
okay, then, the code approximated is this: ?
// When use the buffer?? Lukas |
|
Oscar Giner
Member #2,207
April 2002
|
You've created a 2nd account? Quote: I don't understand because the pop is not necessary The return value is stored in eax, not in the stack. So fopen will put FILE* in eax. Have you tried that code and see if it works? I think that would be much easier. -- |
|
ReyBrujo
Moderator
January 2001
|
You should also check eax is different from NULL after opening the file. -- |
|
lucaz
Member #4,194
January 2004
|
Quote: You've created a 2nd account?
No, he's a friend (lukas) Im lucaz. I'll try the code now. EDIT: |
|
ReyBrujo
Moderator
January 2001
|
Got a user interface course on the last week of January, and then spent most of February doing interface testings and user testings. I missed the hardcore of C programming, though -- |
|
Thomas Fjellstrom
Member #476
June 2000
|
Quote: Not necesarilly. They aren't in Linux, but they are in some versions of MinGW. Its the object file format. elf doesn't require it, but PE/COFF does. -- |
|
Billybob
Member #3,136
January 2003
|
BTW, you can push strings on the stack. You just can't use them like that. You have to pass esp as the argument to the function, since the function wants a pointer.
|
|
lucaz
Member #4,194
January 2004
|
Thanks, I get a 7 |
|
|