Monday, November 3, 2008

Displaying asterisk triangles

This is the inverted of the last one so here goes nothing

Source Code:

jmp start
mess1 db 10,13, "Enter a value (n) [0-9 only]: $"
mess2 db 10,13, "Do you want to continue (y/n): $"
mess3 db 10,13, "There is nothing to display $"
space db " $"
lincar db 10,13, "$"
value db 0
counter db 0
s_counter 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
jl start
cmp al,9
jg start

mov value,al
cmp al,0
je zero

lea dx,lincar
mov ah,9
int 21h

mov ah,0
mov al,value

mov cx,ax
mov counter,1
mov bh,counter
mov bl,value
mov al,0
display:
cmp bh,bl
jg next

mov dl,'*'
mov ah,2
int 21h

lea dx,space
mov ah,9
int 21h

inc bh
jmp display

next:
dec bl
inc al
mov bh,counter

lea dx,lincar
mov ah,9
int 21h

loop display
jmp quit
zero:
lea dx, mess3
mov ah,9
int 21h
quit:
int 20h

No comments: