.sect .text ; .sect .rom; .sect .data; .sect .bss
.define .trpdivz
.define .trpilin
.define .trpcase
.define .trprang
.define .trpset
.define .trpnofp
.define .trpheap
.define .trp
.define .stop

.sect .text
.extern .trpdivz
.extern .trpilin
.extern .trpcase
.extern .trprang
.extern .trpset
.extern .trpnofp
.extern .trpheap
.extern .trp

.trpdivz:
mov ax,6
mov dx,.Mdivz
jmp .Trp
.trpilin:
mov ax,18
mov dx,.Milin
jmp .Trp
.trpcase:
mov ax,20
mov dx,.Mcase
jmp .Trp
.trprang:
mov ax,1
mov dx,.Mrang
jmp .Trp
.trpset:
mov ax,2
mov dx,.Mset
jmp .Trp
.trpnofp:
mov ax,18
mov dx,.Mnofp
jmp .Trp
.trpheap:
mov ax,17
mov dx,.Mheap
jmp .Trp

.Trp:
xor     bx,bx
.extern .trppc
xchg    bx,(.trppc)
test    bx,bx
jz      2f
push    ax
call    (bx)
pop     ax
ret
2:
mov bx,22
push bx
push dx
mov ax,2
push ax
call _write
.stop:
call _exit

.trp:
mov dx,ax
cmp dx,21
jae 1f
sal dx,1
mov bx,.Mtable
add bx,dx
mov bx,(bx)
test bx,bx
jz 1f
mov dx,bx
jmp 2f
1:
mov bx,.Mtrp+14
mov cx,6
mov dx,ax
1:
and dx,7
add dx,'0'
movb (bx),dl
dec bx
sar dx,1
sar dx,1
sar dx,1
loop 1b
mov dx,.Mtrp
2:
jmp .Trp

.sect .rom
.Mtable:
	.data2 0,	.Mrang,	.Mset,	0,	0,	0,	.Mdivz,	0
	.data2 0,	0,	0,	0,	0,	0,	0,	0
	.data2 0,	.Mheap,	.Milin,	.Milin,	.Mcase

.Mdivz: .asciz "Error: Division by 0 \n"
.Milin: .asciz "Illegal EM instruct'n\n"
.Mcase: .asciz "Err in EM case instr \n"
.Mrang: .asciz "Variable out of range\n"
.Mset:  .asciz "Err in EM set instr  \n"
.Mnofp: .asciz "Floating pt not impl.\n"
.Mheap: .asciz "Heap overflow        \n"

.Mtrp:	.asciz "EM trap 0000000 octal\n"
