News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

PTR problems

Started by shaqywacky, August 15, 2011, 03:03:26 AM

Previous topic - Next topic

shaqywacky

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.

hfheatherfox07

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

shaqywacky

Thanks, but I was more doing it just to become more familiar with assembly and notice things I don't understand.

dedndave

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

hfheatherfox07


shaqywacky

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.