0% found this document useful (0 votes)
29 views3 pages

Pattern

This program asks the user to input a number representing the number of rows for an upper star diamond pattern. It then prints the upper and lower patterns with the number of stars and spaces adjusted based on the row number. For the upper half, it prints spaces equal to the total rows minus the current row, and stars equal to twice the current row minus 1. For the lower half, it prints spaces equal to the current row and stars equal to twice the total rows minus the current row plus 1.

Uploaded by

primasg637
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Pattern

This program asks the user to input a number representing the number of rows for an upper star diamond pattern. It then prints the upper and lower patterns with the number of stars and spaces adjusted based on the row number. For the upper half, it prints spaces equal to the total rows minus the current row, and stars equal to twice the current row minus 1. For the lower half, it prints spaces equal to the current row and stars equal to twice the total rows minus the current row plus 1.

Uploaded by

primasg637
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

.

model small
.stack 100h
.data
msg1 db 'Enter total number of UPPER rows: $'
msg2 db 'Star diamond below: $'
rCount db ?
rFinal db ?
.code
main proc
mov ax, @data
mov ds, ax

mov ah, 9
mov dl, offset msg1
int 21h

mov ah, 1
int 21h
sub al, 48
mov rFinal, al

;NEWLINE for msg2


mov ah, 2
mov dl, 13
int 21h
mov dl, 10
int 21h

mov ah, 9
mov dl, offset msg2
int 21h

;NEWLINE
mov ah, 2
mov dl, 13
int 21h
mov dl, 10
int 21h
;NEWLINE
mov ah, 2
mov dl, 13
int 21h
mov dl, 10
int 21h

;UPPER HALF
mov rCount, 0
;Pattern upper half design start
DesignUp:
mov cx, 0 ;to make CH = 0
mov dx, 0 ;to make DH = 0
inc rCount

;SPACE PER ROW = total upper row - current row


mov cl, rFinal
sub cl, rCount
spaceUp:
cmp cl, 0
je breakSpaceUp
mov dl, 32
mov ah, 2
int 21h
loop spaceUp
breakSpaceUp:

;STARS PER ROW = current row * 2 - 1


mov cl, rCount
add cl, cl
sub cl, 1
patternUp:
cmp cl, 0
je breakPatternUp

mov dl, '*'


mov ah, 2
int 21h
loop patternUp
breakPatternUp:

;NEWLINE
mov ah, 2
mov dl, 13
int 21h
mov dl, 10
int 21h

;design break condition if total upper row = current row


mov bl, rCount
cmp bl, rFinal
je breakDesignUp
loop DesignUp
breakDesignUp:

;LOWER HALF
sub rFinal, 1 ;lower row = upper row - 1
mov rCount, 0
;Pattern lower half design start
DesignLow:
mov cx, 0 ;to make CH = 0
mov dx, 0 ;to make DH = 0
inc rCount

;SPACE PER ROW = current row


mov cl, rCount
spaceLow:
cmp cl, 0
je breakSpaceLow

mov dl, 32
mov ah, 2
int 21h
loop spaceLow
breakSpaceLow:

;STARS PER ROW = (total lower row - current row) * 2 + 1


mov cl, rFinal
sub cl, rCount
add cl, cl
add cl, 1
patternLow:
cmp cl, 0
je breakPatternLow

mov dl, '*'


mov ah, 2
int 21h
loop patternLow
breakPatternLow:

;NEWLINE
mov ah, 2
mov dl, 13
int 21h
mov dl, 10
int 21h

;design break condition if total row = current row


mov bl, rCount
cmp bl, rFinal
je breakDesignLow
loop DesignLow
breakDesignLow:
mov ah, 4ch
int 21h
main endp
end main

You might also like