matrix in assembly 8086 mxn dimension

Discussion in 'The Projects Forum' started by zemzi, Dec 24, 2011.

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

    Matrix given in memory to print the spiral in opposite direction from clockwise (left column down the right lower range, right up column, a series of upper left, etc. until you get to the environment). This works just for dimension 3x3. this should works for mxn dimension. but i don't know how, any suggestion???
     
    Last edited by a moderator: Dec 24, 2011
  2. RRITESH KAKKAR

    Senior Member

    Jun 29, 2010
    2,831
    89
    Are you trying to use 8086 uP??
     
  3. zemzi

    Thread Starter New Member

    Dec 14, 2011
    8
    0
    I use 8086, but I don't understand what is up? If you know how to solve my problem please help me?
     
  4. zemzi

    Thread Starter New Member

    Dec 14, 2011
    8
    0
    and works in emu 8086
     
  5. holnis

    Member

    Nov 25, 2011
    50
    4
    But,how exactly, do you want to get the values for the dimensions mxn of your matrix ?
    Is it via the command line or Do you input these values using a prompt box? Or maybe you read the dimensions from an other file.. ?


    up = the Micro-Processor.
     
Loading...