flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
gunblade 04 Nov 2005, 13:31
Well, im assuming your using gcc, either on *nix, or on windows (mingw32).
Firstly, you will want to build the asm source as an object (eg: Format ELF for linux, i think Format MSCOFF for windows. Then if you want to call a function called Test, and pass it the parameters: param1, param2, and param3, then you would do: Code: pushd param3 param2 param1 call Test And when you go to assemble the code, you simply use fasm to assemble it into an object file (usually .o), then use a linker (like ld, part of the gcc package), to make it into an executable and link it with the the compiled C code you have. ld c_code_binary.o asm_code_binary.o -o yourprogram This should work, Good luck, gunblade |
|||
![]() |
|
BXM 04 Nov 2005, 17:02
- In the .idata section, declare the name of the API(s).
- Then declare what functions you want to import - To call the function, use "invoke" or "stdcall". You may find code calling functions from the Win32 API in /FASM/EXAMPLES . The first example imports the "ExitProcess" function from Kernel32.dll, and "mciSendString" from winmm.dll. /FASM/EXAMPLES/DLL is also a good and simple example. |
|||
![]() |
|
Sarge 05 Nov 2005, 21:14
Thanks you very much gunblade and BXM, this is exactly what i need. I really appreciate it.
Thanks, Sarge |
|||
![]() |
|
Chewy509 08 Nov 2005, 02:26
...and to follow on from what the others have said, if you're adventurous and have the right CPU/OS, then the following pdf gives the ABI for x86_64 (aka AMD64) which is what GCC uses on AMD64 based linux systems...
http://www.x86-64.org/documentation/abi-0.96.pdf PS. For those that don't want to read the full ABI, the calling convention has *changed* for x86_64 based systems. A mix of registers and the stack is now used to pass values to a procedure. |
|||
![]() |
|
Sarge 08 Nov 2005, 20:04
I am still having trouble getting this to work, the exe is showing a error message, these are the steps im doing.
1. build .o out of the .c files with gcc 2. use fasm to assemble the asm file to .o 3. use ld [ all the .o that were built with gcc and the asm .o ] -o myapp.exe 4. run exe, which gives me a error any help please. |
|||
![]() |
|
HyperVista 08 Nov 2005, 22:27
Hi Sarge,
What error message are you seeing? |
|||
![]() |
|
Sarge 08 Nov 2005, 22:46
Hi,
Well i have created a startup.o file because fasm is saying "warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000" and when i link the startup.o with ld and run the exe i get, "This application has failed to start because [ENC].dll was not found. Re-installing the application may fix the problem" [ENC] = all encrpted text which i cannot make out to find the right dll This is my startup.c file that is built to .o, Code: int main(int argc, const char* argv[]) { } and this is the asm file that is built as .o Code: format MS COFF extrn _PMACos public __pb_main section "code" code __pb_main: push ebp mov ebp,esp je _15 mov eax,0 pop ebp ret _15: call _PMACos Thanks, Sarge |
|||
![]() |
|
gunblade 09 Nov 2005, 10:29
hehe, nasty mistake there.. gcc/ld find main() in the C file, and use it as the main function, yet its empty, so itll crash.
theres two ways to get round this. Either: remove that startup.c file, its not needed, and in your asm code, put: Code: public _main
_main: at the beginning of the code. ld should be able to pick that up. I would be tempted to say that you should use gcc to link though.. as ld doesnt automatically link with the standard libraries, and therefore you can have some errors which says something like: file.exe: not an executable. If you really want the main to be in the C file, you can keep it as it is, but in the main() function, you put a line saying: Code: __pb_main(); but i would recommend the first method as theres no need to have a C file which just calls the asm code, its easily possible to just add the _main: to the asm file (although the label might be called just main: or __main:, theres a whole strange thing about underscoring labels, its different for every compiler/linker, and sometimes OS. In linux anyway, i dont have to put any underscores, in a program, i just put: Code: public main
main: and gcc picks it up fine as the startup label. Good luck, gunblade |
|||
![]() |
|
Sarge 09 Nov 2005, 13:06
Hi gunblade,
I still seem to be getting "ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to 00401000" for some reason, i have taken out my startup.c and added what you said to the asm file but i just keep getting this error. btw, can you please show me how to use gcc to compile a exe. if possible. Thanks, Sarge |
|||
![]() |
|
gunblade 09 Nov 2005, 13:31
aah, forgot that in windows, they have a different starting label.
so instead of the Code: public main
main: do: Code: public _mainCRTStartup
_mainCRTStartup: and ld should be able to pick that up fine. as for the process, youve got it, just use gcc to compile the C files into .o, use fasm to assemble into .o, then use ld to link them together. if you want the entry label to be called something else, you should be able to do: Code: ld -e entrylabelname ..... which will allow you to choose the name of the entry label. |
|||
![]() |
|
Sarge 09 Nov 2005, 13:42
Hi, gunblade
Thanks alot mate, this really helps me out alot. Now i just have to figure out why it opens a console window and crashes. Thanks, Sarge |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.