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

  1.     title    BCDASM -- Copyright 1997, Morten Elling
  2.     subttl    Validate format of a packed signed BCD
  3.  
  4.     include model.inc
  5.     include modelt.inc
  6.     include bcd.ash
  7.  
  8.     @CODESEG
  9.  
  10. ;//////////////////////////////////////////////////////////////////////
  11. ;//    Name    bcdIsbcd
  12. ;//    Desc    Validate the format of a packed signed BCD number,
  13. ;//        i.e. does it contain non-BCD digits.
  14. ;//
  15. ;//
  16. ;//    Entry    Passed args
  17. ;//    Exit    Acc = 0: Error, contains non-BCD digit(s)
  18. ;//        Acc > 0: No error
  19. ;//
  20. ;//    Note    A packed BCD number stored by the FPU (using the
  21. ;//        FBSTP instruction) may contain 0FFh in the sign byte,
  22. ;//        indicating that the number is a 'BCD indefinite'.
  23. ;//        This function does not flag this as an error (assuming
  24. ;//        it is handled by an FPU exception handler routine),
  25. ;//        and accepts any value in the sign byte.
  26.  
  27. bcdIsbcd proc
  28. arg    srcBCD    :dataptr, \    ; Addr of BCD
  29.     srcsz    :@uint        ; Byte size of BCD
  30. @uses    ds,rbx,rcx,rdx
  31. ;.
  32.     mov   rcx, [srcsz]
  33.     dec   rcx        ; Ignore the sign byte
  34.     mov   rdx, 0A00Ah    ; Handy constant
  35.     @LDS  rbx, [srcBCD]
  36.     @alignn
  37. @@vnxt:    mov   al, [rbx]
  38.         inc   rbx
  39.     cmp   al, dh
  40.     jnc sh @@ret
  41.     and   al, 00Fh
  42.     cmp   al, dl
  43.     jnc sh @@ret
  44.     dec   rcx
  45.     jnz   @@vnxt
  46. @@ret:    ; Carry set if valid
  47.     sbb   rax, rax
  48.     neg   rax        ; Return acc 0 or 1
  49.     RET
  50. bcdIsbcd endp
  51.  
  52.     END