We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,492 Members — Technology Publication meets Social Media

# Matrix in assembly mxn dimension

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

1
Contributor
1
17 Hours
Discussion Span
1 Year Ago
Last Updated
2
Views
kikic
Light Poster
28 posts since Dec 2011
Reputation Points: 7
Skill Endorsements: 0

; multi-segment executable file template.

data segment
matrix db 1, 2, 3, 4, 5, 6, 7, 8, 9 ; load matrix in memory

ends

stack segment
dw 128 dup(0)
ends

code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax

mov bx, matrix ; move matrix to offset bx
mov ch, 3
mov cl, 0

mov dl, [bx] ; get the first element of matrix in dl
mov ah, 02h
int 21h ; print first number
inc cl

cmp cl, ch ; compare if the counter is at the end of column

jge ROWAHEAD ; if greater go to row
add bx, 3 ; if not inc offset for 3

inc cl ; 1 element of roe
inc bx ; inc offset for one place
mov dl, [bx] ; get the number in dl
add dl, 30h ; convert to number
mov ah, 02h
int 21h ; print the number

cmp cl, 5

COLUMNBACK:
inc cl
sub bx, 3
mov dl, [bx]
mov ah, 02h
int 21h
cmp cl, 7
jne COLUMNBACK
je ROWBACK

ROWBACK:
dec bx
mov dl, [bx]
mov ah, 02h
int 21h
JMP MIDDLE

MIDDLE:
mov dl, [bx]
mov ah, 02h
int 21h

JMP END

END:

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???

kikic
Light Poster
28 posts since Dec 2011
Reputation Points: 7