Showing posts with label Asterisk patterns. Show all posts
Showing posts with label Asterisk patterns. Show all posts

Tuesday, November 4, 2008

Displaying asterisk triangles


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 value,al
mov bh,al
mov ch,bh
mov cl,al
again:

cmp bh,0
je continue

lea dx,lincar
mov ah,9
int 21h

mov al,value
sub cl,al
back:

cmp cl,0
je display

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
dec ch
dec cl

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

Displaying asterisk triangles

This one is shape like a quadrilateral triangle


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

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

Displaying asterisk triangles

Another version with two triangles connected at one point

Source Code:

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

mov value,al

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,1
jmp display
zero_bridge:
call zero
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:
inc bl
mov bh,counter

lea dx,lincar
mov ah,9
int 21h

loop display

;-----------------------------------second half-------------------------------------

mov al,value
sub al,1
cmp al,0
je continue
mov ah,0

mov cx,ax
mov counter,1
mov bh,counter
mov bl,al
mov al,0

display2:
cmp bh,bl
jg next2

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

lea dx,space
mov ah,9
int 21h

inc bh
jmp display2

next2:
dec bl
inc al
mov bh,counter

lea dx,lincar
mov ah,9
int 21h

loop display2
jmp continue
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 quit

jmp continue

start_bridge:
call start

quit:
int 20h

Displaying asterisk triangles

This program displays to right triangles that are connected at one point. It uses a looping principle like the other asterisk triangle .
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_bridge
cmp al,0
jl start
cmp al,9
jg start
jmp main

zero_bridge:
call zero
main:
mov value,al
mov bh,al
mov ch,bh
mov cl,al
again:

cmp bh,0
je secondhalf

lea dx,lincar
mov ah,9
int 21h

mov al,value
sub 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
dec ch
dec cl

jmp again

;----------------------------socondhalf----------------------------

secondhalf:

mov al,value
sub al,1
mov bh,al
mov ch,2

again2:

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

back2:

cmp cl,0
je display2

lea dx,space
mov ah,9
int 21h

lea dx,space
mov ah,9
int 21h

inc cl

jmp back2
display2:

lea dx,asterisk
mov ah,9
int 21h

lea dx,space
mov ah,9
int 21h

inc cl

cmp cl,ch
jne display2

dec bh
inc ch

jmp again2
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

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

Displaying asterisk triangles

The third asterisk pattern


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 value,al
mov bh,al
mov ch,bh
mov cl,al
again:
cmp bh,0
je continue

lea dx,lincar
mov ah,9
int 21h

mov al,value
sub 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
dec ch
dec cl

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

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

Displaying asterisk triangles

Will it took me time to get myself to blogging again , this is one my own projects that I program using assembly in my school , but this is just one pattern I'll blog the rest after this


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

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,1
jmp display
start_bridge:
jmp start
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:
inc bl
mov bh,counter

lea dx,lincar
mov ah,9
int 21h

loop display
jmp continue
zero:
lea dx, mess3
mov ah,9
int 21h
jmp continue
continue:
xor dx,dx

lea dx,mess2
mov ah,9
int 21h

mov ah,1
int 21h

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

jmp continue
quit:
int 20h