Hi Charles,
I think that, because of using Fasm as a backend of Small c , i will name it something related to Fasm. may be universalFasm.....
here is a small Example ,
//
// test program
//
$ format PE GUI //this is inline asm
$ entry main
$ include 'MACRO/PROC32.inc'
extern stdcall MessageBoxA();
/* Fasm Proc syntax */
proc itoa value,buf,base
local table db '0123456789ABCDEF' ;Table used in conversion
cmp [base],16 ;Nothing over base 16(Hex) is supported. You could add support for them by just modifying this line and the table above
ja .base_error
cmp [base],2 ;Nothing below base 2 is supported
jb .base_error
pushad ;Save the registers. No one likes a procedure that thrashes everything
mov eax,[value] ;Load up the registers
mov ebx,[base]
mov edi,[buf]
mov edx,0 ;Important note if you didn't know this, division by a dword is a 64-bit divide, edx will interfere if it's not cleared
;Division by a dword does edx:eax div r/m32 where edx:eax is treated as one 64-bit number
push 0xFFFF ;This push is used later in the reversing part, it tells it that it's done.
@@:
or eax,eax ;Is the value to convert zero?
jz .reverse ;If so, we're done here, lets reverse it.
div ebx ;Else, divide it by the base. Result stored in eax, remainder in edx
lea edx,[edx+table] ;Point edx to the byte in the table holding the value we need
movzx edx,byte[edx] ;Put that byte in edx
push edx ;Push it
mov edx,0 ;and as I explained earlier, edx MUST be zero before the next divide, or it will interfere with the divide
jmp @b ;Lather, rinse, and repeat
;The routine above gets the numbers backwards, so we must reverse them.
.reverse:
pop eax ;Pop a converted value off the stack
cmp eax,0xFFFF ;Are we done reversing(was the popped value the 0xFFFF we pushed before we started)?
je @f
stosb ;If not, store the byte in the buffer
jmp .reverse
@@:
mov eax,0 ;The string needs to be zero terminated, so this just places a 0x0 at the end
stosb
popad
mov eax,0 ;Out: eax = 0, everything went fine
ret
.base_error:
mov eax,-1 ;Out: eax = -1, Bad base
ret
endp
/* c function Sytax */
print(x)
int x;
{
char buf[255];
itoa(x,buf,10);
MessageBoxA(0,buf,"the Value Is",0);
}
main()
{
int k,m,c;
k = 10;
m = 20;
c = m + k;
print(c);
}
#asm
section '.idata' import data readable writeable
dd 0,0,0,RVA kernel_name,RVA kernel_table
dd 0,0,0,RVA user_name,RVA user_table
dd 0,0,0,0,0
kernel_table:
ExitProcess dd RVA _ExitProcess
dd 0
user_table:
MessageBoxA dd RVA _MessageBoxA
dd 0
kernel_name db 'KERNEL32.DLL',0
user_name db 'USER32.DLL',0
_ExitProcess dw 0
db 'ExitProcess',0
_MessageBoxA dw 0
db 'MessageBoxA',0
section '.reloc' fixups data readable discardable ; needed for Win32s
#endasm
i will post that in Fasm forum also.