flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Understanding IRP, IRPS, IRPV

Author
Thread Post new topic Reply to topic
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
A small example I found on my PC and thought might be helpful. To view result, click Compile or press Ctrl+F9.

Code:
; EXAMPLE: IRP, IRPS, IRPV

; irp/s iterates through a list of symbols
; separated with commas (irp) or spaces (irps)

; display ABC.123.XYZ using irp/s

irp x,\
 'A','B','C','.' {
 display x
}

irps x,\
 '1' '2' '3' '.' {
 display x
}

e equ 'X','Y','Z'

irp x, e { display x }

restore e

macro display.nl { display 0Dh, 0Ah }

display.nl

; xor eax/ecx/edx

irps x,\
 'a' 'c' 'd' {
 r equ 'e'#x#'x'
 display 'xor ', r, ',', r
 display.nl
 restore r
}

; create a list then iterate through it.
; first match is needed to convert/expand
; the single "name token" e into list a,b,c

e equ 1,2,3      ; create list

n=0              ; count # items...
match a, e {     ; convert/expand
 irp x, a \{     ; iterate through list
  n=n+1
 \}
}

display '#',\    ; display #
 n+'0', ':', ' '

match a, e {     ; convert/expand
 irp x, a \{     ; iterate through list
  display \      ; display all items
   x+'0', ' '
 \}
}
display.nl

macro display.list [e] {
 common
  match a, e \{  ; convert/expand
   irps x, a \\{ ; iterate through list
    display \    ; display all items
     x+'0', ' '
   \\}
  \}
}

display.list 4 5 6 7
display.nl

restore e ; finished

; irpv iterates through the stacked list
; of equate definitions. if the equate is
; undefined, irpv will not be processed

e equ 7       ; create equate stack
e equ 6       ; of digits
e equ 5

n=0           ; count # equates
irpv x, e {   ; iterate through stack
 n=n+1
}

display \     ; display # equates
 '#', n+'0',\
 ':', ' '

irpv x, e {   ; iterate through stack
 display \    ; display all digits
  x+'0', ' '
}
display.nl

irpv x, e {   ; restore equates
 restore e
}             ; now, e is undefined

; ensure 'e' was properly restored.
; to see this message, comment
; "; restore e" above

irpv x, e {
 'Error: Not restored'
}

; do this inside of a macro...

macro test1 [p] {
 common            ; once...
  local list
  list equ
  match e, p \{    ; collect and
   restore list    ; store parameters
   irps x, e \\{   ; in equate stack
    list equ x
   \\}
  \}
  irpv x, list \{  ; iterate through
   display \       ; equate stack
    x+'0', ' '     ; display digits
  \}
  display.nl
  irpv x, list \{  ; restore each one
   restore list
  \}
}

test1 4 3 2 1

; OUTPUT:

; ABC.123.XYZ
; xor eax,eax
; xor ecx,ecx
; xor edx,edx
; #3: 1 2 3
; 4 5 6 7
; #3: 7 6 5
; 4 3 2 1    
Post 15 Jul 2014, 21:04
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
m3ntal,

Are you sure that in
Code:
e equ 'X','Y','Z'

irp x, e { display x }    
irp iterates? It expands to display e, then e is substituted with 'X','Y','Z' as usual. Later you're using match to expand symbolic constants, why not here?
Post 16 Jul 2014, 02:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Perhaps a better way to show if expansion is active or not is to use:
Code:
irp x, e { display x,'-' }    
If you see three dashes then you know that IRP iterated, else you'll see only one dash and know that e was not expanded. For a newbie this kind of thing would be informative.
Post 16 Jul 2014, 02:08
View user's profile Send private message Visit poster's website Reply with quote
m3ntal



Joined: 08 Dec 2013
Posts: 296
m3ntal
baldr: I thought irp/x was an abbreviation for iterate/repeat. Match is not needed in that case.

Seems like you're always trying to discredit me, but what do you contribute? You have knowledge of macros? Please write some tutorials, make a web site, do something productive and you'll feel good about yourself.

Thanks for the suggestion, revolution.
Post 16 Jul 2014, 03:48
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
m3ntal wrote:
Seems like you're always trying to discredit me…
Please don't be overly paranoid. Was my comment rude/embarrassing/defamatory? If you think so, please accept my sincere apologies.

OTOH, I thought it deserves to mention that irp* instant macros don't substitute symbolic constants (actually you'd used match several times later in the source exactly to overcome this).

Hope this helps.
Post 16 Jul 2014, 07:25
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.