我在程序集8086中做了一个代码。我在内存中加载矩阵(数组),尺寸为3x3。但是这个代码仅适用于矩阵3x3的这个维度。有人能给我一个想法,我怎么能使它与尺寸m x n一起工作?该数组加载到内存中,最后只是打印结果,另一个数组。在给定的存储器由于矩阵在程序集mxn尺寸
; 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
COLUMNAHEAD:
mov dl, [bx] ; get the first element of matrix in dl
add dl, 30h ; add to show number
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
jmp COLUMNAHEAD
ROWAHEAD:
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
je COLUMNAHEAD
jne ROWAHEAD
COLUMNBACK:
inc cl
sub bx, 3
mov dl, [bx]
add dl, 30h
mov ah, 02h
int 21h
cmp cl, 7
jne COLUMNBACK
je ROWBACK
ROWBACK:
dec bx
mov dl, [bx]
add dl, 30h
mov ah, 02h
int 21h
JMP MIDDLE
MIDDLE:
add bx, 3
mov dl, [bx]
add dl, 30h
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
矩阵从顺时针打印螺旋在相反的方向(左边的列向下右下范围,直到柱中,一系列左上等的直到到达的环境中)。这适用于维度3x3。这应该适用于mxn维度。但我不知道如何,任何建议?
你有什么麻烦? – 2011-12-24 19:22:11
我知道如何解决矩阵3x3,但我需要编写与矩阵m =行和n =列一起工作的代码....我上面写的代码只适用于矩阵3x3 .. – buuuuu 2011-12-24 19:26:08
是的,但是部分是这个问题?看来你已经掌握了程序集。 – 2011-12-24 19:27:23