It is currently Sun Jul 22, 2018 9:28 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: ASM Output Question regarding push/pop
PostPosted: Tue Apr 10, 2018 11:11 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 12, 2008 1:25 pm
Posts: 367
Location: The Netherlands
Hi All,

I'm working on a simple tool for my own optimization purposes and while I was working on this tool, I noticed something I don't understand. Now, I think this might be some alignment or optimization method I don't know, however I figured I'd ask the question here;

I have a structure named derp within a procedure, and I'm accessing index 100 like so:
Code:
single = derp\chars[100]


The produced assembly code on x64 Linux is:
Code:
; single = derp\chars[100]
  MOV    dword [CLN],60 ; pbcompiler -l option
  LEA    rbp,[rsp+48]
  PUSH   rbp
  POP    rbp
  MOVSX  rax,byte [rbp+100]
  PUSH   rax
  POP    rax
  MOV    byte [v_single],al


However something I don't understand are the push rbp, pop rbp and push rax, pop rax instructions. Can anyone explain to me why those are pushed and popped immediately?

_________________
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Tue Apr 10, 2018 4:53 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13330
Location: France
Is this code in debug mode ? The peephole optimiser should catch these cases and remove them in release. It's useless code, only here because the code generator works step by step and output the asm immediately.


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Tue Apr 10, 2018 5:08 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 12, 2008 1:25 pm
Posts: 367
Location: The Netherlands
Hi Fred! This was compiled with 'pbcompiler -c -l -e outname'. So I'm assuming the debugger is not enabled then, right? I simply enabled the OnError lines support

_________________
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Tue Apr 10, 2018 6:09 pm 
Offline
User
User
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 98
because "pb" translates your code word by word to asm and is very difficult to generate it without junk code.

if you want optimize your code , learn asm!

_________________
interested in Cybersecurity..


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Tue Apr 10, 2018 6:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 12, 2008 1:25 pm
Posts: 367
Location: The Netherlands
CELTIC88 wrote:
because "pb" translates your code word by word to asm and is very difficult to generate it without junk code.

if you want optimize your code , learn asm!


That's a weird response, I know ASM - I merely was asking the reasoning behind this code generation and as you can see from Fred's response, there is a reasoning behind it.

_________________
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Wed Apr 11, 2018 11:11 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13330
Location: France
I will take a closer look to see why it's not removed in release mode.


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Thu Apr 12, 2018 10:10 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 12, 2008 1:25 pm
Posts: 367
Location: The Netherlands
Fred wrote:
I will take a closer look to see why it's not removed in release mode.


Thank you, however is this not because I used the commented asm option? Even though I don't consider this to be a debug mode, it still is an intermediate step isn't it?

_________________
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Thu Apr 12, 2018 10:28 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13330
Location: France
It should be the final file which is sent to the assembler, so no further pass are done on it (it's done like this so you can tweak the output file without wondering if it will be parsed again by the compiler).


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Thu Apr 12, 2018 1:47 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 12, 2008 1:25 pm
Posts: 367
Location: The Netherlands
Yes that is what I always used it for, good to know. Would you like me to test multiple PureBasic versions with this same piece of code? This was produced using the latest PB on Linux x64

_________________
Image
Bas Groothedde,
Imagine Programming

I live in a philosophical paradoxal randome filled with enigma's!


Top
 Profile  
Reply with quote  
 Post subject: Re: ASM Output Question regarding push/pop
PostPosted: Thu Apr 12, 2018 1:51 pm 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13330
Location: France
I don't bother about it, I will take a look.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye