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 > Compiler Internals > Why PUSH/POP use irps way

Author
Thread Post new topic Reply to topic
l4m2



Joined: 15 Jan 2015
Posts: 570
Why PUSH/POP use irps way

Code:
PUSH 3 4

compiled into

Code:
PUSH 3
PUSH 4

but

Code:
PUSH 3 -4

compiled into

Code:
PUSH -1

.
Easily we know why it happens but what if we reach

Code:
macro foo ab {
  push a b
  call 0xbeef
}
foo 3, -7 

? You may get difficulty in understanding what wrong it is
Post 25 Jul 2016, 11:18
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 206
Location: film "CandyMan" directed through Bernard Rose

Code:
3-4=-1


you must define operand size

Code:
push dword 3 dword -4


_________________
smaller is better
Post 25 Jul 2016, 12:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14463
Location: Eta Argus
The algorithm is greedy. So "3 -4" is evaluated first and then passed to the instruction encoder. You can force it like this:

Code:
push 3 (-4)

This breaks the evaluation into two parts because as a whole it is not a valid expression.
Post 25 Jul 2016, 19:17
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1173
Location: Unknown
Offensive post removed.


Last edited by HaHaAnonymous on 25 Jul 2016, 20:01; edited 1 time in total
Post 25 Jul 2016, 19:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14463
Location: Eta Argus
Additional: For your macro you can do this:

Code:
macro foo ab {
  push (a) (b)
  call 0xbeef
}
foo 3, -7

Post 25 Jul 2016, 19:51
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.