Advertisement
Il_Voza

2.2 Sum by DoubleWord

May 4th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Write a program in Assembly that adds the following numbers represented in a vector of byte: -5,-45,-96,-128
  2. ;Sum must be saved into variable 'risultato' of type doubleword
  3. ;Sum again at 'risultato' the addend value, variable of type doubleword with value 69000
  4. ;-When debugging, be careful to way in which doubleword are stored
  5.  
  6. ;IMPLEMENTATION
  7. ;Variables of vector are byte in CA2
  8. ;-To execute the sum on word, it's need of extend the sign: CBW (NB: ONLY for CA2)
  9. ;Doubleword variables are stored starting from the least significant byte
  10. ;Partial result on word must be extended to doubleword: CWD (NB: ONLY for CA2)
  11. ;Attention to the sum of carry when it is necessary:
  12. ;ADC instruction
  13.  
  14. .MODEL small
  15. .STACK
  16. .DATA
  17. vett DB 5,-45,-96,-128
  18. RES DD ?
  19. ADDENDO DD 69000
  20. .CODE
  21. .START
  22. MOV CX,4
  23. MOV BX,0
  24. MOV DX,0
  25. ciclo: MOV AL,vett[BX] ;In ciclo I save sum of elements
  26.        INC BX
  27.        CBW
  28.        ADD DX,AX ;I use DX like temporary container so that I don't use other variables
  29.        DEC CX
  30.        JNZ ciclo
  31. MOV AX,DX
  32. CWD
  33. ADD AX,WORD PTR ADDENDO
  34. ADC DX,WORD PTR ADDENDO+2 ;When I must sum at DX, I do always ADC
  35. MOV WORD PTR RES,AX
  36. MOV WORD PTR RES+2,DX ;So, when I have a number in 32 bit
  37.                       ;in which I must pass a number in 32 bit
  38.                       ;I divide my number into two registers
  39.                       ;AX e DX, and then I copy into RES like I did
  40.                       ;here!!!! DOUBLE WORD ARE TREATED SO!  
  41.  
  42. .EXIT
  43. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement