Monday, November 3, 2008

Displaying asterisk triangles

The Fourth of the set
Source Code:

jmp start

mess1 db 10,13, "Enter value for (n) [0-9 only]: $"
mess2 db 10,13, "There is nothing to display $"
mess3 db 10,13, "Do you want to continue (y/n): $"
lincar db 10,13, "$"
space db " $"
asterisk db "*$"
value db 0

start:

xor ax,ax
xor bx,bx
xor cx,cx

mov ax,3
int 10h

lea dx,mess1
mov ah,9
int 21h

mov ah,1
int 21h
sub al,30h

cmp al,0
je zero
cmp al,0
jl start
cmp al,9
jg start

mov bh,al
mov value,al

mov ch,1

again:

cmp bh,0
je continue

lea dx,lincar
mov ah,9
int 21h

mov bl,value
mov al,ch

sub al,bl

mov cl,al

back:

cmp cl,0
je display

lea dx,space
mov ah,9
int 21h

lea dx,space
mov ah,9
int 21h

inc cl

jmp back
display:

lea dx,asterisk
mov ah,9
int 21h

lea dx,space
mov ah,9
int 21h

inc cl

cmp cl,ch
jne display

dec bh
inc ch

jmp again
zero:
lea dx,mess2
mov ah,9
int 21h
continue:
xor dx,dx

lea dx,mess3
mov ah,9
int 21h

mov ah,1
int 21h

cmp al,'y'
je start_bridge
cmp al,'n'
je exit

jmp continue

start_bridge:
call start
exit:
int 20h

No comments: