NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: paml27 on March 20, 2020, 01:09:02 AM

Title: Why does NASM compiler emit long strings of add instructions?
Post by: paml27 on March 20, 2020, 01:09:02 AM
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? 

Title: Re: Why does NASM compiler emit long strings of add instructions?
Post by: Frank Kotler 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

Title: Re: Why does NASM compiler emit long strings of add instructions?
Post by: paml27 on March 20, 2020, 04:57:35 PM
Hi, Frank,

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

Title: Re: Why does NASM compiler emit long strings of add instructions?
Post by: Frank Kotler 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