flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > fasm68k - a Motorola 68000 instruction set for fasmg

Author
Thread Post new topic Reply to topic
dosmancer



Joined: 20 Feb 2025
Posts: 24
Location: Kingdom of Sweden
dosmancer 05 May 2025, 02:19
I made a 68k instruction set for fasmg: https://github.com/fredrik-hjarner/fasm68k

Sega Mega Drive/Genesis, Neo Geo and Amiga has 68000 processors.

Just got all the tests I had to succeed and produce the correct binary without errors. I need more tests though and to go through the m68k reference manual again to double check I have not missed anything before I can be confident it works.

This overview of the encoding of instructions was very helpful: http://goldencrystal.free.fr/M68kOpcodes-v2.3.pdf
Post 05 May 2025, 02:19
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8406
Location: Kraków, Poland
Tomasz Grysztar 05 May 2025, 10:58
Thank you for sharing! I'm adding it to the list.
Post 05 May 2025, 10:58
View user's profile Send private message Visit poster's website Reply with quote
dosmancer



Joined: 20 Feb 2025
Posts: 24
Location: Kingdom of Sweden
dosmancer 05 May 2025, 19:45
Tomasz Grysztar wrote:
Thank you for sharing! I'm adding it to the list.

Awesome.

The 68000 was both easier and harder to implement than I thought. Most of the stuff was very straight-forward because the relatively simple and relatively small and relatively consistent uniform instructions.

Had a few problems, first some addressing modes in 68000 assembly contains the , (comma) character for example:
Code:
ori.b #0, $0F(a5,d2.l)    


fasmg would interpret that as 3 arguments, so I had to use something like this (could probably be refactored):
Code:
define m68k.split_operands_result
namespace m68k.split_operands_result
    define num_operands
    define op1
    define op2
end namespace

calminstruction m68k.split_operands? line&
        local op1, op2
        match op1 =, op2, line, ()
        jyes two_operands
    ; one_operand:
        call m68k.parse_operand@op1, line
        compute m68k.split_operands_result.num_operands, 1
        arrange m68k.split_operands_result.op1, line
        exit
    two_operands:
        compute m68k.split_operands_result.num_operands, 2
        arrange m68k.split_operands_result.op1, op1
        arrange m68k.split_operands_result.op2, op2
end calminstruction

calminstruction chk.w? operands&
    call m68k.split_operands, operands
    call m68k.parse_operand@op1, m68k.split_operands_result.op1
    call m68k.parse_operand@op2, m68k.split_operands_result.op2
    emit 1, 01000001b + @op2.ea_reg_bits shl 1
    emit 1, 10000000b + @op1.ea_mode_bits shl 3 + @op1.ea_reg_bits
    call emit_ext_words, @op1.ext_bytes, @op1.ext_bytes_bits
end calminstruction
    

Since famg outputs in little-endian I needed this:
Code:
macro calminstruction?.emit? num_bytes*, value*
    emit (num_bytes), (value) bswap (num_bytes)
end macro
    


I suppose I also will need to override other commands such as `store` and `load` which I have not done yet.

I want it to be as compatible with other 68k assemblers as possible but I don't want to spend unreasonable amount of time on that. For example in 68k assemblers they seems to use * (asterisk) as the value of current address (like $ in fasmg), so I think you can have something like this in other 68k assemblers:

Code:
***    


which would mean current address times current address. That's probably too complex to support I think.

Another case would be things being comments automatically in the "last column" without any preceeding semicolon. I don't know maybe that's possible to support we'll see.

Colon-less labels seems to be a thing too but the solution for that is in the fasmg manual if I recall correctly.
Post 05 May 2025, 19:45
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.