lar2.s 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. .define .lar2
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! Load array element, descriptor contains 2-bytes integers
  8. ! Expects on stack: pointer to array descriptor
  9. ! index
  10. ! base address
  11. ! Yields on stack: array element
  12. ! Adapted from .aar2 and .loi
  13. .lar2:
  14. pop h
  15. shld .retadr1
  16. mov h,b
  17. mov l,c
  18. shld .bcreg
  19. pop h ! hl = pointer to descriptor
  20. pop d ! de = index
  21. mov a,e ! bc = index - lower bound
  22. sub m
  23. inx h
  24. mov c,a
  25. mov a,d
  26. sbb m
  27. inx h
  28. mov b,a
  29. push b ! first operand to multiply
  30. inx h
  31. inx h
  32. mov c,m ! bc = size
  33. inx h
  34. mov b,m
  35. push b ! second operand to multiply
  36. call .mli2 ! de = size * (index - lower bound)
  37. pop h ! hl = base address
  38. dad d ! hl = address of array[index]
  39. dad b ! hl= load pointer
  40. xra a ! clear carry bit
  41. mov a,b ! divide bc by 2
  42. rar
  43. mov b,a
  44. mov a,c
  45. rar
  46. mov c,a
  47. jnc 1f
  48. ! for 1 byte array element only:
  49. mov a,c ! trap if bc odd and <>1
  50. ora b
  51. cnz eoddz
  52. dcx h
  53. mov e,m
  54. mvi d,0
  55. push d
  56. jmp 2f
  57. 1: dcx h
  58. mov d,m
  59. dcx h
  60. mov e,m
  61. push d
  62. dcx b
  63. mov a,b
  64. ora c
  65. jnz 1b
  66. 2: lhld .bcreg
  67. mov b,h
  68. mov c,l
  69. lhld .retadr1
  70. pchl