flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > High Level Languages > Why my C compiler puts nop instructions?

Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 95
Why my C compiler puts nop instructions?
I noticied this chain of instructions in my program:


Code:

0040117D  |.^EB AD          JMP SHORT 0040112C
0040117F  |> 90             NOP
00401180  |. 8B45 9C        MOV EAX,[EBP-64]




Why is it here? It's after jmp, and before the rest of the function, and there is one jump to this nop from above. It's either has something to do with alignment (doesn't look like it, overwise jump would happen to 401180, but now it happens to 40117f), or something with how processor works.
Post 24 Dec 2016, 09:02
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14854
Location: Lost in translation
It is the assembler that does this, not the HLL compiler. Most probably the C compiler is using a two pass assembler as the back end.
Post 24 Dec 2016, 10:13
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1384
Location: Toronto, Canada
Also notice the address 00401180 - it should be a branch to it from somewhere.
So, NOP is most likely for branch address alignment.
Post 24 Dec 2016, 15:49
View user's profile Send private message Send e-mail Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 95

AsmGuru62 wrote:
Also notice the address 00401180 - it should be a branch to it from somewhere.
So, NOP is most likely for branch address alignment.



Yes, that's the weird part: there is a jump to 401179, but not to 401180.

Maybe it's just a bug.
Post 24 Dec 2016, 19:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14854
Location: Lost in translation
If you look at the intermediate .asm / .s files created by the compiler for the assembler then the reason for the NOP can be determined.

But make sure you enable Intel mode, not AT&T mode, else your eyes will bleed.
Post 24 Dec 2016, 22:52
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.