News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

SP decrement with Push

Started by arka.sharma, September 28, 2015, 05:37:59 PM

Previous topic - Next topic

arka.sharma

Hi All,

If I use full segment definition and don't use .MODEL and USE16 or USE32 then how SP will be decremented in following cases

push 0h


var dd 0
push cs:var


Regards,
Arka

TouEnMasm


There is no direction flags for the push.
Are you sure of this ????????
Fa is a musical note to play with CL

arka.sharma

Direction flag usually comes into picture while copying block of data right ? Intel Reference Manual doesn't mention anything about direction flag for push I guess.

jj2007

Quote from: ToutEnMasm on September 28, 2015, 07:35:00 PM

There is no direction flags for the push.
Are you sure of this ????????

Me sure of this!!!!!!

dedndave

the direction flag is used with the "string" instructions
MOVS, CMPS, SCAS, STOS, LODS

as for pushing a dword in 16-bit segments, i suppose it's done with 2 pushes
the high word is pushed first, then the low word

if you push a constant, the size is determined by the segment USES

FORTRANS

Hi,

   Using MASM 5.0 and producing a listing, I got the following.


CODE    SEGMENT


   Pushing a constant or a double word variable generates an
error as they are not valid 8086 instructions.


.386
CODE    SEGMENT


   Pushing a constant and a double word variable generates
valid 32-bit instructions in 32-bit code.

Regards,

Steve

TouEnMasm

perhaps a little more code like this one (old so old ...)



                 ;Piece of code
                   
DATA SEGMENT WORD PUBLIC 'DATA'
      PILE DW 0
            PDOSPASS STRUC
  DAX  DW ?
      PDOSPASS ENDS
DATA ENDS

DGROUP GROUP DATA
CODE SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:CODE,DS:DGROUP,ES:DGROUP,SS:DGROUP
            PUBLIC DOSPASS
   
DOSPASS PROC FAR
                 MOV   PILE,SP
                 MOV   AX,SP
         PUSH  BP
                 SUB    AX,SP                 ;see here if it is negative (FF..h) or positive (2h) ?
         MOV   BP,SP                  ;debugger can be usefull!
         PUSH  AX
         PUSH  DS
         SAHF

         MOV   BX,[BP+6]

                 ;end
                 SAHF 
POP  DS
POP  AX
POP  BP
MOV  SP,PILE
RET 2
       DOSPASS ENDP
      CODE ENDS
   END
Fa is a musical note to play with CL

BlueMR2

Quote from: dedndave on September 28, 2015, 10:14:03 PM
as for pushing a dword in 16-bit segments, i suppose it's done with 2 pushes
the high word is pushed first, then the low word

That's right.  Intel is little endian.  I remember having to do DWORD pushes in DESQview.  On my 486 I could just use the 32-bit override, but on the 8088 I had to push high word, then low word (Quarterdeck also supplied macros for doing that to make life easier, like as used in https://github.com/BrianKnoblauch/DVClock/blob/master/CLOCK.ASM ).
My Code Site
https://github.com/BrianKnoblauch

arka.sharma

#8
I performed the following test. I declare a dword variable in code segment as following

var dd 0

Then I added following piece of code

pusha
mov bp, sp
call _DumpRegister
push cs:var
mov bp, sp
add sp, 4
call _DumpRegister
popa


_DumpRegister is a routine which dumps all the registers in console, As it can be seen I have not used "dword ptr" for pushing "var", I have verified the content of bp and I found after the push it is decremented by 4. I have not declared any USE16 or USE32 in my module. I am thinking how the operand width is being calculated in this case. I am using MASM 6.1 and generated exe is MZ format.

dedndave

if you disassemble that program, you will find that two PUSH'es are used