.MODEL SMALL,STDCALL
.386
.DATA
digit db 0
n db ?
i db 0
j db 0
num db 0
array db 10000 dup(0)
.CODE
main proc
;装载数据段地址
mov ax,@data
mov ds,ax
;-----------------把输入存到n中
mov bx, 0
Newchar:
mov ah, 1
int 21h
sub al, 30h
jl endinput
cmp al, 9
jg endinput
cbw
xchg ax, bx
mul cx
xchg ax, bx
add bx, ax
jmp newchar
endinput:
mov n,bl
;-----------------
mov al,1
mov array[0],al
mov al,1
mov digit,al
mov ch,0
mov cl,n
sub cl,2
firstloop:
;i = n - cx = al
mov ah,0
mov al,n
sub ax,cx
mov i,al
;num = 0 = dl,dh也用了
mov dh,0
mov dl,0
mov num,dl
;------------ j = 0 = bx
mov bx,0
secondloop:
; --------temp=a[j]*i+num;
mov al,i
mov ah,array[bx]
mul ah;->ax
add ax,dx
mov dh,10;暂时借用dh,一会儿要再改回dh=0
div dh
; ----------a[j]=temp%10;
mov array[bx],ah
; -----------num=temp/10;
mov dl,al
mov num,dl
mov dh,0
add bx,1
mov j,bl
cmp bl,digit
jl secondloop
whileloop:
mov dl,num
mov dh,0
cmp dx,0
je tonext
mov ax,dx
mov dh,10;暂时借用dh,一会儿要再改回dh=0
div dh
mov dh,0
mov j,bl
mov bh,0;原本bx是j,暂时改成digit
mov bl,digit
mov array[bx],ah
; num=num/10;
mov dl,al
; digit++;
add bl,1
mov digit,bl
mov bl,j;还原bx的值j
cmp dx,0
jne whileloop
tonext:
mov al,i
add al,1
mov i,al
sub cx,1
cmp al,n
jle firstloop
; ------------逆序打印一下
mov bh,0
mov bl,digit
sub bl,1
printloop:
MOV DL,array[bx]
add dl,30h
mov ah,2
int 21h
sub bx,1
cmp bx,0
jnl printloop
jmp exit;
exit:
mov ah,4ch
int 21h
main endp
end main
原文链接: