[英]Printing a triangle of characters in assembly
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.编写汇编程序,给定一个字符作为输入,输出一个字符本身大小为 5 x 5 的三角形。
I have a problem because when I go to input a character, the characters do not form a triangle, but other characters are printed.我有一个问题,因为当我 go 输入一个字符时,字符没有形成三角形,而是打印了其他字符。
My input:我的输入:
f F
My output:我的 output:
Desired output:所需的 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
.正如 vitsoft 指出的那样,由于您将CL
添加到BL
,因此 char 发生了变化。 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:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.