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

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