home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / PSGN.AZM / PSGN.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  1.9 KB  |  70 lines

  1. ;----------------------------------------------------------------
  2. ;        This is a module in the ASMLIB library.
  3. ;
  4. ; This module is responsible for printing SIGNED 2's complement
  5. ; numbers. It does this by determining if the number is negative
  6. ; and if so prints a leading '-' character else it prints it
  7. ; as normally. This module links directly to the PDE module
  8. ; from which it uses the print routines, of course. Sample
  9. ; output is as below.
  10. ;
  11. ; Number (hex)     No LZB        LZB      BLZB      CLZB (*)
  12. ; Positives
  13. ;  0010          0010     10          10       **10
  14. ;  0100          0100       100        100       *100
  15. ;  1000           1000     1000      1000       1000
  16. ; Negatives
  17. ;  800F         -0010    -10       -  10      -**10
  18. ;  80FF             -0100    -100      - 100      -*100
  19. ;  8FFF         -1000    -1000     -1000      -1000
  20. ;
  21. ; As can be seen from the above, it is a little horrible
  22. ; with leading zero blanking, but tough luck. Functions
  23. ; enabled are.
  24. ;
  25. ;  pshde    Print signed hex de.
  26. ;  psdde    Print signed decimal de.
  27. ;
  28. ;            Written        R.C.H.        19/9/83
  29. ;            Last Update    R.C.H.          22/10/83
  30. ;----------------------------------------------------------------
  31. ;
  32.     name    'psgn'
  33.     public    pshde,psdde
  34.     extrn    comp2s,dispatch,pdde,phde
  35.     maclib    z80
  36. ;
  37. pshde:
  38.     call    psign            ; Print a '-' iff negative
  39.     jmp    phde
  40. ;
  41. psdde:
  42.     call    psign
  43.     jmp    pdde
  44. ;
  45. ; This routine will return if the number is positive else
  46. ; it will print a '-' sign then convert the number to positive 
  47. ; then return.
  48. ;
  49. psign:
  50.     push    psw
  51.     mov    a,d            ; Get sign carrying byte
  52.     ani    080h
  53.     ora    a
  54.     jrz    pexit             ; Return if 00 (i.e. positive)
  55. ; Here we print the '-' sign
  56.     mvi    a,'-'
  57.     call    dispatch
  58.     push    h
  59.     call    comp2s            ; Perform the 2's complement and return
  60.     xchg                ; Put result into DE
  61.     pop    h            ; Restore HL from the ordeal
  62. pexit:
  63.     pop    psw
  64.     ret
  65. ;
  66.     end
  67.  
  68.  
  69.  
  70.