MASM DUP issue

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

MASM DUP issue

Post 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?
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: MASM DUP issue

Post 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)
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: MASM DUP issue

Post 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.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: MASM DUP issue

Post 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.
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: MASM DUP issue

Post 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. :)
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: MASM DUP issue

Post 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.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: MASM DUP issue

Post 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.
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: MASM DUP issue

Post by kendfrey »

WRONG. Maybe if you would have read the OP you wouldn't look so foolish.
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: MASM DUP issue

Post by qw »

Could we see the entire source code please?
kendfrey
Member
Member
Posts: 45
Joined: Mon Oct 17, 2011 7:44 am

Re: MASM DUP issue

Post 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.
Post Reply