Hello.
Please advice about pushfd and popfd.
As I read pushFD is for 32 bit registers.
So I tried to make for example ebx greater than 16 bit, for example 67890 and then try to check if just pusha will be ok and it is ok.
Please tell me for what is pushFD and popFD ?
Here is code #1:
.686p
.model flat, stdcall
option casemap:none
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc
.data
MsgText db 'Calculating results is %d',0
MsgTitle db 'ebx and eax are equal',0
buffer db 100 dup(?)
.code
start:
mov ebx, 67890
pusha
mov ebx, 1
popa
invoke wsprintf,ADDR buffer,ADDR MsgText,ebx,1 ;result is 67890
invoke MessageBox,0,ADDR buffer,ADDR MsgTitle,MB_ICONINFORMATION
invoke ExitProcess,0
Example #2.
.686p
.model flat, stdcall
option casemap:none
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc
.data
MsgText db 'Calculating results is %d',0
MsgTitle db 'ebx and eax are equal',0
buffer db 100 dup(?)
.code
start:
mov ebx, 67890
pushfd
mov ebx, 1
popfd
invoke wsprintf,ADDR buffer,ADDR MsgText,ebx,1 ;result is 67890 too as in first example
invoke MessageBox,0,ADDR buffer,ADDR MsgTitle,MB_ICONINFORMATION
invoke ExitProcess,0
So, what is difference between pusha and pushfd ? If you can please make an example if it is not hard. Thank you very much!
I never heard about "pusha" but for pushfd it was used to check the prosesor flag.
For example, you substract 0 with 1 so the value is -1 and it was signed. The prosessor put 1 on their flag and you can retrieve it with pusfd and the popfd.
And for pushad it mean, you save all of the usable registers to the stack and you can get the value back by using popad.
push flags dword
push flags word
push all dword
push all word
pop -||-
pusha, pushf - push according to current word size
pushaw pushad - override current word size and push according to w/d
compile with jwasm:
; jwasm -bin this.asm
.x64p
_TEXT16 segment para use16 public 'CODE'
%echo Current Word Size is @CatStr(%(@WordSize))
pusha
popa
pushaw; default
popaw
pushad; -- size override prefix here
popad; -- size override prefix here
_TEXT16 ends
_TEXT32 segment para use32 public 'CODE'
%echo Current Word Size is @CatStr(%(@WordSize))
pusha
popa
pushaw; -- size override prefix here
popaw; -- size override prefix here
pushad; default
popad
_TEXT32 ends
_TEXT64 segment para use64 public 'CODE'
%echo Current Word Size is @CatStr(%(@WordSize))
;pusha; --- invalid in 64bit mode
;popa
_TEXT64 ends
end
bawrobin,
Is normally the case that when you need to preserve the processor flags and restore them before you do a flag based test that you use PUSHFD to preserve them and POPFD to restore the flags. For registers you use PUSHAD to preserve registers and restore them with POPAD. This is of course in 32 bit. Now unless you have very good reason to try and do these preservatuions in 16 bit, there is no reason generally to use other than the 32 bit instructions.
Thank you very much !