hence/examples/testforth.asm

238 lines
5.2 KiB
NASM
Raw Normal View History

; Generated by Henceforth 0.1.0 (https://git.dergrimm.net/dergrimm/hence.git)
2023-03-23 16:59:10 +00:00
.include "$lib/core.asm"
.include "$lib/std.asm"
2023-03-24 20:13:40 +00:00
.define_eval prev, OFFSET
ts CORE_U16_MAX
tlr CORE_REG_PC
.define_eval diff, (OFFSET - prev)
.define_eval MAIN_JUMPER, (CORE_MEM_PRG_END - diff)
.org prev
.delete prev, diff
2023-04-02 12:32:11 +00:00
; .define_eval prev, OFFSET
;
; .bytes CORE_U16_MAX, CORE_U16_MAX
;
; .define_eval JUMP_TABLE_CONDITIONS_SIZE, (OFFSET - prev)
; .org prev
; .delete prev
; .define_eval JUMP_TABLE_WORDS_SIZE, (0 * 2)
; .define_eval MEM_JUMP_TABLE_LEN, (JUMP_TABLE_CONDITIONS_SIZE + JUMP_TABLE_WORDS_SIZE / 2)
; .define_eval MEM_JUMP_TABLE_PTR, CORE_MEM_MEM
; .define_eval MEM_JUMP_TABLE_END, (MEM_JUMP_TABLE_PTR + MEM_JUMP_TABLE_LEN)
; .debug MEM_JUMP_TABLE_LEN, MEM_JUMP_TABLE_PTR, MEM_JUMP_TABLE_END
; ; jump table
; ; conditions
;
; jump_table_conditions_if_0: .bytes 444
;
; jump_table_conditions_else_0: .bytes 5498
;
;
.define_eval MEM_JUMP_TABLE_LEN, 9
.define_eval MEM_JUMP_TABLE_PTR, CORE_MEM_MEM
.define_eval MEM_JUMP_TABLE_END, (MEM_JUMP_TABLE_PTR + MEM_JUMP_TABLE_LEN)
.define_eval MEM_LOOP_DEPTH, (MEM_JUMP_TABLE_END + 1)
.define_eval MEM_LOOP_I, (MEM_LOOP_DEPTH + 1)
.define_eval MEM_LOOP_J, (MEM_LOOP_I + 1)
2023-03-24 20:13:40 +00:00
.define_eval MEM_CALL_STACK_LEN, 16
.define_eval MEM_CALL_STACK_PTR, (MEM_LOOP_J + 1)
.define_eval MEM_CALL_STACK_END, (MEM_CALL_STACK_PTR + MEM_CALL_STACK_LEN)
.define_eval MEM_ALLOC_PTR, (MEM_CALL_STACK_END + 1)
.macro stack_transfer_alu
.std_ld
tlr CORE_REG_B
.std_ld
tlr CORE_REG_A
.endmacro
2023-03-24 20:13:40 +00:00
2023-04-02 12:32:11 +00:00
; setup jump table
; reference MEM_CALL_STACK_PTR to itself
2023-03-23 16:59:10 +00:00
.std_rset CORE_REG_A, MEM_CALL_STACK_PTR
.std_set MEM_CALL_STACK_PTR
2023-03-24 20:13:40 +00:00
2023-04-02 12:32:11 +00:00
; reference MEM_ALLOC_PTR to itself
.std_rset CORE_REG_A, MEM_ALLOC_PTR
2023-03-23 16:59:10 +00:00
.std_set MEM_ALLOC_PTR
2023-03-24 20:13:40 +00:00
.std_jump MAIN_JUMPER
2023-03-24 20:13:40 +00:00
2023-03-23 16:59:10 +00:00
call_stack_jump:
2023-03-24 20:13:40 +00:00
.std_get MEM_CALL_STACK_PTR
tlr CORE_REG_A
.std_rset CORE_REG_B, 1
.std_alu CORE_ALU_ADD
tlr CORE_REG_A
tlr CORE_REG_B
.std_set MEM_CALL_STACK_PTR
tsr CORE_REG_D
tlr CORE_REG_A
tsr CORE_REG_B
set
tsr CORE_REG_C
tlr CORE_REG_PC
2023-03-23 16:59:10 +00:00
return_call_stack_jump:
2023-03-24 20:13:40 +00:00
.std_get MEM_CALL_STACK_PTR
tlr CORE_REG_A
tlr CORE_REG_C
.std_rset CORE_REG_B, 1
.std_alu CORE_ALU_SUB
tlr CORE_REG_A
.std_set MEM_CALL_STACK_PTR
tsr CORE_REG_C
get
tlr CORE_REG_PC
.define_eval prev, OFFSET
.std_rset CORE_REG_C, CORE_U16_MAX
.std_rset CORE_REG_D, CORE_U16_MAX
ts call_stack_jump
tlr CORE_REG_PC
.define_eval CALL_STACK_JUMP_SIZE, (OFFSET - prev)
.org prev
.delete prev
.macro call_stack_jump, call_stack_jump_arg_0_label
.define_eval prev, OFFSET
.define offset_till_end, (OFFSET - prev * -1 + CALL_STACK_JUMP_COND_IF_ELSE_SIZE)
.std_rset CORE_REG_C, call_stack_jump_arg_0_label
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
ts call_stack_jump
tlr CORE_REG_PC
.delete prev, offset_till_end
.endmacro
.define_eval prev, OFFSET
.std_ld
tlr CORE_REG_A
.std_rset CORE_REG_C, CORE_U16_MAX
.std_rset CORE_REG_D, CORE_U16_MAX
ts call_stack_jump
tlrc CORE_REG_PC
.define_eval CALL_STACK_JUMP_COND_IF_SIZE, (OFFSET - prev)
.org prev
.delete prev
.macro call_stack_jump_cond_if, call_stack_jump_cond_if_arg_0_if_label
.define_eval prev, OFFSET
.define offset_till_end, (OFFSET - prev * -1 + CALL_STACK_JUMP_COND_IF_ELSE_SIZE)
2023-03-24 20:13:40 +00:00
.std_ld
tlr CORE_REG_A
.std_rset CORE_REG_C, call_stack_jump_cond_if_arg_0_if_label
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
ts call_stack_jump
tlrc CORE_REG_PC
.delete prev, offset_till_end
2023-03-24 20:13:40 +00:00
.endmacro
.define_eval prev, OFFSET
.std_ld
tlr CORE_REG_A
.std_rset CORE_REG_C, CORE_U16_MAX
.std_rset CORE_REG_D, CORE_U16_MAX
ts call_stack_jump
tlrc CORE_REG_PC
.std_rset CORE_REG_C, CORE_U16_MAX
.std_rset CORE_REG_D, CORE_U16_MAX
ts call_stack_jump
tlr CORE_REG_PC
.define_eval CALL_STACK_JUMP_COND_IF_ELSE_SIZE, (OFFSET - prev)
.org prev
.delete prev
.macro call_stack_jump_cond_if_else, call_stack_jump_cond_if_else_arg_0_if_label, call_stack_jump_cond_if_else_arg_1_else_label
.define_eval prev, OFFSET
.define offset_till_end, (OFFSET - prev * -1 + CALL_STACK_JUMP_COND_IF_ELSE_SIZE)
.std_ld
tlr CORE_REG_A
.std_rset CORE_REG_C, call_stack_jump_cond_if_else_arg_0_if_label
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
ts call_stack_jump
tlrc CORE_REG_PC
.std_rset CORE_REG_C, call_stack_jump_cond_if_else_arg_1_else_label
.std_rset CORE_REG_D, (OFFSET + offset_till_end)
2023-03-24 20:13:40 +00:00
ts call_stack_jump
tlr CORE_REG_PC
.delete prev, offset_till_end
2023-03-24 20:13:40 +00:00
.endmacro
.macro return_call_stack_jump
.std_jump return_call_stack_jump
.endmacro
; data
; strings
; conditions
; condition: 0
conditions_if_0:
push 42
.std_ld
tlr CORE_REG_A
.std_set CORE_MEM_OUT
.std_rset CORE_REG_A, '\n'
.std_set CORE_MEM_CHR
dbg
.return_call_stack_jump
conditions_else_0:
push 69
.std_ld
tlr CORE_REG_A
.std_set CORE_MEM_OUT
.std_rset CORE_REG_A, '\n'
.std_set CORE_MEM_CHR
.return_call_stack_jump
2023-03-24 20:13:40 +00:00
; words
; main
main:
.org MAIN_JUMPER
ts main
tlr CORE_REG_PC
2023-03-24 20:13:40 +00:00
.org main
push 0
.call_stack_jump_cond_if_else conditions_if_0, conditions_else_0
2023-04-02 12:32:11 +00:00
push 40
push 2
.stack_transfer_alu
.std_alu CORE_ALU_ADD
tls
dbg
push 32
push 4875
push 8748
dbg
push 8777
dbg
2023-03-31 12:36:00 +00:00
dbg
dbg
2023-03-23 16:59:10 +00:00
.std_stop