NASM - The Netwide Assembler
NASM Forum => Using NASM => Topic started by: RuudB on April 28, 2014, 12:04:57 PM
-
Hallo allemaal,
As already mentioned in another thread, http://forum.nasm.us/index.php?topic=1846.0 (http://forum.nasm.us/index.php?topic=1846.0), I wrote my own disassembler. So far it works great, I only need to fine tune 8087 opcodes. Assembling the result is something else. Assembling disassembled BINs that originally were created with NASM seems no problem so far. But when the BINs were created with other assemblers I ran into two problems:
- different code is used
For example: 'or al,al' is assembled by NASM to '08 C0'. But the original code is '0A C0'. The difference is the 'from/to' bit and the result in the end is exactly the same. But I wonder if there is a way to get the original code again.
- different length of code
This is a problem. And I give you the most extreme example:
Original: 89 95 0000 mov word ptr ds:[0][di],dx
NASM: 8915 mov [di+00000h],dx
I understand why NASM does this; this code does the same but needs less bytes. My problem: I'm using NASM to recreate old BIOSes and now I find that after assembling the generated source I am missing several bytes. Which in this case means that, for example, the well known 'jmp 0F000h:coldboot' is not to be found at the usual address 0FFF0h anymore.
My main question: is there a way to force NASM to use the '+00000h' part as well?
Another example:
Original: 8B 90 0008 mov dx,word ptr d_0007+1[bx+si]
NASM: 8B5008 mov dx,[bx+si+00008h]
Any help or comment is welcome!
With kind regards / Met vriendelijke groet, Ruud Baltissen
www.Baltissen.org (http://www.Baltissen.org)
-
Hallo Ruud,
Well...
mov [word di + 0], dx
mov dx. [bx + si + 800h]
... seems to get you a little closer. I'm not sure the second one's right. (the "word" specifier seems to need to be first in the brackets). I don't think there's a way to flip the "from/to" bit (there's the "db" option, but that's too ugly to contemplate).
Best,
Frank
-
Hallo Frank,
mov [word di + 0], dx
... seems to get you a little closer.
It did! I know that the use of 'word' and 'byte' is a must in some cases. But I hadn't seen any example like yours yet.
Thank you very much!
With kind regards / Met vriendelijke groet, Ruud Baltissen
www.Baltissen.org
-
Hallo Frank,
I updated my disassembler but at the end I ran into just one code I wasn't able to tackle:
Original: 81 E7 000E and di,0Eh
NASM: 83E70E and di,word 0000Eh
As you can see the 'word' has no effect here. I also tried 'and word di,0000Eh' but with the same result. If you, or anyone else, have a trick in your sleeve that could help, I would be gratefull.
With kind regards / Met vriendelijke groet, Ruud Baltissen
www.Baltissen.org
-
Nasm is rather stubborn about doing the signed byte optimizations. In order to convince Nasm that you really really want the word form...
and di, strict word 0Eh
Someone explained to me once why it had to be that way, but I forget. I consider it a PITA, but I rarely need the "long form" anyway.
Oh, wait. To get 81 E7 00 0E, you'd want 0E00h which is a word anyway. In any case, the "strict" keyword may help you beat Nasm into submission.
Best,
Frank
-
Hallo Frank,
In any case, the "strict" keyword may help you beat Nasm into submission.
That is the trick, thank you !!!
Kind regards, Ruud