flat assembler
Message board for the users of flat assembler.
Index
> Main > Importing C functions to FASM |
Author |
|
flaith 06 Jun 2005, 20:15
first you must define
Code: extrn printf ; because of c and you must compile it as an objet Code: format MS COFF and link with gcc !!! hmmm May be ! _________________ Je suis sur de 'rien', mais je ne suis pas sur du 'tout'. |
|||
06 Jun 2005, 20:15 |
|
coconut 07 Jun 2005, 04:32
|
|||
07 Jun 2005, 04:32 |
|
shaolin007 07 Jun 2005, 12:19
Thanks coconut, but I'm still having problems getting this to run. It crashes at run time. I'm I still doing something wrong?
Code: format PE CONSOLE 4.0 entry BeginCode include '%fasminc%\win32a.inc' section '.code' executable readable writeable BeginCode: cinvoke printf, hellostring cinvoke getch push 0 call [ExitProcess] section '.data' data readable writeable hellostring db "This was printed out with the printf() function!",0 section '.idata' data readable writable library kernel,'KERNEL32.DLL',\ msvcrt,'msvcrt.dll' import kernel,\ ExitProcess,'ExitProcess' import msvcrt,\ printf,'printf',\ getch, 'getch' |
|||
07 Jun 2005, 12:19 |
|
pelaillo 07 Jun 2005, 13:25
You are missing first parameter to printf:
Code: cinvoke printf, format, hellostring (...) format db "%s",0 hellostring db "This was printed out with the printf() function!",0 |
|||
07 Jun 2005, 13:25 |
|
shaolin007 07 Jun 2005, 13:59
pelaillo wrote: You are missing first parameter to printf: I still can't get it to work. By the way, if you don't specify a format type then couldn't you just pass the pointer to the string like you do in C? Code: example printf("My string"); // No argument type string new code Code: format PE CONSOLE 4.0 entry BeginCode include '%fasminc%\win32a.inc' section '.code' executable readable writeable BeginCode: cinvoke printf, type, hellostring cinvoke getch push 0 call [ExitProcess] section '.data' data readable writeable type db "%s",0 hellostring db "This was printed out with the printf() function!",0 section '.idata' data readable writable library kernel,'KERNEL32.DLL',\ msvcrt,'msvcrt.dll' import kernel,\ ExitProcess,'ExitProcess' import msvcrt,\ printf,'printf',\ getch, 'getch' |
|||
07 Jun 2005, 13:59 |
|
Reverend 07 Jun 2005, 14:22
Maybe your 'cinvoke' macro is incorrect. Try:
Code: push hellostring call [printf] add esp, 4 call [getch] |
|||
07 Jun 2005, 14:22 |
|
shaolin007 07 Jun 2005, 14:35
Reverend wrote: Maybe your 'cinvoke' macro is incorrect. Try: Thanks man but still no dice. There must be something I am missing. Seems like I read somewhere that you have to underscore the name of the functions but I have tried that and it still didn't work. |
|||
07 Jun 2005, 14:35 |
|
flaith 07 Jun 2005, 17:06
Much better now (look at the 'idata' section and 'getch' to '_getch')
Code: format PE CONSOLE 4.0 entry BeginCode include '%fasminc%\win32a.inc' section '.code' executable readable writeable BeginCode: cinvoke printf, type, hellostring cinvoke getch invoke ExitProcess section '.data' data readable writeable type db "%s",0 hellostring db "This was printed out with the printf() function!",0 section '.idata' import data readable writable library kernel,'KERNEL32.DLL',\ msvcrt,'msvcrt.dll' import kernel,\ ExitProcess,'ExitProcess' import msvcrt,\ printf,'printf',\ getch, '_getch' _________________ Je suis sur de 'rien', mais je ne suis pas sur du 'tout'. |
|||
07 Jun 2005, 17:06 |
|
shaolin007 07 Jun 2005, 18:27
flaith wrote: Much better now (look at the 'idata' section and 'getch' to '_getch Hmm still crashing. I wouldn't think that it would be like this to call a simple c function. |
|||
07 Jun 2005, 18:27 |
|
flaith 07 Jun 2005, 18:42
I don't get it, it run ok for me :
compiled with Fasm 1.61.8 _________________ Je suis sur de 'rien', mais je ne suis pas sur du 'tout'. |
|||
07 Jun 2005, 18:42 |
|
shaolin007 07 Jun 2005, 19:22
I don't get it either. I have exactly the same code as you have there and it will compile fine but when you execute it it crashes! Doesn't make a bit of sense. Any suggest as to what it may be?
|
|||
07 Jun 2005, 19:22 |
|
flaith 07 Jun 2005, 20:40
_________________ Je suis sur de 'rien', mais je ne suis pas sur du 'tout'. |
|||
07 Jun 2005, 20:40 |
|
coconut 07 Jun 2005, 21:38
what windows are you running, and msvcrt.dll version? btw looking at msvcrt with dependancy walker (great free program), getch is exported as _getch
http://www.dependencywalker.com/ Last edited by coconut on 07 Jun 2005, 21:42; edited 1 time in total |
|||
07 Jun 2005, 21:38 |
|
shaolin007 07 Jun 2005, 21:39
flaith wrote: Ok, and if you try my own exe ??? LOL I know what it is now. I forgot to add the 'import' directive to my '.idata' section! Silly error! |
|||
07 Jun 2005, 21:39 |
|
coconut 07 Jun 2005, 21:40
ouch lol
|
|||
07 Jun 2005, 21:40 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.