Author Topic: wrong length in bytes when assembling an instruction  (Read 80 times)

Offline RuudB

  • Jr. Member
  • *
  • Posts: 21
wrong length in bytes when assembling an instruction
« on: December 04, 2018, 04:31:42 PM »
Hello,

I'm busy re-engineering the BIOS-es of old IBM-XT and I'm trying to generate BIN files that are the same as the original as exactly as possible. So far I ran into the problem that NASM doesn't assemble an instruction into the same bytes as the original assembler used to create the original BINs. For example: "8B D9" is translated by NASM's disassembler into "mov bx,cx". But the assembler translates this instruction into "89 CB". I can live with that because I tested several of the NASM generated BIOS-es and they worked fine. But if somebody knows a way to tell NASM to use the other code, it would make me happy.

Today I ran into a real problem. "81 E2 0E 00" is disassembled into "and dx,0xe" and that is assembled into "83 E2 0E". I now miss one byte. I tried with adding "word", using 000Eh, 0x000E and combinations of it but with no result. OK, I could fill it up with a NOP but I will only do that when there is no other solution.

Who can tell me what to do to get at least my original length of four bytes?

Many thanks in advance!

Kind regards, Ruud Baltissen

 


Offline dreamCoder

  • Full Member
  • **
  • Posts: 100
Re: wrong length in bytes when assembling an instruction
« Reply #1 on: December 04, 2018, 07:04:37 PM »
Not familiar with 16-bit code but most likely you're compiling with different optimization flags

nasm -f bin something.asm          ;optimization on (default. shortened)
nasm -f bin something.asm -O0   ;optimization off (longer bytes)

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2329
  • Country: us
Re: wrong length in bytes when assembling an instruction
« Reply #2 on: December 04, 2018, 08:40:25 PM »
"strict word" may do what you want. In general, if you want binary identical code with some other assembler, use the other assembler.

Best,
Frank


Offline RuudB

  • Jr. Member
  • *
  • Posts: 21
Re: wrong length in bytes when assembling an instruction
« Reply #3 on: December 05, 2018, 07:27:01 AM »
Hello,


> nasm -f bin something.asm -O0   ;optimization off (longer bytes)

Unfortunately that didn't work.


> "strict word" may do what you want.

And it did, thank you!


> In general, if you want binary identical code with some other assembler, use the other assembler.

If you can tell me what assembler IBM used in 1981, I will. But I also wonder if this assembler can handle the layout used by NASM. MASM already cannot handle it so I don't think an older program will.

And again, thank you both for your support!

Kind regards, Ruud Baltissen



Offline dreamCoder

  • Full Member
  • **
  • Posts: 100
Re: wrong length in bytes when assembling an instruction
« Reply #4 on: December 05, 2018, 02:10:03 PM »
That should do the trick, and has similar effect as Frank's suggestion.

What the -O0 does is to produce the longer encoding format of your binary without any space-saving optimization. The keyword "strict" does the same trick if you're compiling using the the default optimization. "strict" works per instruction. If you can't afford to do it line by line, "-O0" is the way to go. But anything that works should be fine.

Offline RuudB

  • Jr. Member
  • *
  • Posts: 21
Re: wrong length in bytes when assembling an instruction
« Reply #5 on: December 06, 2018, 11:26:00 AM »
Hallo DreamCoder,

> That should do the trick, and has similar effect as Frank's suggestion.

In my case it did not work. But I would not wonder if I, again, did something wrong :) But we are talking about five additions of STRICT.

Anyway, the PC now boots fine with the NASM version of the original sources of the first ROM of April 24th 1981!

Kind regards, Ruud Baltissen

Offline dreamCoder

  • Full Member
  • **
  • Posts: 100
Re: wrong length in bytes when assembling an instruction
« Reply #6 on: December 06, 2018, 11:39:54 AM »
first ROM of April 24th 1981!

Whhooaah! Reminds me of ET and stuff like that  :P
Btw, stay healthy.