Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Given thw following table of word:
- ; 154 123 109 86 4 ?
- ; 412 -23 -231 9 50 ?
- ; 123 -24 12 55 -45 ?
- ; ? ? ? ? ? ?
- ;Implement the program that writes the sum of every row and column respectively into last column and last row
- R EQU 4
- C EQU 6
- .MODEL small
- .STACK
- .DATA
- table DW 154,123,109,86,4,?
- DW 412,-23,-231,9,50,?
- DW 123,-24,12,55,-45,?
- DW C DUP (?)
- var DW ?
- .CODE
- .STARTUP
- MOV BX,0
- MOV DI,0
- MOV AX,0
- MOV CX,C-1 ;CX and DX are used like counters to go out from cycles
- MOV DX,R-1
- ciclo1:
- ciclo11:
- ADD AX,table[BX][DI]
- ADD DI,2
- DEC CX
- CMP CX,0
- JNE ciclo11
- MOV table[BX][DI],AX ;Since before that I go out from jump I did DI+2, now I write the result in that position of matrix, where there is ?
- MOV DI,0
- MOV AX,0
- ADD BX,C*2 ;IMPORTANT! Must be BX=C*2, that is the offset from a row of matrix to the other. C*2 because the matrix is a DW. If it was a BYTE, I would have added at BX only C
- ;So the offset between rows of a given matrix DW is: BX=2*NumColumns
- MOV CX,C-1
- DEC DX
- CMP DX,0
- JNE ciclo1
- MOV BX,0
- MOV DI,0
- MOV AX,0
- MOV CX,C ;C, not C-1 because now I have also the last column that before had the ?
- MOV DX,R-1
- ciclo2:
- ciclo22:
- ADD AX,table[BX][DI]
- ADD BX,C*2
- DEC DX
- CMP DX,0
- JNE ciclo22
- MOV table[BX][DI],AX
- MOV DX,R-1 ;C, not C-1 because now I have also the last column that before had the ?
- MOV BX,0
- ADD DI,2
- MOV AX,0
- DEC CX
- CMP CX,0
- JNE ciclo2
- .EXIT
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement