Advertisement
Il_Voza

1.6 Compute average between elements of a vector

May 3rd, 2013
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Write a program that computes the (integer) average between DIM values of a vector of type byte, and saves the
  2. ;result into variable 'risultato'
  3. ;Verify rounding effected
  4.  
  5. DIM EQU 4
  6. .MODEL small
  7. .STACK
  8. .DATA
  9. vett DB 3,4,3,4
  10. res DB ?
  11. .CODE
  12. .STARTUP
  13. XOR SI,SI ;I initialize SI to 0
  14. MOV CX,DIM
  15. XOR AL,AL
  16.  
  17.  
  18. ciclo: ADD AL,vett[SI]
  19.        INC SI
  20.        DEC CX
  21.        CMP CX,0
  22.        JNZ ciclo  
  23. MOV AH,0
  24. MOV DL,DIM
  25. DIV DL ;Into division, DL is divisor,
  26.        ;and it must be a register. Dividend
  27.        ;is AX, but since I am considering 8 bit, it is AL
  28.        ;and AL is also the quotient of the division
  29.        ;The rest of division is into AH
  30. .EXIT
  31. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement