Thursday, December 11, 2008

matrix transpose sample (reverse rows with columns).

; matrix.asm
; name "matrix"
org 100h
jmp start ; go to code...
msg db "to the view matrix click vars button,", 0dh,0ah db " and set elements property to 3 for these items:", 0dh,0ah, 0ah db " matrix ", 0dh,0ah db " row1 ", 0dh,0ah db " row2 ", 0dh,0ah, 0dh,0ah db "or add print-out support to this program...", 0dh,0ah, '$'
matrix_size equ 3
; ----- matrix ------ matrix db 1,2,3row1 db 4,5,6row2 db 7,8,9;--------------------
i dw ?j dw ?
start:mov i, 0next_i:
; j = i + 1 mov cx, i inc cx mov j, cx next_j:
mov si, i mov bx, j
mov al, matrix_size mov cx, si mul cl mov si, ax mov dl, matrix[si][bx]
mov si, i mov al, matrix_size mul bl mov bx, ax xchg matrix[bx][si], dl
mov bx, j mov al, matrix_size mov cx, si mul cl mov si, ax mov matrix[si][bx], dl
inc j cmp j, matrix_size jb next_jinc icmp i, matrix_size/2jbe next_i
; print message.... lea dx, msgmov ah, 9int 21h
; wait for any key press... mov ah, 0int 16h
ret

No comments: