Hi

I'm a little confused when to use Byte Ptr in my code. For example if I do something like this


.data
ErrCode db 0


.code
mov ,1
....
....
....

xor eax,eax
mov al,
.if eax==0
do some stuff

Will MASM be clever enough to figure that ErrCode is a declared as a byte so when the immediate value of 1 is moved to it stored a byte there (and not a word or anything else). 

In general I'd like to know if MASM does not spit out an error message is it safe to assume it knows when immediate (or other) data should be a byte, word or double word? 

TIA
dicky
Posted on 2005-10-02 13:49:25 by dicky96
dicky96,
    Why don't you try to store a constant greater than a byte and see what happens?  And your test should be, .IF AL == 0 . Ratch
Posted on 2005-10-02 14:55:17 by Ratch
OK yepp that kinda proves the point when i tried a value over 1 byte in size. 

error A2070: invalid instruction operands
warning A4014: instructions and initialized data not supported in BSS segments

I'm not sure what the second message meant (or even what a BSS segment is?)

Can I trust masm to always do "the right thing" in these cases or is it possible for it to get confused - I can imagine how that would lead to some crazy software bugs.

Oh BTW why in my above example should I say
.if al==0? 

Seeing as I xor eax,eax first then surely

.if eax==0 amounts to the same thing? 

Posted on 2005-10-02 16:33:05 by dicky96
BSS is ancient terminology for uniinitialized memory space.

It corresponds with a .data? segment.
Posted on 2005-10-02 19:13:31 by tenkey
dicky96,


Oh BTW why in my above example should I say
.if al==0? 

Seeing as I xor eax,eax first then surely

.if eax==0 amounts to the same thing? 


    .Because .IF AL == 0 works whether you zero out EAX or not.  Why waste memory and CPU time on a needless operation?  Ratch
Posted on 2005-10-02 19:35:06 by Ratch
Dicky,

In MASM you require the data size specifiers when te assembler has no way of working out the size of the operands. This is usually when one operand is a memory operand and the other is an immediate value.

    mov , 1    ; error, assembler does not know how big "1" is.
    mov DWORD PTR , 1

Basically MASM will use the fully specified form with no problems even when it does not need it and much of the code you see is actually a shorthand because the parser in MASM will work out the size if it can from a register or in some instances a memory operand size that is already known.
Posted on 2005-10-02 19:45:15 by hutch--