Author Topic: SP decrement with Push  (Read 2392 times)

arka.sharma

  • Regular Member
  • *
  • Posts: 7
SP decrement with Push
« 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

Code: [Select]
push 0h
Code: [Select]
var dd 0
push cs:var


Regards,
Arka

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: SP decrement with Push
« Reply #1 on: September 28, 2015, 07:35:00 PM »

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

arka.sharma

  • Regular Member
  • *
  • Posts: 7
Re: SP decrement with Push
« Reply #2 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.

jj2007

  • Member
  • *****
  • Posts: 7763
  • Assembler is fun ;-)
    • MasmBasic
Re: SP decrement with Push
« Reply #3 on: September 28, 2015, 09:23:54 PM »

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

Me sure of this!!!!!!

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: SP decrement with Push
« Reply #4 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

FORTRANS

  • Member
  • ****
  • Posts: 946
Re: SP decrement with Push
« Reply #5 on: September 29, 2015, 01:24:47 AM »
Hi,

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

Code: [Select]
CODE    SEGMENT
   Pushing a constant or a double word variable generates an
error as they are not valid 8086 instructions.

Code: [Select]
.386
CODE    SEGMENT

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

Regards,

Steve

ToutEnMasm

  • Member
  • *****
  • Posts: 1189
    • EditMasm
Re: SP decrement with Push
« Reply #6 on: September 29, 2015, 02:58:49 AM »
perhaps a little more code like this one (old so old ...)

Code: [Select]

                 ;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

  • Member
  • **
  • Posts: 115
Re: SP decrement with Push
« Reply #7 on: September 30, 2015, 01:30:31 AM »
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 ).

arka.sharma

  • Regular Member
  • *
  • Posts: 7
Re: SP decrement with Push
« Reply #8 on: September 30, 2015, 12:01:29 PM »
I performed the following test. I declare a dword variable in code segment as following

Code: [Select]
var dd 0
Then I added following piece of code

Code: [Select]
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.
« Last Edit: September 30, 2015, 01:47:00 PM by arka.sharma »

dedndave

  • Member
  • *****
  • Posts: 8752
  • Still using Abacus 2.0
    • DednDave
Re: SP decrement with Push
« Reply #9 on: September 30, 2015, 07:12:39 PM »
if you disassemble that program, you will find that two PUSH'es are used