The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: bugthis on April 15, 2025, 08:20:16 AM

Title: [BX], OFFSET BUG - JWASM should throw error too, as MASM v5.10 does
Post by: bugthis on April 15, 2025, 08:20:16 AM
I already mentioned this in another thread about a different bug, but it only caused confusion, and I just tested this new old bug in a recent version of JWASM >= v2.19, and unfortunately, it's still there. So I'm starting a new thread here to avoid confusion.

This is the code:
Code (asm) Select
.MODEL SMALL, C
.STACK

.DATA
  STR_1 DB 160 DUP("*")

.CODE
START:
  MOV AX, @DATA
  MOV DS, AX
  MOV [BX], OFFSET STR_1 ; This line is intentionally wrong.
                         ; MASM returns an ERROR because the square brackets are invalid
                         ; current JWASM >= v2.19 doesn't complain and produces code
                         ; with undefined behavior.

;  MOV BX, OFFSET STR_1   ; This is the correct version

  MOV AH, 4Ch
  INT 21h
END START

That's the error message, MASM v5.10 throws:
CRASHME.ASM(11): error A2035: Operand must have size
...                             
  1 Severe Errors   

JWASM >= v2.19 compiles the code and the resulting executable produces undefined behavior.
JWASM should throw an error message too to prevent that.
Title: Re: [BX], OFFSET BUG - JWASM should throw error too, as MASM v5.10 does
Post by: sinsi on April 15, 2025, 08:28:01 AM
Both should be valid, MASM can't work out the size of an OFFSET so needs a WORD PTR override
MOV WORD PTR [BX], OFFSET STR_1
Title: Re: [BX], OFFSET BUG - JWASM should throw error too, as MASM v5.10 does
Post by: bugthis on April 15, 2025, 08:53:59 AM
I understand, thank you. Is JWASM able to determine the size of the operand in all cases?

EDIT:
If JWASM can do this automatically, at least a warning message would be helpful for compatibility reasons. Then the code will compile even if someone uses MASM.
Title: Re: [BX], OFFSET BUG - JWASM should throw error too, as MASM v5.10 does
Post by: sinsi on April 15, 2025, 09:06:54 AM
ML 6.14 has no trouble.
Isn't JWASM MASM 6.x compatible?
Title: Re: [BX], OFFSET BUG - JWASM should throw error too, as MASM v5.10 does
Post by: lucho on April 16, 2025, 08:06:18 PM
Quote from: bugthis on April 15, 2025, 08:53:59 AMI understand, thank you. Is JWASM able to determine the size of the operand in all cases?
The size of an offset is 16 bits, so "WORD PTR" isn't needed (nor is wrong). Although it's required if the source is an immediate number and the destination is memory, in this case it can be omitted.

QuoteIf JWASM can do this automatically, at least a warning message would be helpful for compatibility reasons. Then the code will compile even if someone uses MASM.
I don't think a warning is justified in this case. Why emulate quirks of very old MASM versions?
Title: Re: [BX], OFFSET BUG - JWASM should throw error too, as MASM v5.10 does
Post by: bugthis on April 17, 2025, 04:29:07 AM
Quote from: lucho on April 16, 2025, 08:06:18 PMThe size of an offset is 16 bits, so "WORD PTR" isn't needed (nor is wrong). Although it's required if the source is an immediate number and the destination is memory, in this case it can be omitted.
..
I don't think a warning is justified in this case. Why emulate quirks of very old MASM versions?
I understand. Therefore, I agree, assuming MASM >= v6.x also works without "WORD PTR" like JWASM. Unfortunately, I don't have MASM >= v6.x and haven't been able to test it with it.
Title: Re: [BX], OFFSET BUG - JWASM should throw error too, as MASM v5.10 does
Post by: lucho on April 18, 2025, 01:39:56 AM
Quote from: bugthis on April 17, 2025, 04:29:07 AMUnfortunately, I don't have MASM >= v6.x and haven't been able to test it with it.
Visual Studio includes MASM and can be downloaded and installed free of charge. See this topic in this forum:

https://masm32.com/board/index.php?topic=8732.0 (https://masm32.com/board/index.php?topic=8732.0)

By the way, the MASM32 (https://masm32.com/download.htm) package includes MASM 6.14. Take into account that MASM versions newer than 6.11d require Windows but work with the HX DOS extender too.
Title: Re: [BX], OFFSET BUG - JWASM should throw error too, as MASM v5.10 does
Post by: bugthis on April 18, 2025, 04:45:03 AM
Quote from: lucho on April 18, 2025, 01:39:56 AMVisual Studio includes MASM and can be downloaded and installed free of charge. See this topic in this forum:

https://masm32.com/board/index.php?topic=8732.0 (https://masm32.com/board/index.php?topic=8732.0)

By the way, the MASM32 (https://masm32.com/download.htm) package includes MASM 6.14. Take into account that MASM versions newer than 6.11d require Windows but work with the HX DOS extender too.
Thanks for the information. Strictly speaking, I don't have a more recent 16-bit version of MASM than the one I mentioned. The assembly language book I bought back then came with a 32-bit version of MASM for Windows on CD-ROM, but unfortunately, there wasn't a 16-bit version included. And I'm using Linux as host system and FreeDOS in a VM for programming in assembly, so no Windows.

The MASM 5.10 version included with the MS-DOS 4.0 source code release (https://github.com/microsoft/MS-DOS/tree/main/v4.0/src/TOOLS) is the only legal and still publicly available source for a 16-bit binary of MASM that I know of.

That's why I use JWASM. As a nice side effect, I can also put it through its paces. It is also included in the FreeDOS distribution.

I didn't know that the 32-bit Windows version of MASM was supposed to work under DOS with the HX DOS extender. I might try that.