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

  1. ;----------------------------------------------------------------
  2. ;        This is a module in the ASMLIB library
  3. ; This module has been written for range checking the accumulator 
  4. ; either a value in DE or against a table. This is useful for checking
  5. ; values against legal limits. 
  6. ;
  7. ; CHKRNG    Will check if D <= A >= E. If this fails then
  8. ;        the routine returns a NON-ZERO flag. Else 
  9. ;        it returns a zero flag.
  10. ;
  11. ; CHKTBL    Does the same check but uses DE as a pointer to
  12. ;        a table of ranges and addresses. Byte 1 in the table is
  13. ;        the high value and byte 2 the low value. If A FAILS to 
  14. ;        equal or fit b/n these values then the following 
  15. ;        address is jmp'd to. An example follows.
  16. ;
  17. ; Table    db    high1,low1,address1
  18. ;    db    high2,low2,address2
  19. ;       "    "  "  "  "  "  "  "
  20. ;    db    lown,highn,addressn
  21. ;
  22. ;     lxi    d,table            ; Check against the first element
  23. ;    call    chktbl            ; check the table
  24. ;    ; Here is returned to if the value in A is between elemnts of the table
  25. ;    ; on exit DE--> next table element if we passed, else goto the address.
  26. ;    
  27. ;            Written        R.C.H.              18/8/82
  28. ;            Last Update    R.C.H.        18/8/83
  29. ;----------------------------------------------------------------
  30. ;
  31.     name    'chkrng'
  32. ;
  33.     public    chkrng,chktbl
  34.     maclib    z80
  35. ;
  36. chkrng:    ; See if D <= A <= E
  37.     sta    temp                ; Save the value
  38.     cmp    d
  39.     jrz    chkrng15
  40.     jrnc    rng$fail            ; NO CARRY = A is too big
  41. chkrng15:
  42.     cmp    e
  43.     jrc    rng$fail
  44.     xra    a                ; Load ZERO indicator flag
  45. chkrng2:    ; Restore the accumulator and return
  46.     lda    temp    
  47.     ret
  48. ;
  49. rng$fail:    ; Load a non zero flag and return
  50.     mvi    a,0ffh
  51.     ora    a                ; ensure ZERO is OFF-A-MUNDO
  52.     jr    chkrng2                ; Re-load accumulator and exit
  53. ;
  54. ;
  55. chktbl:    ; Check a table against the value in A
  56.     push    h
  57.     xchg                ; HL --> table
  58.     mov    d,m            ; high value
  59.     inx    h
  60.     mov    e,m            ; low value
  61.     inx    h            ; now we point to address field
  62.     call    chkrng            ; check the range now
  63.     jrnz    goto$address        ; WE FAIL if NON ZERO
  64.     inx    h
  65.     inx    h            ; point to next table element now
  66.     xchg                ; put into de again
  67.     pop    h
  68.     ret
  69. ;
  70. ; Here is jumped to if the accumulator does not fit between the values
  71. ; in the table. This routine must load the table address and jump to it.
  72. ;
  73. goto$address:
  74.     mov    e,m            ; low address stored first
  75.     inx    h
  76.     mov    d,m            ; high address
  77.     inx    h            ; point to next table element for later
  78.     xchg                ; now DE = table addr, HL = address
  79.     xthl                ; HL = original , top = address
  80.     lda    temp
  81.     ret            ; goto the address
  82. ;
  83.     dseg                ; data segment
  84. temp    db    00            ; save the accumulator temporarily
  85.  
  86.     end
  87.  
  88.  
  89.