matrix in assembly 8086 mxn dimension

zemzi

Joined Dec 14, 2011
8
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

Rich (BB code):
; 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???

Last edited by a moderator:

RRITESH KAKKAR

Joined Jun 29, 2010
2,829
Are you trying to use 8086 uP??

zemzi

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

zemzi

Joined Dec 14, 2011
8
and works in emu 8086

holnis

Joined Nov 25, 2011
49
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.. ?

I use 8086, but I don't understand what is up?
up = the Micro-Processor.