Page 1 of 1

MASM DUP issue

Posted: Sat Oct 22, 2011 3:51 pm
by kendfrey
I am working on a bootloader in MASM, and I think I have worked out all the subtle quirks of MASM, except this one. At the end of my code I have:

Code: Select all

db (510 - ($ - first)) dup (0) ; first is the label of the first instruction (due to lack of $$)
dw 0aa55h
When I try to assemble in WinAsm, I get "error A2092: count must be positive or zero" on the dup line. The smallest value it will take is 532 instead of 510. Then it works exactly as expected, when I build it into a COM file. It has a length of 534 bytes.
When I build it with the last two lines commented out, it creates a file 352 bytes long, so the error is not not occurring because my bootloader is too large.
Does anyone have an explanation for this weird phenomenon?

Re: MASM DUP issue

Posted: Sat Oct 22, 2011 4:04 pm
by Casm
kendfrey wrote:I am working on a bootloader in MASM, and I think I have worked out all the subtle quirks of MASM, except this one. At the end of my code I have:

Code: Select all

db (510 - ($ - first)) dup (0) ; first is the label of the first instruction (due to lack of $$)
dw 0aa55h
When I try to assemble in WinAsm, I get "error A2092: count must be positive or zero" on the dup line. The smallest value it will take is 532 instead of 510. Then it works exactly as expected, when I build it into a COM file. It has a length of 534 bytes.
When I build it with the last two lines commented out, it creates a file 352 bytes long, so the error is not not occurring because my bootloader is too large.
Does anyone have an explanation for this weird phenomenon?
Try:

db (510 - ($ - offset first)) dup (0)

Re: MASM DUP issue

Posted: Sat Oct 22, 2011 4:30 pm
by kendfrey
Casm wrote: Try:

db (510 - ($ - offset first)) dup (0)
No, that didn't work. BTW automatic dereferencing is one of my least favourite "features" of MASM.
I tried

Code: Select all

db (510 - ($)) dup (0)
and that still didn't work.

Re: MASM DUP issue

Posted: Sat Oct 22, 2011 4:41 pm
by Casm
kendfrey wrote:BTW automatic dereferencing is one of my least favourite "features" of MASM.
Don't worry, I have got more than enough dislikes of my own when it comes to all things Linux.

It may not be elegant, but you could try assembling it to see how large the binary is, and then manually put in however many bytes are necessary to bring it up to 510.

Re: MASM DUP issue

Posted: Sat Oct 22, 2011 4:46 pm
by kendfrey
If I can't get an answer here, then I will probably manually pad it. I just want to get it done automatically to avoid bugs. Still, I think that type of bug will be the least of my worries. :)

Re: MASM DUP issue

Posted: Tue Oct 25, 2011 10:06 am
by kendfrey
I have discovered the cause of the bug. It seems it is treating a short jmp as 10 bytes.

Code: Select all

.model tiny
.code

first:
jmp Main
Main:
cli
hlt

db (4 - ($ - first)) dup (0) ; should work but doesn't
end

Code: Select all

.model tiny
.code

first:
jmp Main
Main:
cli
hlt

db (12 - ($ - first)) dup (0) ; lowest value that does work
end
The first example fails with error A2092. The second example works exactly as expected.
Now if someone knows where a good place is for MASM bug reports, I could report it.

Re: MASM DUP issue

Posted: Tue Nov 01, 2011 3:01 pm
by qw
The answer is already here:
kendfrey wrote:When I try to assemble in WinAsm, I get "error A2092: count must be positive or zero" on the dup line. The smallest value it will take is 532 instead of 510.
No bug in MASM, your code is already 532 bytes, which is 22 bytes too big.

Re: MASM DUP issue

Posted: Tue Nov 01, 2011 3:04 pm
by kendfrey
WRONG. Maybe if you would have read the OP you wouldn't look so foolish.

Re: MASM DUP issue

Posted: Wed Nov 02, 2011 6:37 am
by qw
Could we see the entire source code please?

Re: MASM DUP issue

Posted: Wed Nov 02, 2011 10:42 am
by kendfrey
You can take a look at the example I gave of working vs non-working code. That is the simplest example I could get. That code was in a DosCom project in WinAsm, compiled with MASM32.