flat assembler
Message board for the users of flat assembler.
Index
> Main > How can I make a function that receives and sends parameters |
Author |
|
luisvalencia 08 Apr 2005, 18:36
How can I do that?
for example that receves 2 float numbers and it returns the sum of those. |
|||
08 Apr 2005, 18:36 |
|
Nikolay Petrov 10 Apr 2005, 17:23
Code: ;tree = one+two fld qword[first];entry first in st fadd qword[two]; add st with two fst qword[tree]; store result in tree. if you write fstp ... - you will store result and operation pop How to do that in function: Code: proc floatadd,arg1,.arg1,arg2,.arg2;result is arg1+arg2 finit fld qword[arg1] fadd qword[arg2] return endp ;in program ......... ;tree = one+two stdcall floatadd,dword[one],dword[one+4],dword[two],dword[two+4] fstp qword[tree]; store result in tree |
|||
10 Apr 2005, 17:23 |
|
Yardman 12 Apr 2005, 00:15
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 02:05; edited 1 time in total |
|||
12 Apr 2005, 00:15 |
|
rob.rice 13 Apr 2005, 02:21
you could also use pointer kept in memory so all your subs would use the same pointers
|
|||
13 Apr 2005, 02:21 |
|
Vasilev Vjacheslav 14 Apr 2005, 10:04
my example:
Code: format pe gui 4.0 entry start include '%fasminc%\win32a.inc' MAX_PATH = 260 EXCEPTION_MAXIMUM_PARAMETERS = 15 MAXIMUM_SUPPORTED_EXTENSION = 512 SIZE_OF_80387_REGISTERS = 80 macro m2m dest,src { push src pop dest } struct FLOATING_SAVE_AREA .ControlWord dd ? .StatusWord dd ? .TagWord dd ? .ErrorOffset dd ? .ErrorSelector dd ? .DataOffset dd ? .DataSelector dd ? .RegisterArea rb SIZE_OF_80387_REGISTERS .Cr0NpxState dd ? ends struct CONTEXT .ContextFlags dd ? .iDr0 dd ? .iDr1 dd ? .iDr2 dd ? .iDr3 dd ? .iDr6 dd ? .iDr7 dd ? .FloatSave FLOATING_SAVE_AREA .regGs dd ? .regFs dd ? .regEs dd ? .regDs dd ? .regEdi dd ? .regEsi dd ? .regEbx dd ? .regEdx dd ? .regEcx dd ? .regEax dd ? .regEbp dd ? .regEip dd ? .regCs dd ? .regFlag dd ? .regEsp dd ? .regSs dd ? .ExtendedRegisters rb MAXIMUM_SUPPORTED_EXTENSION ends struct EXCEPTION_RECORD .ExceptionCode dd ? .ExceptionFlags dd ? .pExceptionRecord dd ? .ExceptionAddress dd ? .NumberParameters dd ? .ExceptionInformation rd EXCEPTION_MAXIMUM_PARAMETERS ends struct EXCEPTION_POINTERS .pExceptionRecord dd ? .pContextRecord dd ? ends struct struct_seh .org_esp dd ? .org_ebp dd ? .save_eip dd ? ends section '.data' data readable writable szError db "Unable to calculate FPU operation! Maybe your processor doesn't support FPU!" szNULL db 0 szFloat1 dd 2.0 szFloat2 dd 3.3 int_pointer dd ? section '.udata' readable writable seh struct_seh szResult dq ? section '.code' code readable executable start: stdcall _calc,szFloat1,szFloat2,seh,szResult or eax,eax jnz @F invoke MessageBox,NULL,szError,szNULL,MB_OK+MB_ICONHAND jmp exit_prog @@: fld dword [eax] mov edx,int_pointer frndint fistp dword [edx] exit_prog: invoke ExitProcess,NULL proc _calc, lpAddr1,lpAddr2,lpSEH,lpResult pushad mov edi,[lpSEH] ; init seh mov [edi+struct_seh.save_eip],.safe_place mov [edi+struct_seh.org_ebp],ebp push seh_proc push dword [fs:0] mov [edi+struct_seh.org_esp],esp mov dword [fs:0],esp mov esi,[lpAddr1] mov edi,[lpAddr2] mov eax,[lpResult] finit fld dword [esi] fld dword [edi] fadd st0,st1 fst dword [eax] jmp .out .safe_place: xor eax,eax .out: mov dword [esp+28+8],eax ; kill seh pop dword [fs:0] add esp,4 popad return endp proc seh_proc, pExcept,pFrame,pContext,pDispatch mov esi,[pExcept] ; EXCEPTION_RECORD mov edi,[pContext] ; CONTEXT m2m [edi+CONTEXT.regEip],[seh.save_eip] m2m [edi+CONTEXT.regEsp],[seh.org_esp] m2m [edi+CONTEXT.regEbp],[seh.org_ebp] xor eax,eax return endp section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ user32,'user32.dll' include '%fasminc%\apia\kernel32.inc' include '%fasminc%\apia\user32.inc' ; eof |
|||
14 Apr 2005, 10:04 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.