flat assembler
Message board for the users of flat assembler.
Index
> Windows > Trying to use libC functions |
Author |
|
OzzY 17 Mar 2005, 19:15
Oh sorry... I've just discovered it right now...
I just read the libC reference and realized that it returns -1 on EAX if error or EOF. So, here is the code fixed: Code: format PE console include '%fasminc%\win32a.inc' start: invoke GetModuleFileName,0,buf,256 invoke fopen,buf,rmode mov [fp],eax invoke fopen,dest,wmode mov [fp2],eax mov ecx,1536 next: invoke fgetc,[fp] cmp eax,-1 jz done invoke fputc,eax,[fp2] loop next done: invoke fclose,[fp] invoke fclose,[fp2] ret dest db 'test2.txt',0 buf rb 256 rmode db 'rb',0 wmode db 'wb',0 fp dd 0 fp2 dd 0 ;idata data import library crt,'msvcrt.dll',\ kernel32,'kernel32.dll' import kernel32,GetModuleFileName,\ 'GetModuleFileNameA' import crt,fopen,'fopen',\ fclose,'fclose',\ fgetc,'fgetc',\ fputc,'fputc' end data Anyway thanks! And FASM is just great! Soon I'll be writing macros that will allow people to use libC just like a normal c program, like: printf "Hi!" printf "What is your name?" scanf "%s",buf . . . and so on... Bye! |
|||
17 Mar 2005, 19:15 |
|
Nikolay Petrov 17 Mar 2005, 20:14
the functions and procedures are not stdcall. That's why you MUST "invoke" with "cinvoke" to return the stack - like wsprintf.
Code: ;save as test.asm and run it... format PE console entry start include '%fasminc%\win32a.inc' proc start enter invoke GetModuleFileName,0,buf,256 cinvoke fopen,buf,rmode mov [fp],eax cinvoke fopen,dest,wmode mov [fp2],eax mov ecx,1536 next: cinvoke fgetc,[fp] cmp eax,-1 jz done cinvoke fputc,eax,[fp2] loop next done: cinvoke fclose,[fp] cinvoke fclose,[fp2] return endp dest db 'test2.exe',0 buf rb 256 rmode db 'rb',0 wmode db 'wb',0 fp dd ? fp2 dd ? data import library crt,'msvcrt.dll',kernel32,'kernel32.dll' import kernel32,GetModuleFileName,'GetModuleFileNameA' import crt, fopen,'fopen',\ fclose,'fclose',\ fgetc,'fgetc',\ fputc,'fputc' end data |
|||
17 Mar 2005, 20:14 |
|
f0dder 23 Mar 2005, 10:30
Keep the calling convention in mind - when you call external code (libc, the API, ...) those routines are allowed to trash eax,ecx,edx and must preserve ebx,esi,edi,ebp - this means you can't depend on the values of eax,ecx,edx after a call to libc (except that eax is returncode, of course).
|
|||
23 Mar 2005, 10:30 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.