Matrix in assembly mxn dimension in emu 8086

Discussion in 'Homework Help' started by zemzi, Jan 5, 2012.

  1. zemzi

    Thread Starter New Member

    Dec 14, 2011
    8
    0
    I made a code in assembly 8086. I load matrix (array) in memory with dimension 3x3. but this code works just for this dimension of matrix 3x3. Could someone give me an idea how could i make it to work with dimension m x n? the array is loaded in memory and at the end just print the result, another array. thanks

    Code ( (Unknown Language)):
    1. ; multi-segment executable file template.
    2.  
    3. data segment
    4. matrix db 1, 2, 3, 4, 5, 6, 7, 8, 9 ; load matrix in memory
    5.  
    6. ends
    7.  
    8. stack segment
    9. dw 128 dup(0)
    10. ends
    11.  
    12. code segment
    13. start:
    14. ; set segment registers:
    15. mov ax, data
    16. mov ds, ax
    17. mov es, ax
    18.  
    19.  
    20.  
    21. mov bx, matrix ; move matrix to offset bx
    22. mov ch, 3
    23. mov cl, 0
    24.  
    25.  
    26. COLUMNAHEAD:
    27.  
    28. mov dl, [bx] ; get the first element of matrix in dl
    29. add dl, 30h ; add to show number
    30. mov ah, 02h
    31. int 21h ; print first number
    32. inc cl
    33.  
    34. cmp cl, ch ; compare if the counter is at the end of column
    35.  
    36.  
    37. jge ROWAHEAD ; if greater go to row
    38. add bx, 3 ; if not inc offset for 3
    39. jmp COLUMNAHEAD
    40.  
    41.  
    42.  
    43.  
    44.  
    45. ROWAHEAD:
    46. inc cl ; 1 element of roe
    47. inc bx ; inc offset for one place
    48. mov dl, [bx] ; get the number in dl
    49. add dl, 30h ; convert to number
    50. mov ah, 02h
    51. int 21h ; print the number
    52.  
    53. cmp cl, 5
    54. je COLUMNAHEAD
    55. jne ROWAHEAD
    56.  
    57.  
    58. COLUMNBACK:
    59. inc cl
    60. sub bx, 3
    61. mov dl, [bx]
    62. add dl, 30h
    63. mov ah, 02h
    64. int 21h
    65. cmp cl, 7
    66. jne COLUMNBACK
    67. je ROWBACK
    68.  
    69. ROWBACK:
    70. dec bx
    71. mov dl, [bx]
    72. add dl, 30h
    73. mov ah, 02h
    74. int 21h
    75. JMP MIDDLE
    76.  
    77.  
    78. MIDDLE:
    79. add bx, 3
    80. mov dl, [bx]
    81. add dl, 30h
    82. mov ah, 02h
    83. int 21h
    84.  
    85. JMP END
    86.  
    87. END:
    88.  
    89.  
    90. this is the code i wrote. it works for the matrix
    91. 1, 2, 3,
    92. 4, 5, 6,
    93. 7, 8, 9 and print 1, 4, 7, 8, 9, 6, 3, 2, 5
     
Loading...