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 > Programming Language Design > Z80 compilation with fasmg

Author
Thread Post new topic Reply to topic
marste



Joined: 05 May 2015
Posts: 32
Z80 compilation with fasmg
Last weekend I started the fasmg Z80 coding as I was saying some time ago.
I thought about it and my approach for simplicity and effectiveness would be to encode each different instruction in a different macro, and if it is not possible (as I assume) in a different "match" instruction (as below)...

Following a "not working" example of 4 instructions: I tried to read documentation but no success. Posting here with hope that is possible to easily correct and so I might understand it better and continue to implement the full instruction set.


Code:

; example macro (see examples below for instructions encodings)
macro LD first , second , notusedthirdpartoleave
    match first,HL?
        if second relativeto 0
            db $21
            dw second
        end if
    else match first,=( HL? =)
        if second relativeto 0
            db $36
            db second
        end if
    else match first,=( HL? =)
        match second,A?
            db $77
        end match
    else if first relativeto IX? ; ... missing check of enlcosing ( )
        if second relativeto 0
            db $DD,$36
            db first-IX?,second
        end if
    end if
end macro

; example instructions to compile
LD HL$1200 + $34  ; $21,$34,$12
LD (HL) , $11 + 1   ; $36,$12
LD ( HL ) , A       ; $77
LD (IX+5-2),1       ; $DD,$36,3,1

Post 08 Mar 2016, 17:17
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6179
Location: Kraków, Poland
The main problem is that you got the order of arguments to MATCH wrong: it should be the matched pattern first, and then the text to match. Also you need to precede "HL" token with "=", otherwise it is treated as parameter name (at the same time you do not need to put "=" before the parentheses, though it does not hurt there):

Code:
macro LD? first , second
    match =HL?,first
        db $21
        dw second
    else match ( =HL? ) =, =A?first,second
        db $77
    else match ( =HL? ), first
        db $36
        db second
    else match ( expr ),first
        if expr relativeto IX?
            db $DD,$36
            db first-IX?,second
        end if
    end match
end macro

element IX?

; example instructions to compile
LD HL$1200 + $34  ; $21,$34,$12
LD (HL) , $11 + 1   ; $36,$12
LD ( HL ) , A       ; $77
LD (IX+5-2),1       ; $DD,$36,3,1

Also note that this macro silently ignores any unrecognized syntax, you'd need to add the "else" clauses with some error signaling to make sure that it does not allow any syntax errors to pass undetected.
Post 08 Mar 2016, 18:44
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.