sar2.s 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. .define .sar2
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! Store array element, descriptor contains 2-bytes integers
  8. ! Expects on stack: pointer to array descriptor
  9. ! index
  10. ! base address
  11. ! array element
  12. ! Adapted from .aar2 and .sti
  13. .sar2:
  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. xra a
  40. mov a,b
  41. rar
  42. mov b,a
  43. mov a,c
  44. rar
  45. mov c,a ! bc = word count
  46. jnc 1f
  47. ! if 1 byte array element only:
  48. mov a,c ! trap if bc odd and <>1
  49. ora b
  50. cnz eoddz
  51. pop d
  52. mov m,e
  53. jmp 2f
  54. 1: pop d
  55. mov m,e
  56. inx h
  57. mov m,d
  58. inx h
  59. dcx b
  60. mov a,b
  61. ora c
  62. jnz 1b
  63. 2: lhld .bcreg
  64. mov b,h
  65. mov c,l
  66. lhld .retadr1
  67. pchl