Quantcast
Channel: x86 Assembly - Programmers Heaven
Viewing all articles
Browse latest Browse all 152

matrix diagonal & loops

$
0
0
with the following program I want to print on the screen the matrix diagonal. I need help to improve the code especially diagonal proc.
How can I use loops in diagonal proc?

Data segment
m db 25, 45, 67, 89
db 70, 30, 45, 23
db 34, 67, 89, 23
db 44, 55, 66, 77
msg db 'Matrix diagonal:$'
digit db ?
num db ?, '$'
x dw ?
y dw ?
Data ends

Sseg segment stack 'stack'
db 100h dup(?)
Sseg ends

Code segment
assume cs:code, ds:data

;====================================
; input:
; output:
; purpose:
; registers changed:
;====================================

diagonal proc
mov ax, data
mov es, ax
mov al, digit ; allocate space for integer
mov ah, 0 ; set video mode
mov bl, 10
div bl ; divide by 10

mov digit, ah
mov dl, al
add dl, '0'

pushx
mov num, dl
mov bp, offset num
mov ah, 13h ; function 13 - write string
mov bh, 0 ; screen page 0
mov bl, red_on_green ; color
mov cx, 1 ; length of string
mov dl, byte ptr y ; column
mov dh, byte ptr x ; row
mov al, 0
int 10h
popx

mov al, digit ; allocate space for integer
mov ah, 0 ; set video mode
mov bl, 1 ;//////////////////////
div bl ; divide by 10

mov dl, al
add dl, '0'

pushx
mov num, dl
mov bp, offset num
mov ah, 13h ; function 13 - write string
mov bh, 0 ; screen page 0
mov bl, red_on_green ; color
mov cx, 1 ; length of string
inc y ;///////////////////
mov dl, byte ptr y ; column
mov dh, byte ptr x ; row
mov al, 0
int 10h
popx

mov ax, data
mov ds, ax
ret
endp

;********************** Print Matrix ****************************

printMatrix proc
print msg
new_line

; initialize variables
mov bx, 0
mov cx, 4 ; 4 rows in the matrix
mov x, 10
mov y, 30

show: push bx
mov al, m[bx]
mov digit, al
add x, 1
add y, 2
call diagonal
pop bx

add bx, 5
loop show
ret
endp



Viewing all articles
Browse latest Browse all 152

Trending Articles