flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Signed value in macro/load

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 27 Sep 2014, 20:58
Code:
macro call Dst
{
local ..Str
..Str: call Dst
load byte A1st from ..Str
if A1st=0xE8
load dword A2nd from (..Str+1)   ; How to get signed value of A2nd?
  if A2nd<-32768 | A2nd>32767
    err
  end if
end if
}

use32
org 0x0
call $-32
    

A2nd equals for example 0xFFFFFFC0 after load.
How to code "MOVSX" in macro?
Maybe add to fasm optional directive "LOAD SIGNED from"?

_________________
smaller is better
Post 27 Sep 2014, 20:58
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 27 Sep 2014, 22:09
You can use this simple macro devised by LocoDelAssembly:
Code:
macro def [name, size]
{ 
   macro signExtend.#name v.out, v.in 
   \{ 
      v.out = v.in or (0 - v.in shr (size - 1)) shl (size - 1) 
   \} 
} 

def byte,  8,\ 
    word, 16,\ 
   dword, 32,\ 
   qword, 64 

purge def    

Your sample can be adapted to use it this way:
Code:
macro call Dst 
{ 
local ..Str 
..Str: call Dst 
load A1st byte from ..Str
if A1st=0xE8 
load A2nd dword from (..Str+1)   ; How to get signed value of A2nd?
signExtend.dword A3rd,A2nd
  if A3rd<-32768 | A3rd>32767
    err 
  end if 
end if 
} 

use32 
org 0x0 
call $-32     
Post 27 Sep 2014, 22:09
View user's profile Send private message Visit poster's website Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc 28 Sep 2014, 01:13
CandyMan
I think, much better idea would be to compare $-localDst (where localDst = Dst) with the bounding values than to load the displacement from the encoded instruction.

_________________
Faith is a superposition of knowledge and fallacy
Post 28 Sep 2014, 01:13
View user's profile Send private message Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 413
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 28 Sep 2014, 09:03
Thanks.

_________________
smaller is better
Post 28 Sep 2014, 09:03
View user's profile Send private message 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


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.