exg.s 649 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. .define .exg
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! Exchange top bytes of stack
  8. ! Expects in de-registers the number of bytes to be exchanged.
  9. .exg: mov a,e
  10. rar
  11. cc eoddz !trap if numer of bytes is odd
  12. pop h
  13. shld .retadr
  14. mov h,b
  15. mov l,c
  16. shld .bcreg
  17. lxi h,0
  18. dad sp
  19. mov b,h
  20. mov c,l !now bc points to first operand
  21. dad d !and hl to the second
  22. push d !place number of bytes on top of stack
  23. 1: mov d,m
  24. ldax b
  25. mov m,a
  26. mov a,d
  27. stax b
  28. xthl !caused by a lack of registers
  29. dcx h !decrement top of stack
  30. mov a,h
  31. ora l
  32. xthl
  33. inx h
  34. inx b
  35. jnz 1b
  36. pop d
  37. lhld .bcreg
  38. mov b,h
  39. mov c,l
  40. lhld .retadr
  41. pchl