hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
720 stars 56 forks source link

Add output format for the game "Turing Complete" #183

Closed thenorili closed 10 months ago

thenorili commented 1 year ago

Players of the game "Turing Complete" often use customasm to design a richer assembly language than the game provides and then copy the resulting binary into the game.

This change introduces an annotated format compatible with the Turing Complete assembly editor, using '#' for comments and '0x' or '0b' to prefix data groups.

If you'd prefer that I factor this into a config option for format_annotated or factor out shared code between format_annotated and format_tcgame please ask, I'm open to that option.

An excerpted example of the output:

# outp | addr | data (base 2)

#   0:0 |    0
# init:

#   0:0 |    0
# mov sp, #0xFF
0b11000000 0b11111111 0b00000000 0b00001011
#   4:0 |    4
# mov fp, sp
0b01000000 0b00001011 0b00000000 0b00001001
#   8:0 |    8
# sub sp, sp, #16
0b01000001 0b00001011 0b00010000 0b00001011
#   c:0 |    c
# mov lr, #exit
0b11000000 0b00010100 0b00000000 0b00001110
#  10:0 |   10
# jmp #main
0b11100000 0b00000000 0b00000000 0b00011100
#  14:0 |   14
# exit:

#  14:0 |   14
# mov sp, fp
0b01000000 0b00001001 0b00000000 0b00001011
#  18:0 |   18
# mov out, #0
0b11000000 0b00000000 0b00000000 0b00001111
#  1c:0 |   1c
# main:

#  1c:0 |   1c
# push lr
0b10000001 0b00000001 0b00001011 0b00001011 0b01000000 0b00001011 0b00000000 0b00001100 0b01000000 0b00001110 0b00000000 0b00001101
#  28:0 |   28
# push fp
0b10000001 0b00000001 0b00001011 0b00001011 0b01000000 0b00001011 0b00000000 0b00001100 0b01000000 0b00001001 0b00000000 0b00001101
thenorili commented 1 year ago

The latest update corrects a typo s/tmgame/tcgame and incidentally removes some trailing whitespace from the files I worked on. I hope that the whitespace changes don't trouble the review process at all!

hlorenzi commented 1 year ago

I think this looks great! I think it's better that the code is completely isolated, since I'm imagining this is a more of a niche use-case. But looking at the generated code, it seems to be pretty generic. Perhaps we could name the format something else? Just to avoid references to a commercial product.

If we keep the product name, I think we'll also need to move its code declarations and help entries to the end of their respective lists, to reflect their niche status.