flat assembler
Message board for the users of flat assembler.
Index
> Main > saving regs in func havin local data without using macros. |
Author |
|
vid 05 Nov 2007, 15:19
in your case, second one, because if you pushed at first one, then "ebp-4" would point to saved registers.
But there is also option of saving them before enter, and that has advantage that you can exit procedure without unwinding stack, like this: Code: func: label .tmp dword at ebp-4 push ebx ecx push ebp mov ebp, esp sub esp, 4 ... push eax sub esp, 10 jmp .r ;we can exit procedure properly even with things left on stack ... .r: mov esp, ebp pop ebp pop ecx ebx retn I remember this way had some disadvantage too, but i can't recall what it was now. |
|||
05 Nov 2007, 15:19 |
|
bitRAKE 05 Nov 2007, 18:29
Code: strLEN: or ecx, -1 xor eax, eax pop edx ; return address xchg edi, [esp] repne scasb pop edi not ecx dec ecx jmp edx |
|||
05 Nov 2007, 18:29 |
|
LocoDelAssembly 05 Nov 2007, 19:22
This particular way is unconvinient, Pentium processors and newer has a special buffer to predict where the RET instruction will go, but if the CALL is not paired with one RET then the next RET will be mispredicted due to the unbalance.
Besides that, it is a good example |
|||
05 Nov 2007, 19:22 |
|
bitRAKE 05 Nov 2007, 19:57
Very true. If speed is the goal then ESP should only be updated twice within a PROC - once on entry and once on exit. This small routine should only be used where speed is not a concern. Also, it might be good to mention that XCHG with a memory operand induces a bus lock!
Often a routine has ESP dependancies at the beginning because of frame or register preservation. Fastcall convention helps a little here, but often it is difficult to avoid all together. The tail code is usually easier to remove ESP dependancies on - reduced to just RET #, or establishing a return value in EAX along with changes to ESP. |
|||
05 Nov 2007, 19:57 |
|
0.1 06 Nov 2007, 04:48
Thanks guyz!
So dumb is me! But hey I am only 0.1, lot of bugs still remain! _________________ Code: o__=- ) (\ /\ |
|||
06 Nov 2007, 04:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.