Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Write a program in Assembly that adds the following numbers represented in a vector of byte: -5,-45,-96,-128
- ;Sum must be saved into variable 'risultato' of type doubleword
- ;Sum again at 'risultato' the addend value, variable of type doubleword with value 69000
- ;-When debugging, be careful to way in which doubleword are stored
- ;IMPLEMENTATION
- ;Variables of vector are byte in CA2
- ;-To execute the sum on word, it's need of extend the sign: CBW (NB: ONLY for CA2)
- ;Doubleword variables are stored starting from the least significant byte
- ;Partial result on word must be extended to doubleword: CWD (NB: ONLY for CA2)
- ;Attention to the sum of carry when it is necessary:
- ;ADC instruction
- .MODEL small
- .STACK
- .DATA
- vett DB 5,-45,-96,-128
- RES DD ?
- ADDENDO DD 69000
- .CODE
- .START
- MOV CX,4
- MOV BX,0
- MOV DX,0
- ciclo: MOV AL,vett[BX] ;In ciclo I save sum of elements
- INC BX
- CBW
- ADD DX,AX ;I use DX like temporary container so that I don't use other variables
- DEC CX
- JNZ ciclo
- MOV AX,DX
- CWD
- ADD AX,WORD PTR ADDENDO
- ADC DX,WORD PTR ADDENDO+2 ;When I must sum at DX, I do always ADC
- MOV WORD PTR RES,AX
- MOV WORD PTR RES+2,DX ;So, when I have a number in 32 bit
- ;in which I must pass a number in 32 bit
- ;I divide my number into two registers
- ;AX e DX, and then I copy into RES like I did
- ;here!!!! DOUBLE WORD ARE TREATED SO!
- .EXIT
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement