home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / BCDASM.ZIP / BCDASM / SRC / BCDBE2LE.ASM < prev    next >
Encoding:
Assembly Source File  |  1997-06-03  |  2.1 KB  |  79 lines

  1.     title    BCDASM -- Copyright 1997, Morten Elling
  2.     subttl    Convert packed signed BCDs to/from little-/big-endian
  3.  
  4.     include    model.inc
  5.     include    modelt.inc
  6.     include    bcd.ash
  7.  
  8.     @CODESEG
  9.  
  10. ;//////////////////////////////////////////////////////////////////////
  11. ;//    Name    bcdBe2le
  12. ;//    Desc    Convert packed signed BCD from big-endian format
  13. ;//        to little-endian format.
  14. ;//
  15. ;//
  16. ;//    Entry    Passed args
  17. ;//    Exit    Packed signed little-endian BCD returned to destination
  18. ;//        Acc undefined.
  19. ;//
  20. ;//    Note    Destination and source *cannot* overlap.
  21. ;//
  22. ;//        Little-endian format stores the least-significant byte
  23. ;//        lowest in memory (the usual on Intel PCs).
  24.  
  25. bcdBe2le proc
  26. arg    dstBCD    :dataptr, \    ; Addr of destination BCD storage
  27.     srcBCD    :dataptr, \    ; Addr of source big-endian BCD
  28.     srcsz    :@uint        ; Byte size of each BCD
  29. @uses    ds,es,rsi,rdi,rcx,rax
  30. ;.
  31.     @LDS  rsi, [srcBCD]
  32.     @LES  rdi, [dstBCD]
  33.     mov   rcx, [srcsz]    ; No. of bytes to do
  34.     add   rdi, rcx        ; Point dst index
  35.     dec   rdi        ;   to dst's sign byte
  36.     @alignn
  37. @@nxtb: cld            ; Auto-increment src index
  38.     lodsb            ; Get a byte
  39.     std            ; Auto-decrement dst index
  40.     stosb            ; Store the byte
  41.     loop  @@nxtb        ; Repeat until done
  42.     cld            ; Reset df
  43.     RET
  44. bcdBe2le endp
  45.  
  46.  
  47. ;//////////////////////////////////////////////////////////////////////
  48. ;//    Name    bcdLe2be
  49. ;//    Desc    Convert packed signed BCD from little-endian format
  50. ;//        to big-endian format.
  51. ;//
  52. ;//
  53. ;//    Entry    Passed args
  54. ;//    Exit    Packed signed big-endian BCD returned to destination.
  55. ;//        Acc undefined.
  56. ;//
  57. ;//    Note    Destination and source *cannot* overlap.
  58.  
  59. bcdLe2be proc
  60. arg    dstBCD    :dataptr, \    ; Addr of destination BCD storage
  61.     srcBCD    :dataptr, \    ; Addr of source little-endian BCD
  62.     srcsz    :@uint        ; Byte size of each BCD
  63. @uses    ds,es,rsi,rdi,rcx,rax
  64. ;.
  65.     @LDS  rsi, [srcBCD]
  66.     @LES  rdi, [dstBCD]
  67.     mov   rcx, [srcsz]    ; No. of bytes to do
  68.     add   rsi, rcx        ; Point source index
  69.     dec   rsi        ;   to src's sign byte
  70.     @alignn
  71. @@nxtl: std            ; Auto-decrement src index
  72.     lodsb            ; Get a byte
  73.     cld            ; Auto-increment dst index
  74.     stosb            ; Store the byte
  75.     loop  @@nxtl        ; Repeat until done
  76.     RET
  77. bcdLe2be endp
  78.  
  79.     END