dia.s 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. .define .diagnos
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. space = 040
  7. del = 0177
  8. .sect .text
  9. .diagnos:
  10. move.l hol0,-(sp)
  11. move.l hol0+4,d2
  12. beq 1f
  13. move.l d2,a0
  14. move.l #40,d0
  15. 3:
  16. move.b (a0)+,d1
  17. beq 2f
  18. cmp.b #del,d1
  19. bge 1f
  20. cmp.b #space,d1
  21. blt 1f
  22. sub #1,d0
  23. bgt 3b
  24. clr.b (a0)
  25. 2:
  26. move.l d2,-(sp)
  27. pea fmt
  28. jsr printf
  29. add #12,sp
  30. jmp printf
  31. 1:
  32. move.l #unknwn,d2
  33. bra 2b
  34. .sect .bss
  35. getal:
  36. .space 12
  37. char:
  38. .space 1
  39. .align 4
  40. .sect .data
  41. hexs:
  42. .ascii "0123456789abcdef"
  43. .align 4
  44. .sect .text
  45. printf:
  46. movem.l d0/d1/d2/a0/a1/a2/a3/a4/a5/a6, -(sp)
  47. lea 44(sp), a6 ! a6 <- address of arguments
  48. move.l (a6)+, a5 ! a5 <- address of format
  49. next: move.b (a5)+, d0
  50. beq out
  51. cmp.b #'%', d0
  52. beq procnt
  53. put: move.l d0, -(sp)
  54. jsr putchar ! long argument on stack
  55. tst.l (sp)+
  56. bra next
  57. procnt: move.b (a5)+, d0
  58. cmp.b #'d', d0 ! NOTE: %d means unsigned.
  59. beq digit
  60. cmp.b #'x', d0
  61. beq hex
  62. cmp.b #'s', d0
  63. beq string
  64. cmp.b #'%', d0 ! second % has to be printed.
  65. beq put
  66. tst.b -(a5) ! normal char should be printed
  67. bra next
  68. string: move.l (a6)+, a2 ! a2 <- address of string
  69. sloop: move.b (a2)+, d0
  70. beq next
  71. move.l d0, -(sp)
  72. jsr putchar ! long argument on stack
  73. tst.l (sp)+
  74. bra sloop
  75. digit: move.l (a6)+, d1 ! d1 <- integer
  76. move.l #getal+12, a2 ! a2 <- ptr to last part of buf
  77. clr.b -(a2) ! stringterminator
  78. 1:
  79. move.l d1,-(sp)
  80. move.l #10,-(sp)
  81. jsr .dvu ! d1 <- qotient; d0 <- remainder
  82. add.l #'0', d0
  83. move.b d0, -(a2)
  84. tst.l d1 ! if quotient = 0 then ready
  85. bne 1b
  86. bra sloop ! print digitstring.
  87. hex: move.l (a6)+, d1 ! d1 <- integer
  88. move.l #getal+12, a2 ! a2 <- ptr to last part of buf
  89. clr.b -(a2) ! stringterminator
  90. move.l #7, d2 ! loop control
  91. 1: move.l d1, d0
  92. and.l #15, d0
  93. move.l #hexs,a0
  94. add.l d0,a0
  95. move.b (a0), -(a2) ! hex digit
  96. asr.l #4, d1
  97. dbf d2, 1b
  98. bra sloop
  99. out:
  100. movem.l (sp)+, d0/d1/d2/a0/a1/a2/a3/a4/a5/a6
  101. rts
  102. putchar:
  103. move.l #1, -(sp)
  104. pea 11(sp)
  105. move.l #1, -(sp)
  106. jsr WRITE
  107. lea 12(sp), sp
  108. rts
  109. .align 2
  110. .sect .data
  111. fmt: .asciz "%s, line %d: "
  112. unknwn: .asciz "unknown file"
  113. .align 2