home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / zendisk2.zip / LST13-8.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  1KB  |  58 lines

  1. ;
  2. ; *** Listing 13-8 ***
  3. ;
  4. ; Counts the number of negative values in a 1000-word array,
  5. ; by comparing each element to 0 and branching accordingly.
  6. ;
  7.     jmp    Skip
  8. ;
  9. WordArray    label    word
  10. X=-500
  11.     rept    1000
  12.     dw    X
  13. X=X+1
  14.     endm
  15. WORD_ARRAY_LENGTH    equ    ($-WordArray)
  16. ;
  17. ; Counts the number of negative values in a word-sized
  18. ; array.
  19. ;
  20. ; Input:
  21. ;    CX = length of array in words
  22. ;    DS:SI = pointer to start of array
  23. ;
  24. ; Output:
  25. ;    DX = count of negative values in array
  26. ;
  27. ; Registers altered: AX, CX, DX, SI
  28. ;
  29. ; Direction flag cleared
  30. ;
  31. ; Note: Does not handle arrays that are longer than 32K
  32. ;    words or cross segment boundaries.
  33. ;
  34. CountNegativeWords:
  35.     cld
  36.     sub    dx,dx    ;initialize the count to 0
  37. CountNegativeWordsLoop:
  38.     lodsw        ;get the next word from the array
  39.     and    ax,ax    ;is the word negative?
  40.     jns    CountNegativeWordsLoopBottom
  41.             ;not negative-do the next element
  42.     inc    dx    ;word is negative, so increment the
  43.             ; negative-word counter
  44. CountNegativeWordsLoopBottom:
  45.     loop    CountNegativeWordsLoop
  46.     ret
  47. ;
  48. Skip:
  49.     call    ZTimerOn
  50.     mov    si,offset WordArray
  51.             ;point to the array to count
  52.             ; the # of negative words in...
  53.     mov    cx,WORD_ARRAY_LENGTH/2
  54.             ;...set the # of words to check...
  55.     call    CountNegativeWords
  56.             ;...and count the negative words
  57.     call    ZTimerOff
  58.