flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Replacing a part of value

Author
Thread Post new topic Reply to topic
Jin X



Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
I want to define some value and then perform some macro which must use this value with replacing one literal with another.
E.g.
Code:
define val mov ax,[reg+si]

macro use x
{
  local new, is_set
  new equ
  irps v, val \{
    is_set equ 0
    match =reg, v \\{
      new equ new x
      is_set equ 1
    \\}
    match =0, is_set \\{
      new equ new v
    \\}
  \}
  new
}

use bx    
Macro 'use' must replace 'reg' by parameter 'x'.
This code doesn't work because 'irps v, val' substitutes just chars 'val' in 'v' but not value of 'val'.
How to fix this code?
Post 28 Feb 2021, 19:02
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
I wrapped everything in 'match' and got what I want Smile
Post 28 Feb 2021, 19:09
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
But if I want to make universal macro?
Code:
define val mov ax,[reg+si]

macro replace_and_use x, y, val&
{
  local result, is_set
  result equ
  match val, val \{
    irps v, val \\{
      is_set equ 0
      match =y, v \\\{
        result equ result x
        is_set equ 1
      \\\}
      match =0, is_set \\\{
        result equ result v
      \\\}
    \\}
  \}
  result
}

replace_and_use reg, bx, val    

Of course, match =y, v doesn't work. How can I compare 2 symbol values?
Post 28 Feb 2021, 19:15
View user's profile Send private message Reply with quote
Jin X



Joined: 06 Mar 2004
Posts: 104
Location: Russia
Jin X
Why "solved"? The last question is not solved... :-/
Post 04 Mar 2021, 20:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 18182
Location: In your JS exploiting you and your system
revolution
I think it was a cross post. I saw your message saying you got what you wanted and I guess you posted the follow-up question at the same time as I marked it solved.

You can change the title at any time by editing your first post. So if a mod makes a mistake you can fix it.
Post 05 Mar 2021, 02: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


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

Website powered by rwasa.