trp.s 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. .sect .text ; .sect .rom; .sect .data; .sect .bss
  2. .define .trpdivz
  3. .define .trpilin
  4. .define .trpcase
  5. .define .trprang
  6. .define .trpset
  7. .define .trpnofp
  8. .define .trpheap
  9. .define .trp
  10. .define .stop
  11. .sect .text
  12. .extern .trpdivz
  13. .extern .trpilin
  14. .extern .trpcase
  15. .extern .trprang
  16. .extern .trpset
  17. .extern .trpnofp
  18. .extern .trpheap
  19. .extern .trp
  20. .trpdivz:
  21. mov ax,6
  22. mov dx,.Mdivz
  23. jmp .Trp
  24. .trpilin:
  25. mov ax,18
  26. mov dx,.Milin
  27. jmp .Trp
  28. .trpcase:
  29. mov ax,20
  30. mov dx,.Mcase
  31. jmp .Trp
  32. .trprang:
  33. mov ax,1
  34. mov dx,.Mrang
  35. jmp .Trp
  36. .trpset:
  37. mov ax,2
  38. mov dx,.Mset
  39. jmp .Trp
  40. .trpnofp:
  41. mov ax,18
  42. mov dx,.Mnofp
  43. jmp .Trp
  44. .trpheap:
  45. mov ax,17
  46. mov dx,.Mheap
  47. jmp .Trp
  48. .Trp:
  49. xor bx,bx
  50. .extern .trppc
  51. xchg bx,(.trppc)
  52. test bx,bx
  53. jz 2f
  54. push ax
  55. call (bx)
  56. pop ax
  57. ret
  58. 2:
  59. mov bx,22
  60. push bx
  61. push dx
  62. mov ax,2
  63. push ax
  64. call _write
  65. .stop:
  66. call _exit
  67. .trp:
  68. mov dx,ax
  69. cmp dx,21
  70. jae 1f
  71. sal dx,1
  72. mov bx,.Mtable
  73. add bx,dx
  74. mov bx,(bx)
  75. test bx,bx
  76. jz 1f
  77. mov dx,bx
  78. jmp 2f
  79. 1:
  80. mov bx,.Mtrp+14
  81. mov cx,6
  82. mov dx,ax
  83. 1:
  84. and dx,7
  85. add dx,'0'
  86. movb (bx),dl
  87. dec bx
  88. sar dx,1
  89. sar dx,1
  90. sar dx,1
  91. loop 1b
  92. mov dx,.Mtrp
  93. 2:
  94. jmp .Trp
  95. .sect .rom
  96. .Mtable:
  97. .data2 0, .Mrang, .Mset, 0, 0, 0, .Mdivz, 0
  98. .data2 0, 0, 0, 0, 0, 0, 0, 0
  99. .data2 0, .Mheap, .Milin, .Milin, .Mcase
  100. .Mdivz: .asciz "Error: Division by 0 \n"
  101. .Milin: .asciz "Illegal EM instruct'n\n"
  102. .Mcase: .asciz "Err in EM case instr \n"
  103. .Mrang: .asciz "Variable out of range\n"
  104. .Mset: .asciz "Err in EM set instr \n"
  105. .Mnofp: .asciz "Floating pt not impl.\n"
  106. .Mheap: .asciz "Heap overflow \n"
  107. .Mtrp: .asciz "EM trap 0000000 octal\n"