dup.s 477 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. .define .dup
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! Duplicate top bytes of stack
  8. ! Expects in de-registers: number of bytes to duplicate
  9. .dup: mov a,e !trap if number is odd
  10. rar
  11. cc eoddz
  12. pop h
  13. shld .retadr
  14. mov h,b
  15. mov l,c
  16. shld .bcreg
  17. mov h,d
  18. mov l,e
  19. dad sp
  20. 1: dcx h
  21. mov b,m
  22. dcx h
  23. mov c,m
  24. push b
  25. dcx d
  26. dcx d !number of bytes must be a word-multiple i.e. even
  27. mov a,d
  28. ora e
  29. jnz 1b
  30. lhld .bcreg
  31. mov b,h
  32. mov c,l
  33. lhld .retadr
  34. pchl