The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: fdig on February 17, 2006, 08:17:50 PM

Title: push ah
Post by: fdig on February 17, 2006, 08:17:50 PM
Hi,

why i cannot push byte registers (ah) on stack?

Here's what ml.exe assembler says:


error A2149: byte register cannot be first operand


greetings
Title: Re: push ah
Post by: Mark Jones on February 17, 2006, 08:24:49 PM
Hello Fdig. AH is a BYTE and the stack in 32-bit windows is comprised of DWORD values, hence the two are incompatible. If you must push AH, try this:


    xor ecx,ecx
    mov cl,ah
    push ecx


Is this for DOS assembly or WIN32 assembly?

Try looking in the ASMINTRO.HLP file - very useful stuff in there. Have Fun!
Title: Re: push ah
Post by: Ratch on February 17, 2006, 10:31:20 PM
fdig,

     Or the following.  Ratch


MOVZX ECX,AH
PUSH ECX
Title: Re: push ah
Post by: zcoder on February 17, 2006, 10:38:11 PM
Or if nothing is in AL
       PUSH EAX


Zcoder....
Title: Re: push ah
Post by: arafel on February 17, 2006, 11:21:37 PM
how about:

sub     esp, 4
mov     [esp], byte ptr ah


:wink
Title: Re: push ah
Post by: zooba on February 18, 2006, 01:17:35 AM
Quote from: arafel on February 17, 2006, 11:21:37 PM
how about:

sub     esp, 4
mov     [esp], byte ptr ah


:wink

Doesn't necessarily mean the rest of the value is clear:

push 0
mov  [esp], ah


:U
Title: Re: push ah
Post by: arafel on February 18, 2006, 02:03:01 AM
Quote from: zooba on February 18, 2006, 01:17:35 AM
Doesn't necessarily mean the rest of the value is clear:

Well, no one mentioned the necessity for the whole dword to be cleared. Original intent was to store a single byte on the stack, presumably for later extraction of the same single byte.
Title: Re: push ah
Post by: zooba on February 18, 2006, 02:49:38 AM
Quote from: arafel on February 18, 2006, 02:03:01 AM
Quote from: zooba on February 18, 2006, 01:17:35 AM
Doesn't necessarily mean the rest of the value is clear:

Well, no one mentioned the necessity for the whole dword to be cleared. Original intent was to store a single byte on the stack, presumably for later extraction of the same single byte.


Fair point. However, it does mean that EAX can be popped and the value is zero-extended already :bg
Title: Re: push ah
Post by: fdig on February 18, 2006, 12:33:53 PM
Quote from: Mark Jones on February 17, 2006, 08:24:49 PM
Hello Fdig. AH is a BYTE and the stack in 32-bit windows is comprised of DWORD values, hence the two are incompatible.

Hi, Ah ok!

Quote
Is this for DOS assembly or WIN32 assembly?

DOS assembly.

Thx for the many answers ;)
Title: Re: push ah
Post by: MichaelW on February 18, 2006, 01:29:34 PM
MASM returns an error because the processor does not support pushing (or popping) a byte-size register or memory operand, regardless of the stack address size.