我正在写一个简单的计算器(add,sub,mul,div,带有做功能和模数的选项) 在8086年的集会中 我得到一个错误说“2000字节后找不到字节24h。” 打印出来之后。 我很确定当代码到达第142行并使用printStr过程时会发生错误。 请帮忙吗?
data segment
menu db 'Please enter your Choice of action :',10,13 ;action selection screen
db 'for Add press +',10,13
db 'for Sub press -',10,13
db 'for Mul press *',10,13
db 'for Div press /',10,13
db 'for mod press %',10,13
db 'for Pow press ^',10,13
db 'for Exit press x$'
enterNum1 db 'Please enter the first number$'
enterNum2 db 'Please enter the second number$'
error db 'Incorrect option, please try again$'
newline db 13,10,'$'
numStr db ?,?,?
action db ?
num1 db ?
num2 db ?
resultStr db ?,?,?
result db ?
ends
stack segment
dw 255 dup(0)
ends
code segment
printStr:
mov bp,sp
push dx
push ax
mov dx,[bp+2]
mov ah,9
int 21h
pop ax
pop dx
ret 2
inputStr:
Push bp
mov bp,sp
Push ax
Push si
mov ah,1
mov si,[bp+4]
islo1:
mov ah,1
int 21h
CMP al,13
JE ishem1
mov [si],al
inc si
JMP islo1
ishem1:
mov Byte Ptr[si],'$'
Pop si
Pop ax
Pop bp
ret 2
strtoint:
Push bp
mov bp,sp
Push ax
Push dx
Push si
Push di
mov ax,0
mov dl,10
mov si,[bp+6]
mov di,[bp+4]
lo1:
cmp Byte Ptr[si],'$'
JE hem1
mul dl
mov dh,[si]
sub dh,30h
add al,dh
inc si
JMP lo1
hem1:
mov [di],al
Pop di
Pop si
Pop dx
Pop ax
Pop bp
ret 4
inttostr:
Push bp
mov bp,sp
Push ax
Push dx
Push si
Push cx
mov cx,0
mov dl,10
mov si,[bp+6]
mov ax,[bp+4]
cmp ax,0
JZ it01
lo3:
cmp al,0
JZ he1
mov ah,0
div dl
push Ax
inc Cx
cmp al,0
JZ he1
JMP lo3
it01:
mov cx,1
JMP it0
he1:
l2:
pop Ax
it0:
add ah,30h
mov [si],ah
inc si
loop l2
mov Byte Ptr[si],'$'
Pop cx
Pop si
Pop dx
Pop ax
Pop bp
ret 4
plus:
push ax
push offset enterNum1 ; input the first number
call printStr
push offset numStr
call inputStr
push offset newline
call printstr
push offset numStr ; convert the string of the first number to an actual number
push offset num1
call strtoint
; input the second number
push offset enterNum2
call printStr
push offset numStr
call inputStr
push offset newline
call printstr
push offset numStr ; convert the string of the second number to an actual number
push offset num2
call strtoint
mov al, num1
add al, num2
mov result, al
push offset resultStr
push offset result
call inttostr
push offset resultStr
call printstr
ret
start:
mov ax,data
mov ds,ax
repeat:
push offset menu
call printStr ; print the menu to the user
push offset newline
call printStr
push offset action ; input the action from the user
call inputStr
; push offset newline
;call printStr
cmp action,'+'
JE addition
cmp action,'-'
JE subtraction
cmp action,'*'
JE multiplication
cmp action,'/'
JE devision
push offset error ; if the user didn't enter any of the options, the code will get to here, and the user will be asked to try again
call printStr
push offset newline
call printStr
push offset newline
call printStr
jmp repeat
addition:
call plus
subtraction:
; call minus
multiplication:
; call star
devision:
; call slash
mov ax, 4c00h
int 21h
ends
end start
答案 0 :(得分:0)
printStr不会推送和弹出BP - 这可能没有帮助