all repos — xyw @ f9db54986add6293b8bea565ec774c09a442e75b

A minimal virtual machine and assembler for terminals.

examples/on-error.xyw

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
.include "devices.xyw" 

; register on error handler
on_error system.on_error STW

; main program
$10 $0 DIV
end JMPw

; on error handler
.label on_error
    system.error LDB $1 EQU on_error.div-by-zero.print JCNw
    unknown-error print JSRw
    $0 system.error STB
    RTS
    .label on_error.div-by-zero.print
        div-by-zero-error print JSRw
        $3 system.error STB
        RTS

; printing subroutine
; a16 --
.label print
  POPxw
  .label print.loop
    LDBxw terminal.output STB
    INCxw LDBxw print.loop JCNw
    CLRxw
    RTS

.label div-by-zero-error
.string "Error: Division by zero.\n"
.label unknown-error
.string "Error: Unknown error.\n"
.label end