4

I'm having problems understanding the DUP directive.
When I initialize an array with the following code:

t1 dd 2 dup(25ABh), 12h

I can see the following data stored in the data segment:

14 00 00 00 12 00 00 00

Why is it not AB 25 00 00 AB 25 00 12 00 00 00?

If I delete the dup directive and write t1 dd 25ABh, 12h instead, I get the expected
AB 25 00 00 12 00 00 00

In emu8086's GUI:
Screenshot of the result I get

What am I doing wrong?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Anonimo
  • 41
  • 2
  • `dup` is not an instruction, it's an assembler directive, and its behavior may vary between assemblers. So tell us what assembler you're using. – Nate Eldredge May 29 '21 at 19:27
  • 8086, running in emu8086 – Anonimo May 29 '21 at 19:30
  • 3
    I think you're using it properly; emu8086 might be broken. I don't have JWASM installed locally (an open-source assembler that uses MASM-style directives), but it's on https://tio.run/##Vc3NCsIwDAfwe54itynMYSs@gKJXX0BEYlNQadfRVN2evm46/DgE8iP/JCRi/cl1s@uDxOdcMSWCpJAZNfKtmejlan2ellhQAVCZwBaOkigmbGIwgIg@3NFSW6L6iC@jnCWM0muf1OE77sN6PlA6MeQcDH0b4muzr7@zeqF@o@N3W3MD290G3875CQ. (But I had to write a `_start` that makes a Linux write system call, so the 00 bytes are unprinting. Still, I do see `«%«%` so there's something repeated twice, before a printable `'a'` that I used instead of 12h) – Peter Cordes May 29 '21 at 19:45
  • 1
    (And BTW, this wouldn't be the first bug someone's run into in emu8086, and posted about on Stack Overflow. It's not a great assembler, and AFAIK isn't being developed / maintained anymore.) – Peter Cordes May 29 '21 at 22:07
  • 3
    It's an EMU8086 bug with `DD` directive (it should work with `DW`). You will have to avoid using DUP when the data size is a double word (DD). If you use a real MASM or compatible assembler it would work as you expect. – Michael Petch May 30 '21 at 00:48

0 Answers0