I must do a program in tasm which have to print a triangle on numbers like this:
input: n. Ex: n=4
output:
1
1 2
1 2 3
1 2 3 4
I've managed to make my program print this thing, but i also have to make it work with numbers between 0 and 255, not only for digits.
I know that i have to read a number digit by digit and create a sum like this:
if i have to read 82, i read firstly 8, put it in a register, and then, when i read 2, it must be added to 8*10.
Can you help me to implement this in my program?
.model small
.stack 100h
.data
msg db "Enter the desired value: $", 10, 13
nr db ?
.code
mov AX, @data
mov DS, AX
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
mov ah, 02h
int 21h
mov DX, OFFSET msg
mov AH, 9
int 21h
xor ax, ax
mov ah, 08h ;citire prima cifra din numar
int 21h
mov ah, 02h
mov dl, al
int 21h
sub al,30h
mov ah,10
mul ah
mov [nr],al ;mutam prima cifra inmultita cu 10 in nr
mov ah, 08h
int 21h
mov ah, 02h
mov dl, al
int 21h
sub al, 30h
add [nr], al
sub nr,30h
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
mov ah, 02h
int 21h
mov cx,1
mov bx,31h
mov ah, 2
mov dx, bx
int 21h
loop1:
xor ax, ax
mov al, nr
cmp ax, cx
je final
mov dl, 10
mov ah, 02h
int 21h
mov dl, 13
mov ah, 02h
int 21h
mov bx, 0
loop2:
inc bx
add bx,30h
mov ah, 2
mov dx, bx
int 21h
sub bx,30h
cmp bx, cx
jne loop2
inc bx
add bx,30h
mov ah, 2
mov dx, bx
int 21h
inc cx
jmp loop1
final:
mov AH,4Ch ; Function to exit
mov AL,00 ; Return 00
int 21h
end