Author Topic: Why does NASM compiler emit long strings of add instructions?  (Read 8835 times)

Offline paml27

  • Jr. Member
  • *
  • Posts: 37
I just used ndisasm to disassemble code I compiled with the NASM compiler.  I see several instances of long blocks where the instruction add [rax],al is repeated, like this:

00000425  0000              add [rax],al
00000427  0000              add [rax],al
00000429  0000              add [rax],al
0000042B  0000              add [rax],al
0000042D  0000              add [rax],al
0000042F  0000              add [rax],al
00000431  0000              add [rax],al
00000433  0000              add [rax],al
00000435  0000              add [rax],al

What do these sequences mean?  Wouldn't this be best reduced to fewer instructions? 


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Why does NASM compiler emit long strings of add instructions?
« Reply #1 on: March 20, 2020, 01:36:00 AM »
 Hi pam127,

As you can see in the second column, those are zeros. I think you will see that they are not executed. I hope not!

Best,
Frank

« Last Edit: March 20, 2020, 01:38:25 AM by Frank Kotler »

Offline paml27

  • Jr. Member
  • *
  • Posts: 37
Re: Why does NASM compiler emit long strings of add instructions?
« Reply #2 on: March 20, 2020, 04:57:35 PM »
Hi, Frank,

Yes, I see.  Thanks for clearing that up.  Do those function like no-ops? 


Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Why does NASM compiler emit long strings of add instructions?
« Reply #3 on: March 20, 2020, 10:23:36 PM »
Not really. They are a block of "data" that shouldn't be executed at all. To be clear... Nasm does not emit a long string of "add"s. Nasm does not emit any instruction mnemonics  at all. You and I provide those. Nasm converts them to nimbers. Ndisasm converts the numbers to mnemonics. But Ndisasm isn't very bright. Doesn't try to be. It attempts to disassemble everything - executable header, data, padding...

Agner Fog's "objconv" is much brighter! Look for it around "agner.org". I think you'll like it!

Best,
Frank