I am developing this exercise:
write the assembler program that, given a character as input, outputs a triangle of size 5 x 5 of the character itself.
I have a problem because when I go to input a character, the characters do not form a triangle, but other characters are printed.
My input:
f
My output:
Desired output:
f
ff
fff
ffff
fffff
My code:
Title PROVA
;programma per la prova dell’ambiente Turbo Assembler
DOSSEG
.MODEL SMALL
.STACK 100
.DATA
; se ci sono qui vanno dichiarate le vriabili
.CODE
MOV AX, @data ;(obbligatorie) inizializzano il DS
MOV DS, AX
MOV AX, 00
MOV BX, 00
MOV CX, 00
MOV DX, 00
mov ah,01h ;input va a mettere l'input in AL ;n
int 21h
MOV BL, AL ;n
MOV CL, BL ;n
MOV CH, 0H
ciclo:
CMP CH, 5H
JE fine
inc CH
MOV DL, BL
mov ah, 02h ;stampa il contenuto di dl
int 21h
mov DL, 10D
int 21h
mov DL, 13D
int 21h
;BL
ADD BL, CL
JMP ciclo
fine:
MOV AL, 00H ;(obbligatorie) ritornano il controllo al sistema operativo
MOV AH, 4CH
INT 21H
END
As vitsoft pointed out, the char changed because you add CL
to BL
.
To make a triangle you need to use another loop, as Michael said.
Below is the part to change:
MOV AH, 01h ; input va a mettere l'input in AL ;n
INT 21H
MOV BL, AL ; n
MOV CH, 0H
ciclo:
CMP CH, 5H
JE fine
INC CH
MOV DL, 10D
INT 21H
MOV DL, 13D
INT 21H
MOV CL, CH
MOV AH, 02H ; stampa il contenuto di dl
MOV DL, BL
innerLoop:
INT 21H
DEC CL
JNE innerLoop
JMP ciclo
fine: