.include "$lib/core.asm" .include "$lib/std.asm" ;.include "$lib/main.asm" .define_eval prev, OFFSET ts 0xffff tlr CORE_REG_PC .define_eval diff, (OFFSET - prev) .define_eval MAIN_JUMPER, (CORE_MEM_PRG_END - diff) .org prev .delete prev, diff .define_eval MAIN_JUMPER, (CORE_MEM_PRG_END - 3 - 1) .define_eval MEM_LOOP_DEPTH, CORE_MEM_MEM .define_eval MEM_LOOP_I, (MEM_LOOP_DEPTH + 1) .define_eval MEM_LOOP_J, (MEM_LOOP_I + 1) .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 .std_rset CORE_REG_A, MEM_CALL_STACK_PTR .std_set MEM_CALL_STACK_PTR .std_rset CORE_REG_A, MEM_ALLOC_PTR .std_set MEM_ALLOC_PTR .std_jump MAIN_JUMPER call_stack_jump: .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 return_call_stack_jump: .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 .macro call_stack_jump, call_stack_jump_arg_0_label, call_stack_jump_arg_1_offset .std_rset CORE_REG_C, call_stack_jump_arg_0_label .std_rset CORE_REG_D, (call_stack_jump_arg_1_offset + 7) ts call_stack_jump tlr CORE_REG_PC .endmacro .macro call_stack_jump_cond_if, call_stack_jump_cond_if_arg_0_if_label, call_stack_jump_cond_if_arg_1_offset .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, (call_stack_jump_cond_if_arg_1_offset + 7) ts call_stack_jump tlrc CORE_REG_PC .endmacro .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, call_stack_jump_cond_if_else_arg_2_offset .std_ld tlr CORE_REG_A .std_rset CORE_REG_C, call_stack_jump_cond_if_else_arg_0_if_label .define_eval call_stack_jump_cond_if_else_local_end_offset, (call_stack_jump_cond_if_else_arg_2_offset + 11) .debug call_stack_jump_cond_if_else_local_end_offset .std_rset CORE_REG_D, call_stack_jump_cond_if_else_local_end_offset 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, (call_stack_jump_cond_if_else_arg_2_offset + 11) ts call_stack_jump tlr CORE_REG_PC .debug call_stack_jump_cond_if_else_local_end_offset .delete call_stack_jump_cond_if_else_local_end_offset .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 .return_call_stack_jump conditions_else_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 .return_call_stack_jump ; words words_0: ; name : "test" push 40 push 2 .stack_transfer_alu .std_alu CORE_ALU_ADD tls .return_call_stack_jump ; main main: .org MAIN_JUMPER ts main tlr CORE_REG_PC .org main push 0 .call_stack_jump_cond_if_else conditions_if_0, conditions_else_0, OFFSET .call_stack_jump words_0, OFFSET dbg .call_stack_jump words_0, OFFSET dbg .std_stop