News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

push 0 appearing in between a function call ?

Started by gelatine1, June 20, 2014, 05:21:26 AM

Previous topic - Next topic

MichaelW

MASM 5.1 would report an attempt to push or pop a byte register as:

error A2058: Byte register illegal
Well Microsoft, here's another nice mess you've gotten us into.

nidud

#16
deleted

jj2007

Quote from: nidud on June 21, 2014, 05:56:37 AM
It's also possible to use an unaligned stack to some extent
;)
include \masm32\include\masm32rt.inc
.code
start:   
  push ax
  MsgBox 0, "Hello World", "Wow...", MB_OK
  pop ax
  exit
end start

MichaelW

For 16-bit operands, since the processor knows what the operand size and stack-address size are, it sign or zero extends the operand as necessary.


;----------------------------------------
; Returns the maximum alignment of _ptr.
;----------------------------------------

alignment MACRO _ptr
    push ecx
    xor eax, eax
    mov ecx, _ptr
    bsf ecx, ecx
    jz @F
    mov eax, 1
    shl eax, cl
  @@:
    pop ecx
    EXITM <eax>
ENDM

include \masm32\include\masm32rt.inc
.code
start:

  mov ebx, esp
  push ax
  mov esi, esp
  pop ax
  mov edi, esp
  printf("%d\t%d\t%d\n",alignment(ebx),alignment(esi),alignment(edi))

  mov ebx, esp
  push ds
  mov esi, esp
  pop ds
  mov edi, esp
  printf("%d\t%d\t%d\n\n",alignment(ebx),alignment(esi),alignment(edi))

  inkey
  exit
end start


4       4       4
4       4       4

Well Microsoft, here's another nice mess you've gotten us into.

Gunther

Jochen,

your example works well under Windows 7 - 32 and 64 bit.

Gunther
You have to know the facts before you can distort them.

jj2007

Quote from: Gunther on June 21, 2014, 07:56:58 PM
your example works well under Windows 7 - 32 and 64 bit.

Under Windows XP it shows a very strange box. So they "fixed" that problem, in order to ensure that lousy coders have something to chase in their sleepless nights :biggrin:

nidud

#21
deleted

Gunther

Jochen,

I've tested it with Win XP as virtual machine and it works well.

Gunther
You have to know the facts before you can distort them.

nidud

#23
deleted

dedndave

masm behaves differently for PUSH and INVOKE

Gunther

You have to know the facts before you can distort them.

dedndave

well - versions 6.14 and 6.15 seem to - lol
otherwise, we wouldn't be having this discussion

MichaelW

Quote from: nidud on June 22, 2014, 02:18:55 AM
Quote from: MichaelW on June 21, 2014, 07:48:51 PM
For 16-bit operands, since the processor knows what the operand size and stack-address size are, it sign or zero extends the operand as necessary.
I don't think that's correct, at least not on my machine

On further examination it is correct for segment registers only, and my alignment macro is apparently broken, or at least for the way I used it.
Well Microsoft, here's another nice mess you've gotten us into.

jj2007

Quote from: Gunther on June 22, 2014, 12:36:52 AM
I've tested it with Win XP as virtual machine and it works well.

Interesting. This is what I see on XP SP3 (and whenever I see it, I know it's the stack...)

nidud

#29
deleted