The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: arka.sharma on September 28, 2015, 05:37:59 PM

Title: SP decrement with Push
Post by: arka.sharma on September 28, 2015, 05:37:59 PM
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
Title: Re: SP decrement with Push
Post by: TouEnMasm on September 28, 2015, 07:35:00 PM

There is no direction flags for the push.
Are you sure of this ????????
Title: Re: SP decrement with Push
Post by: arka.sharma on September 28, 2015, 08:47:24 PM
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.
Title: Re: SP decrement with Push
Post by: jj2007 on September 28, 2015, 09:23:54 PM
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!!!!!!
Title: Re: SP decrement with Push
Post by: dedndave on September 28, 2015, 10:14:03 PM
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
Title: Re: SP decrement with Push
Post by: FORTRANS on September 29, 2015, 01:24:47 AM
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
Title: Re: SP decrement with Push
Post by: TouEnMasm on September 29, 2015, 02:58:49 AM
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
Title: Re: SP decrement with Push
Post by: BlueMR2 on September 30, 2015, 01:30:31 AM
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 ).
Title: Re: SP decrement with Push
Post by: arka.sharma on September 30, 2015, 12:01:29 PM
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.
Title: Re: SP decrement with Push
Post by: dedndave on September 30, 2015, 07:12:39 PM
if you disassemble that program, you will find that two PUSH'es are used