.MODEL SMALL .STACK .DATA msg1 db '1+2+...+$' odoa db 0dh,0ah,'$' t1 db 20 dup (?) tt db 20 dup (?) oper db 120 tmp db ? ans dw ? tmp1 dw ? tab db '0123456789' .CODE beg: MOV AX,@DATA MOV DS,AX ; call clrscr lea dx,msg1 mov ah,09 int 21h ; xor si,si xor ax,ax lea bx,tab mov dl,10 mov al,oper mov tmp,al ; store 120 into tmp ; cont: idiv dl mov tmp,al ; ah is the remainder, al is the quotient mov al,ah xlat mov tt[si],al inc si xor ax,ax mov al,tmp cmp al,0 je final jmp cont ; final: mov cx,si dec si pri: mov dl,tt[si] mov ah,02h int 21h dec si loop pri ; mov dl,'=' mov ah,02 ; print '=' int 21h ; ; begin to sum up total ; xor ax,ax mov al,oper mov cx,ax xor ax,ax sum: add ax,cx loop sum ; ; print result ; mov ans,ax ; store the sum result ; xor si,si xor dx,dx lea bx,tab mov cx,10 mov ax,ans ; cont1: idiv cx mov tmp1,ax ; dx is the remainder, ax is the quotient mov al,dl xlat mov tt[si],al inc si xor dx,dx mov ax,tmp1 cmp ax,0 je final1 jmp cont1 ; final1: mov cx,si dec si pri1: mov dl,tt[si] mov ah,02h int 21h dec si loop pri1 ; lea dx,odoa mov ah,09 int 21h ; mov ah,4ch int 21h ; clrscr proc push ax push es push di push cx mov ax,0b800h mov es,ax xor di,di mov cx,2000 mov ax,0720h rep stosw ; mov dx,0 mov ah,02 int 10h pop cx pop di pop es pop ax ret clrscr endp END beg