我在程序集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