News:

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

Main Menu

What is the difference between WORD and WORD PTR

Started by StillLearningMasm, July 16, 2023, 04:50:37 PM

Previous topic - Next topic

NoCforMe

Quote from: FORTRANS on July 17, 2023, 11:17:57 PMHi,

Quote from: NoCforMe on July 17, 2023, 07:02:13 PM
Quote from: _japheth on July 17, 2023, 06:47:54 PMUsing 32-bit registers is perfectly valid in "16-bit code" and works quite well.

Hmm; don't you mean "using 16-bit registers is perfectly valid in 32-bit code"?

  No, using 32-bit registers works well in 16-bit (MS-DOS) code.  You
do use 16-bit addressing.  Just as you would use 32-bit addressing in
32-bit (Windows) code using 16-bit registers.  Not to mention using 8-bit
registers in either mode.

First of all, have we lost the OP here? Hope we haven't scared them off.

Second of all, hmmm, I thought you couldn't use 32-bit anything in 16-bit programming. Isn't that in real mode? Does anyone actually do that, use 32-bit regs in 16-bit mode? Seems a bit ... Frankenstinian to me.
Assembly language programming should be fun. That's why I do it.

FORTRANS

Quote from: NoCforMe on July 18, 2023, 04:29:58 AMSecond of all, hmmm, I thought you couldn't use 32-bit anything in 16-bit programming.

   I believe you thought wrong in this case.

QuoteIsn't that in real mode?

   Yes, in most cases, DOS is in real mode, or running under some
sort of memory manager that allows real mode programs to run.

QuoteDoes anyone actually do that, use 32-bit regs in 16-bit mode? Seems a bit ... Frankenstinian to me.

   I have done that.  Use 32-bit registers in a DOS program, mainly
to extend loops or counts past 65k iterations.  I would have to check
to make sure of other uses, as it has been a while.

Regards,

Steve N.

NoCforMe

Well. I stand (sit, actually) corrected.

OK, but my other objection (that you really can't use 16-bit registers for memory access in a 32-bit program) is valid. Just loaded up a program in Olly and checked a statement that accesses (the address of) a variable:

MOV EDX,OFFSET EdAsm.0040C94C

You can see that there's no way that value (40C94Ch) will fit into a 16-bit register. So an attempted access with, say, [BX] will fail here.
Assembly language programming should be fun. That's why I do it.

jj2007

If you manage to get access to the first 65536 bytes of your address space, mov eax, [bx] will work.

Rockphorr

Quote from: StillLearningMasm on July 16, 2023, 04:50:37 PMI receintly learned that MASM supports using BYTE, WORD etc without having PTR after it.
What is the difference between WORD and WORD PTR?

I created this code fragment:
mov ax, word [bx]
mov ax, word ptr [bx]

That creates this code:
 00000018  67& 66| 8B 47   mov ax, word [bx] ;same as mov ax,[bx + 2]
      02

 0000001D  67& 66| 8B 07   mov ax, word ptr [bx] ;same as mov ax,[bx]

So what is PTR? I thought it might be the same as offset but it dpesn't seem to be and MASM does a terrible way of explaining it for me.

Thank you,
StillLearningMasm



mov ax,[bx]  is equalent  mov ax, word ptr [bx]

when you skip "ptr" it is assembled like mov ax, 2[bx] couse sizeof(word)=2