汇编求和,要求有输入输出。

来源:百度知道 编辑:UC知道 时间:2024/06/05 09:34:53
1 + (2+2) + 3 + (4+4) + 5 + (6+6) + 7+ …… +N,要求N的值从键盘输入,使用循环结构,N<20,计算显示为十进制。
急求!

DATAS SEGMENT
kyBuf db 3,?,4 dup(?)
ErMsg db "Input should in range 1-19, please try again ...$"
OutResult db 20 dup(?),"$"
Max dw 19
DATAS ENDS

STACKS SEGMENT
db 128 dup(?)
STACKS ENDS

CODES SEGMENT
ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
push ax
push bx
push cx
push dx
push si
push di

MOV AX,DATAS
MOV DS,AX
@waitky:
mov ah,0ah
lea dx,kyBuf
int 21h
xor cx,cx
lea si,kyBuf+1
mov cl,byte ptr[si]

mov bx,2
xor ax,ax
@CV:
mov dx,10
mul dx
mov dl,kyBuf[bx]
sub dl,"0"
add ax,dx
inc bx
loop @CV
cmp ax,Max
jg @ermsg
xchg ax,cx
xor ax,ax
mov si,2
@funnysum:
push ax
m