Skip to content

Instantly share code, notes, and snippets.

@Jarvix
Created April 7, 2012 13:30
Show Gist options
  • Save Jarvix/2328917 to your computer and use it in GitHub Desktop.
Save Jarvix/2328917 to your computer and use it in GitHub Desktop.
jxAssembler preprocessor and parser
.include "Test2.s"
; Comment lines
; another one
:lala
SET A, 0x30 ; should be
SET [ A+0x1000 ], 0x20; removed
SUB A, [ 0x1000]
IFN A, 0x10
SET PC, crash
SET I, 10
SET A, 0x2000
:loop SET [0x2000+I], [A]
SUB I, 1
IFN I, 0
SET PC, loop
:crash
SHL X, 4
SET PC, POP
SET PC, PUSH
;SET [0x10++], 0x10
===== Test2.s is now empty ======
========= REWRITTEN TO, BY PREPROCESSOR ========
:lala
SET A, 0x30
SET [ A + 0x1000 ], 0x20
SUB A, [ 0x1000 ]
IFN A, 0x10
SET PC, crash
SET I, 10
SET A, 0x2000
:loop
SET [ 0x2000 + I ], [ A ]
SUB I, 1
IFN I, 0
SET PC, loop
:crash
SHL X, 4
SET PC, [ SP ++ ]
SET PC, [ -- SP ]
========= PARSED INTERNALLY TO ==========
(
"__label_ref(lala)",
"__opcode(SET)",
"__reg_general(A)",
"__literal(48)",
"__opcode(SET)",
"__ptr_val({",
"__reg_general(A)",
"__operator_add",
"__literal(4096)",
"})",
"__literal(32)",
"__opcode(SUB)",
"__reg_general(A)",
"__ptr_val({",
"__literal(4096)",
"})",
"__opcode(IFN)",
"__reg_general(A)",
"__literal(16)",
"__opcode(SET)",
"__reg_program_counter",
"__label(crash)",
"__opcode(SET)",
"__reg_general(I)",
"__literal(10)",
"__opcode(SET)",
"__reg_general(A)",
"__literal(8192)",
"__label_ref(loop)",
"__opcode(SET)",
"__ptr_val({",
"__reg_general(I)",
"__operator_add",
"__literal(8192)",
"})",
"__ptr_val({",
"__reg_general(A)",
"})",
"__opcode(SUB)",
"__reg_general(I)",
"__literal(1)",
"__opcode(IFN)",
"__reg_general(I)",
"__literal(0)",
"__opcode(SET)",
"__reg_program_counter",
"__label(loop)",
"__label_ref(crash)",
"__opcode(SHL)",
"__reg_general(X)",
"__literal(4)",
"__opcode(SET)",
"__reg_program_counter",
"__ptr_val({",
"__reg_stack_pointer",
"__operator_inc",
"})",
"__opcode(SET)",
"__reg_program_counter",
"__ptr_val({",
"__operator_dec",
"__reg_stack_pointer",
"})"
)
=== which is an array with text items ;) ====
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment