flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Macro with size of operand

Author
Thread Post new topic Reply to topic
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 04 Mar 2012, 11:13
Sorry, I have again a macro problem with parameters.

Following code:

Code:
macro REM line,start,end,val
  {
                db      line shr 8      ; line number of REM statement
                db      line and $FFh   ; line number of REM statement
           if val eq
                dw      end-start+2     ; lenght of line
                db      $EA             ; REM statement (token code)
           else
                db      ???+2
                db      $EA             ; REM statement (token code)
                db      val
                db      NEWLINE
           end if
  }
    


It can have either 3 or 4 parameters.
If last parameter fails there will be a default construction with "following" data in the source which used the macro.

If last parameter is present, parameter 2 and 3 are ignored and the string given in val has to be integrated but I need also the length of the string given in parameter val. Now I did put ??? for it.

AND "if val eq" throws an error when compiling, but this is still a copy of the given example in the FASM manual:

Code:
    macro mov op1,op2,op3
     {
      if op3 eq
        mov   op1,op2
      else
        mov   op1,op2
        mov   op2,op3
      end if
     }
    


Thanks for any help. Wink

By the way, its the construction of a REM statement for a BASIC interpreter. Cool
Post 04 Mar 2012, 11:13
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 04 Mar 2012, 11:35
Firstly "$FFh" is not right. Try with "$FF" or "0FFh"

Secondly, you can't use "end" as a parameter, it is a directive.
Post 04 Mar 2012, 11:35
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 04 Mar 2012, 12:33
revolution wrote:
Firstly "$FFh" is not right. Try with "$FF" or "0FFh"

Secondly, you can't use "end" as a parameter, it is a directive.

Okay, already corrected $FFh in $FF.
And changed parameter end to ed.

But same error as before regarding last parameter:
"illegal instruction" => "if eq"
But this was exactly the example in FASM main documentation.

So how can I ask if parameter val is given or not ?
I thought about a misstype of eq which should be equ but this throws an error on "else" line (illegal instruction).

My code now is:
Code:
macro REM line,start,ed,val
  {
                db      line shr 8      ; line number of REM statement
                db      line and $FF   ; line number of REM statement
           if val equ
                dw      ed-start+2     ; lenght of line
                db      $EA             ; REM statement (token code)
           else
                db      ???
                db      $EA             ; REM statement (token code)
                db val
                db      NEWLINE
           end if
  }
    


And should be used like

REM 1,asmcode_st,asmcode_end

or

REM 20,0,0,'some_data'
Post 04 Mar 2012, 12:33
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 04 Mar 2012, 12:34
You have "if val equ". That is a different thing.
Post 04 Mar 2012, 12:34
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 04 Mar 2012, 12:42
Okay - I found the problem.
I am using this in my Z80 version of FASM and accidently I removed the
if
else
end

instructions. Sorry for asking. Confused


But one thing remains.
How can I get the length of val in this macro (which now works regarding the length, marked with 3 ???.

Code:
macro REM line,start,ed,val
  {
             db      line shr 8      ; line number of REM statement
              db      line and $FF   ; line number of REM statement
          if val eq
                dw      ed-start+2     ; lenght of line
             db      $EA             ; REM statement (token code)
           else
             db      ???            ; should be length of val (string)
           db      $EA             ; REM statement (token code)
                db     val
          db      NEWLINE
        end if
  }
    
Post 04 Mar 2012, 12:42
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20299
Location: In your JS exploiting you and your system
revolution 04 Mar 2012, 12:44
Code:
;...
local .x,.length
db .length
db $EA
.x db val
.length = $-.x
;...    
Post 04 Mar 2012, 12:44
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 517
Location: Munich
shutdownall 04 Mar 2012, 13:10
Thanks for help, works fine now. Very Happy
Post 04 Mar 2012, 13:10
View user's profile Send private message Send e-mail 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.