# printing a pyramid

hello, im only a beginner programmer is assembly, i have this code plz tell me wy its printing an infinite number of '*'

and plz help me with this code in printing a pyramid by taking the input for how many lines pyramid the user wants

.model medium
.stack 100h
.data
var1 db ?
var2 db '*'
temp db ?
.code
main proc
mov ax,@data
mov ds,ax
mov temp,'0'
mov bx,'1'
start:
start1:
inc temp
mov ah,2
mov dl,var2
int 21h
cmp bx,temp
jne start1
mov temp,'0'
mov ah,2
mov dl,0Ah
int 21h
cmp bx,'5'
jne start
mov ax,4c00h
int 21h
main endp
end main

• : plz tell me wy its printing an infinite number of '*'
:
: and plz help me with this code in printing a pyramid by taking the input for how many lines pyramid the user wants
[code]
.model medium
.stack 100h
.data
var1 db ?
var2 db '*'
temp db ?
.code
main proc
mov ax,@data
mov ds,ax
mov temp,'0'
mov bx,'1'
start:
start1:
inc temp
mov ah,2
mov dl,var2
int 21h
cmp bx,temp
jne start1
mov temp,'0'
mov ah,2
mov dl,0Ah
int 21h
cmp bx,'5'
jne start
mov ax,4c00h
int 21h
main endp
end main
[/code]
[green]
I didn't assemble & debug your code, but at first glance:
It appears that your conditions to jump/loop are too complicated
and this is where the error lies.
You are ADDing BX,2 and then checking CMP BX,'5'
and '5' = 53 which is an odd number, it will never find it with
JNE START
JA or JB type thing will work with mismatch number because when
the value is exceeded it JMPs or quits JMPing, so
JB START might be the cure.

Two labels together means that one label is not needed, as in
START:
START1:

MOV DL,VAR2 ; could be
MOV DL,'*' ; VAR2 isn't needed

;here's an average type loop in a loop (REPZ is a loop)
;Get keyboard input for height
;make a red pyrimid in Video mode 3

; .com file UNTESTED code, alter to suite, you debug
JMP START
MSG DB "Enter a number 1-9 (ESC=Exit)\$"
BEEP:
MOV AH,2 ; print char in DL function
MOV DL,7
INT 21h
START:
MOV AH,9 ;print message to \$ function
MOV DX,OFFSET MSG
INT 21h
MOV AH,8 ;get key function
INT 21h
CMP AL,27 ; ESC key?
JZ BYE
CMP AL,'1'
JB BEEP ;below '1' is bad = BEEP
CMP AL,'9' ; above '9' is bad = BEEP
JA BEEP
SUB AL,'0' ;convert char 1-9 from ASCII, to value
MOV CL,AL
XOR CH,CH ; CX = height now
PUSH ES
MOV AX,0xB800
MOV ES,AX
MOV DI,400 ; ES:DI = video seg:offset in memory
MOV AL,'*' ;character
MOV AH,4 ;color red
MOV DX,1 ; starting width
TOP: ;of loop
PUSH CX
PUSH DI
MOV CX,DX ;width
REPZ STOSW ;repeat write char & attribute to ES:DI
POP DI
ADD DI,158 ;down 1 row & left 1 column
INC DX ;width gets wider x2
INC DX
POP CX
LOOP TOP
POP ES
MOV AH,8 ;pause (get key with out echo)
INT 21h
BYE:
MOV AX,0x4C00 ; exit program with errorlevel 00 in AL reg
INT 21h

;you could replace REPZ STOSW with a LABEL:, instructions, & LOOP LABEL

I hope that helps some how

Bitdog
[/green]