rck.s 831 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. .define .rck
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! Range check
  8. ! Expects on stack: address of range check descriptor
  9. ! index
  10. ! Yields index on stack unchanged
  11. ! Causes a trap if index is out of bounds
  12. .rck: pop h
  13. shld .retadr
  14. mov h,b
  15. mov l,c
  16. shld .bcreg
  17. pop h ! hl = return address
  18. pop d ! de = index
  19. mov c,m ! bc = lower bound
  20. inx h
  21. mov b,m
  22. inx h
  23. mov a,d
  24. xra b
  25. jm 1f ! jump if index and l.b. have different signs
  26. mov a,e
  27. sub c
  28. mov a,d
  29. sbb b
  30. jmp 2f
  31. 1: xra b ! now a = d again
  32. 2: cm erange ! trap if index too small
  33. mov c,m
  34. inx h
  35. mov b,m
  36. mov a,d
  37. xra b
  38. jm 1f ! jump if index and u.b. have different signs
  39. mov a,c
  40. sub e
  41. mov a,b
  42. sbb d
  43. jmp 2f
  44. 1: xra d ! now a = b
  45. 2: cm erange ! trap if index is too large
  46. lhld .bcreg
  47. mov b,h
  48. mov c,l
  49. lhld .retadr
  50. pchl