Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PROC USES with PUSHA/POPA PUSHF/POPF

Status
Not open for further replies.

MisterAPL

MIS
Feb 9, 2003
1
DE
I like writing funtion frames for 32 bit DLLs and EXEs in this comfortable way:

[tt]
Func PROC USES EBX ECX ESI,
ParamInt:DWORD
LOCAL LocalInt:DWORD
...
RET
Func ENDP
[/tt]

How can I modify the [tt]PROC USES[/tt] statement to push all registers and/or the flag register?
 
In most assemblers is a macro for pushing all flags/registers - I think in MASM/TASM the macro is 'PUSHR'
and 'POPR'. Alternatively, you could manually push all flags/registers before code in the function, then pop them all off after. eg.

function:
push ax
push bx
push cx
push dx
etc...
; Code goes here
...
pop dx
pop cx
pop bx
pop ax
ret
 
pusha,popa - 16bit regs - ax,cx,dx,bx,sp,bp,si,di
pushad,popad - 32bit regs - eax,ecx,edx,ebx,esp,ebp,esi,edi
pushf,popf,pushfd,popfd - 16bit flags or 32bit eflags

in order of push, in reverse for pop.
32bit opcodes only valid for 16bit mode because in 32bit mode all opcodes operate the extended 32bit registers.
you have to push/pop the segments selectors manually.
i tend to find pusha/popa is costly on the stack.
irrelevant when task switching.

i find when manipulating registers for return values using ebp to modify stack and popa does not award any benefits over manual pops ie to return eax value

push ebx
push ecx
push eax

<BLAH>
<set eax to return value>

pop ecx ;lose old eax value
pop ecx
pop ebx
ret <or iret as the case maybe>

hope it helps - straiph
&quot;There are 10 types of people in this world, those who know binary and those who don't!&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top