The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: shaqywacky on August 15, 2011, 03:03:26 AM

Title: PTR problems
Post by: shaqywacky on August 15, 2011, 03:03:26 AM
Hello again!

I'm still working on my decimal to ascii converter and I've run into a problem.  I've narrowed it down to this simple code block.  It should take a number(DWORD) and try to put it in a byte in memory, using PTR.

So here's the code, I took out the unnecessary parts:

.DATA
numb DWORD 7
charb BYTE 31h



.CODE
main PROC

mov eax, numb ; Move numb into eax
lea ebx, charb ; Load the address of charb into ebx
mov BYTE PTR [ebx], eax ; Attempt(unsuccessfully) to load 7 from eax into charb

xor eax, eax ;exit
ret

main ENDP

It bring up an error that says :"'mov BYTE PTR [ebx], eax': Instruction operands must be the same size".  With my understanding of PTR is that the point of PTR is to make it so you can use operands that are not the same size.  So I'm pretty confused.

Thanks guys.
Title: Re: PTR problems
Post by: hfheatherfox07 on August 15, 2011, 03:39:28 AM
I saw your post and i remembered this source in MASM from 2005

I hope this helps you ... it converts from dec to hex to bin
Title: Re: PTR problems
Post by: shaqywacky on August 15, 2011, 03:52:13 AM
Thanks, but I was more doing it just to become more familiar with assembly and notice things I don't understand.
Title: Re: PTR problems
Post by: dedndave on August 15, 2011, 04:35:11 AM
a dword is 32 bits
a byte is 8 bits
you can't put 20 pounds of shit in a 5 pound sack   :lol

there are a couple ways to go about grabbing the lower byte of a dword, however

look up the MOVZX and MOVSZ instructions
another way....
        mov     eax,SomeDword
        mov     SomeByte,al
Title: Re: PTR problems
Post by: hfheatherfox07 on August 15, 2011, 04:43:17 AM
The problem of "Instruction operands must be the same size" was addressed here:


http://www.masm32.com/board/index.php?PHPSESSID=1fba624f0f2404ac83e75becf8fb6c7b&topic=3165.0
Title: Re: PTR problems
Post by: shaqywacky on August 15, 2011, 07:02:28 AM
Yep, I did not understand how PTR worked at all.  I was under the impression that when you did something like

;assume test is a byte
mov BYTE PTR test, eax

would make eax act as if it were a byte size.  That seem to be completely wrong.  I have to look it up tomorrow because I have to wake up for work in about 6 hours.

Quote from: dedndave on August 15, 2011, 04:35:11 AM
another way....
        mov     eax,SomeDword
        mov     SomeByte,al

Now I feel dumb, that was so obvious.   :(

@hfheatherfox07

Thanks for the link, I'm sure it will help but I'll have to read that tomorrow.