Il_Voza

3.4 Sum of every row and column into last column and row

May 12th, 2013
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Given thw following table of word:
  2. ;  154  123   109  86    4   ?
  3. ;  412  -23  -231   9   50   ?
  4. ;  123  -24    12  55  -45   ?
  5. ;    ?    ?     ?   ?    ?   ?
  6.  
  7. ;Implement the program that writes the sum of every row and column respectively into last column and last row
  8.  
  9. R EQU 4
  10. C EQU 6
  11. .MODEL small
  12. .STACK
  13. .DATA
  14. table DW 154,123,109,86,4,?
  15.       DW 412,-23,-231,9,50,?
  16.       DW 123,-24,12,55,-45,?
  17.       DW C DUP (?)
  18. var DW ?
  19. .CODE
  20. .STARTUP
  21. MOV BX,0
  22. MOV DI,0
  23. MOV AX,0
  24. MOV CX,C-1   ;CX and DX are used like counters to go out from cycles
  25. MOV DX,R-1
  26. ciclo1:
  27.  
  28.        ciclo11:
  29.               ADD AX,table[BX][DI]
  30.               ADD DI,2
  31.               DEC CX
  32.               CMP CX,0
  33.               JNE ciclo11
  34.        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 ?
  35.        MOV DI,0
  36.        MOV AX,0
  37.        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
  38.                   ;So the offset between rows of a given matrix DW is: BX=2*NumColumns
  39.        MOV CX,C-1
  40.        DEC DX
  41.        CMP DX,0
  42.        JNE ciclo1
  43.        
  44. MOV BX,0
  45. MOV DI,0
  46. MOV AX,0
  47. MOV CX,C  ;C, not C-1 because now I have also the last column that before had the ?
  48. MOV DX,R-1
  49. ciclo2:
  50.        
  51.        ciclo22:
  52.                ADD AX,table[BX][DI]
  53.                ADD BX,C*2
  54.                DEC DX
  55.                CMP DX,0
  56.                JNE ciclo22
  57.        MOV table[BX][DI],AX
  58.        MOV DX,R-1 ;C, not C-1 because now I have also the last column that before had the ?
  59.        MOV BX,0
  60.        ADD DI,2
  61.        MOV AX,0
  62.        DEC CX
  63.        CMP CX,0
  64.        JNE ciclo2
  65. .EXIT
  66. END
Advertisement
Add Comment
Please, Sign In to add comment