加法代码问题
程序代码:
data segment ;数据代码段 buf db 20,?,20 dup(?) A dw 0 B dw 0 result dw ? crlf db 0ah,0dh,'$' data ends ;数据代码段结束 code segment assume cs:code,ds:data start: mov ax,data mov ds,ax lea dx,buf mov ah,10 int 21h inc dx mov di,dx mov cx,[di] and cx,0ffh mov bl,16 next: inc di mov al,[di] cmp al,'+' je jadd cmp al,'-' je jsub cmp al,'Z' jle no1 sub al,20h no1: cmp al,'9' jle no2 sub al,7 no2: sub al,30h mov bh,al mov ax,A mul bl mov A,ax mov al,bh and ax,0ffh add A,ax dec cx jmp next jadd: call proc1 mov ax,A add ax,B jmp exit jsub: call proc1 mov ax,A sub ax,B jmp exit exit: mov result,ax lea dx,crlf mov ah,9 int 21h lea bx,buf mov ax,[bx+1] and ax,0ffh add bx,ax mov byte ptr[bx+2],'=' mov byte ptr[bx+3],'$' lea dx,buf add dx,2 mov ah,9 int 21h mov ax,result call DISPLAY mov ah,4ch int 21h proc1 proc near mov bl,16 dec cx continue: inc di mov al,[di] cmp al,'Z' jle no5 sub al,20h no5: cmp al,'9' jle no6 sub al,7 no6: sub al,30h mov bh,al mov ax,B mul bl mov B,ax mov al,bh and ax,0ffh add B,ax loop continue ret proc1 endp DISPLAY PROC NEAR MOV CX,0 MOV BX,16 CONTINUE1: XOR DX,DX DIV BX PUSH DX INC CX CMP AX,0 JNZ CONTINUE1 NEXT1: POP DX AND DX,0FFH ADD DL,30H CMP DL,'Z' JLE no3 SUB DL,20H no3: CMP DL,'9' JLE no4 ADD DL,7 no4: MOV AH,02 INT 21H LOOP NEXT1 mov ah,01h int 21h DISPLAY ENDP code ends end start
这个代码是我从网上找来的一段代码,但是测试之后发现有点小问题
这个代码实现的是简易计算器功能
但是当测试1111+1111时显示的是222
貌似少了一位
但是我也不知道问题出在哪里
(我只留下了程序中的加法和减法运算)
求解~