flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
Goplat 22 Mar 2008, 01:06
You have to take into account that functions' names get "decorated" by the compiler. For a cdecl function (the default kind in C), this is just an underscore prepended to the name, so a function named "foo" in C source code will be named "_foo" in the object file.
Since fasm does not do name decoration, you have to call the function "_foo". |
|||
![]() |
|
revolution 22 Mar 2008, 01:39
You can also use public foo as '_foo'
|
|||
![]() |
|
Patrick_ 03 Apr 2008, 23:06
Thanks, that worked. I'm having trouble calling libc functions, though. I have something like:
Code: format MS COFF
extrn printf
public _main
_main:
... But when I run gcc -o out out.o, it gives me "undefined reference to WinMain@16". I tried "public WinMain@16" and replaced "_main" with "WinMain@16" but no go. Any ideas? I'm so used to programming in straight assembly... |
|||
![]() |
|
Patrick_ 03 Apr 2008, 23:26
Oops, nevermind. It seems I was linking against the wrong file when I tried publicizing "WinMain@16". It works now.
![]() |
|||
![]() |
|
asmfan 04 Apr 2008, 06:17
Won't create new thread and ask here
What is the difference of Quote:
and Quote:
Could someone explain the plain COFF non MS format? Underscore is for C calling convention. Can fasm automatically decorate names according keywords in proc directives (stdcall/c)? And more: why cannot I compile this: Code: format MS COFF INCLUDE 'win32wxp.inc' public MyProc proc MyProc stdcall uses ebx esi edi, x:DWORD, y:DWORD local .cntr:dword mov eax,[x] mov [.cntr],eax mov eax,[y] mov [.cntr],eax ret endp _________________ Any offers? |
|||
![]() |
|
revolution 04 Apr 2008, 06:25
asmfan wrote: Could someone explain the plain COFF non MS format asmfan wrote: Can fasm automatically decorate names according keywords in proc directives asmfan wrote: why cannot I compile this: Code: local .cntr:DWORD |
|||
![]() |
|
asmfan 04 Apr 2008, 09:37
Once again thank you revolution!
And once again i'm stumbling on lower&upper cases of data reservind/declaration directives aka DD vs. dd, dword vs DWORD, etc... and once again i'm asking Thomasz to make additional aliases to allow this cases... I know what ms coff is (pecoff_v8.doc helped that) but mere coff... maybe googling will help but if there is a few difference then i thought someone could clarify them here on forum and then Tomasz could kindly put them in fasm.pdf for simplicity of understanding. |
|||
![]() |
|
White-spirit 04 Apr 2008, 09:53
As we talk here about calling Asm code from C, how to do the inverse ?
here's my code : Code: ;; Asm code format MS COFF extrn print extrn putchar extrn itoa print_float: mov ebp,esp push dword [esp+4] call ftol push eax mov ebx,eax ; saves eax push eax push 10 push 0 push 0 call itoa push eax call print push '.' call putchar sub dword [ebp+4], ebx fld dword [ebp+4] .loop: fmul [ten] fist dword [ebp+12] push dword [ebp+12] push 10 push 0 push 0 call itoa push eax fisub dword [esp] call print push 0 ficom dword [esp] fstsw [esp] fwait pop eax sahf jnz .loop ret 4 --------- /* C code */ #include <stdarg.h> #define PREFIX 1 #define SUFFIX 0 void clrscr (); void scroll (); void print (const char*); void printf (const char*, ...); void putchar (char); extern void print_float (float); const char* itoa (int,int,int,int); // PS : it's not a standard C compatible itoa For the linking, i use : Code: fasm float.asm float.o i586-elf-gcc -ffreestanding -mno-stack-arg-probe -c kernel2.c -o kernel2.o i586-elf-ld -e kernel_main -Ttext 0x1000 -o kernel2 float.o kernel2.o i586-elf-objcopy -R .note -R .comment -S -O binary kernel2 kernel2.bin ( the i586-elf is for the cross compiler :p ) If i use for example ( extrn "_print" as print ) instead of ( extrn print ), ld give's me the following error message : Code: float.o :: undefined reference to '_print' But if i use "extrn print" instead, the linking works without any error message, but Bochs reboots on "call itoa" :s Who can help me please ? Thanks ![]() |
|||
![]() |
|
revolution 04 Apr 2008, 10:02
Whenever you call a c-style function then you must use the c-calling convention whereby you must pop the parameters off the stack after the call.
Code: ... push dword [ebp+12] push 10 push 0 push 0 call itoa add esp,4*4 ;pop off the 4 parameters we pushed up there ... |
|||
![]() |
|
White-spirit 04 Apr 2008, 10:48
Thanks, but Bochs still reboots, and in the Bochs console i see : "(invalid) : FFFF" :s
|
|||
![]() |
|
revolution 04 Apr 2008, 10:57
White-spirit wrote: Thanks, but Bochs still reboots, and in the Bochs console i see : "(invalid) : FFFF" :s |
|||
![]() |
|
White-spirit 04 Apr 2008, 12:11
Thanks but I prefer do only one C call to see if the issue comes from there :
Code: push '.' call putchar add esp,4 It still reboots :s |
|||
![]() |
|
revolution 04 Apr 2008, 13:38
I expect you have a stack imbalance. Post your code where you have only the putchar test.
|
|||
![]() |
|
White-spirit 04 Apr 2008, 14:13
Code: ;; ASM Code format ms coff extrn putchar public call_test call_test: push '.' call putchar add esp,4 ret 4 // C Code void scroll (); void putchar (char); extern void call_test (); unsigned int x=0; unsigned int y=0; int kernel_main(void) { call_test(); while(1); return(0); // not very important } void scroll() { int i; unsigned char *screen = (unsigned char*) 0xB8000; for (i = 0*80; i < 24*80; i++) { screen[i] = screen[i+160]; } for (i = 24*80; i < 25*80; i++) screen[i] = 0; y = 24; } void putchar( char s ){ unsigned char* screen = (unsigned char*) (0xB8000+y*160+x*2); if (s == 0xA ){ // LF : 0xA x=0; y++; screen=(unsigned char*) (0xB8000+y*160); } else { *(screen++)=s; *(screen)=0x07; x++; } if (x>=79){ x=0; y++; } if (y>=24){ scroll(); y=1; } } Here's a Bochs screenshot ( notice the '!' after 'Please Visit :' ), and Bochs still reboots ![]() ![]() |
|||
![]() |
|
dap 04 Apr 2008, 14:24
Try removing the '4' after 'ret'. Also C functions are public by default, you don't need to use 'extern' in their protoypt. If you want to make them private use the 'static' keyword.
|
|||
![]() |
|
White-spirit 04 Apr 2008, 14:43
I tried, but it's still the same ><
Code: format ms coff extrn putchar public call_test call_test: push '.' call putchar jmp $ ; To see if it arrives so far add esp,4 ret |
|||
![]() |
|
edfed 04 Apr 2008, 15:02
a char is a byte.
are you sure you push a dword? is it possible it pushes only a word? push '.' <-- operand size? word or dword? |
|||
![]() |
|
White-spirit 04 Apr 2008, 15:43
Thanks edfed, but i don't see any operand size problems, i tested a minimalistic putchar in Asm and it works, so it's a C-call problem :
Code: format ms coff public call_test putchar: mov al, byte [esp+4] mov byte [0xB8000], al mov byte [0xB8001], 0x37 ret 4 call_test: push '.' call putchar jmp $ ; To see if it arrives so far, and yes, it does ! add esp,4 ret Thanks for help . |
|||
![]() |
|
White-spirit 05 Apr 2008, 15:13
Someone ? :/
|
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.