flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 08 Feb 2011, 06:46
You have to save and restore edi if you want to comply with ccall convention. See the code for absolute value below.
Code: include 'win32ax.inc' .data values: dd -3,-4,6,-8,10 ;The top line declares a variable to store some values count =5 ; a count of 5 .code start: ccall AbsSum,values,count ;return value is in eax invoke ExitProcess,eax AbsSum: push ebp ;Pushing into stack mov ebp,esp ;Initializing stack pointer push edi ;ccall convention is to preserve edi, esi and ebx mov ecx,[ebp+8] ; ecx = Start mov edx,[ebp+12]; edx = Count xor eax,eax ; sum = 0 test edx,edx je .L34 .L35: mov edi,[ecx] ;edi=value neg edi ;edi=-value cmovs edi,[ecx] ;edi=abs(value) add eax,edi add ecx,4 ; Start ++ dec edx ; Count -- jnz .L35 ;Stop when 0 .L34: pop edi ;restore edi mov esp,ebp pop ebp ; Pop stack ret ; Return value .end start |
|||
![]() |
|
edprog 08 Feb 2011, 06:56
Wow i was totally doing it wrong,,, And I was also using sub, cmovg etc.. lol... thank you very much for your help!!! this is really helpful
|
|||
![]() |
|
revolution 08 Feb 2011, 07:21
Note that cmov is not available on all 32-bit CPUs. This may or may not affect you, but is something to be aware of.
|
|||
![]() |
|
edprog 08 Feb 2011, 07:26
Thank you for helping me understand FASM, I wouldnt have done it without you!
Regards |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.