News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Please advice. pushfd and popfd

Started by bawrobin, March 27, 2010, 07:05:30 AM

Previous topic - Next topic

bawrobin

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!

Farabi

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.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

drizz

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
The truth cannot be learned ... it can only be recognized.

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bawrobin