在进行前 2 次调用后,没有任何不好的事情发生,但只要您按 Enter 键选择菜单,它就会输出两个提示,要求用户输入,而不是在每个提示输入操作数时暂停。
为什么中断会跳过?
我现在真的很困惑。
SECTION .data
AskForCalculationPrompt: db "Choose which operation you want", 0xA, "1. Addition", 0xA, "2.Subtraction", 0xA, "3. Multiplication", 0xA, "4. Division", 0x3
AskForCalculationPromptln: equ $-AskForCalculationPrompt
FirstOperandPrompt: db "Enter the first operand:", 0xA
FirstOperandPromptln: equ $-FirstOperandPrompt
SecondOperandPrompt: db "Enter the second operand:", 0xA
SecondOperandPromptln: equ $-SecondOperandPrompt
AnswerPrompt: db "The answer is: "
AnswerPromptln: equ $-AnswerPrompt
ErrorMsg: db "Wrong Choice made...insert correct choice"
ErrorMsgln: equ $-ErrorMsg
SECTION .bss
Choice: resb 1
FirstOperand: resb 1
SecondOperand: resb 1
Answer: resb 1
SECTION .text
;Make interrupt to ask for a prompt ask for calculation prompt
global _start
_start:
mov eax, 4 ;Specify sys_write call
mov ebx, 1 ;Standard output
mov ecx, AskForCalculationPrompt
mov edx, AskForCalculationPromptln
int 80h
;Make interrupt to read textfrom keyboard
READ:
mov eax, 3 ;Sys_read call
mov ebx, 0 ;Standard input file descriptor 0
mov ecx, Choice
mov edx, 1
int 80h
;Determine what we inserted
;Prompt for first operand
mov eax, 4
mov ebx, 1
mov ecx, FirstOperandPrompt
mov edx, FirstOperandPromptln
int 80h
;Retrieve first operand input
mov eax, 3
mov ebx, 0
mov ecx, FirstOperand
mov ebx, 1
int 80h
;Prompt for second operand
mov eax, 4
mov ebx, 1
mov ecx, SecondOperandPrompt
mov edx, SecondOperandPromptln
int 80h
;Retrieve second operand input
mov eax, 3
mov ebx, 0
mov ecx, SecondOperand
mov edx, 1
int 80h
;Load values retrieved into registers eax, ebx, ecx, for comparison and operation
mov al, byte [Choice]
mov bl, byte [FirstOperand]
mov cl, byte [SecondOperand]
JMP SWITCH
;*******************************************************************************
;SWITCH*************************************************************************
;*******************************************************************************
SWITCH:
cmp al, 0x31
je ADDLABEL
cmp al, 0x32
je SUBTRACTLABEL
cmp al, 0x33
je MULTIPLICATIONLABEL
cmp al, 0x34
je DIVISIONLABEL
JMP DEFAULTLABEL
DEFAULTLABEL:
mov eax, 4
mov ebx, 1
mov ecx, ErrorMsg
mov edx, ErrorMsgln
int 80h
JMP READ
;*****************************************************************************
;OPERATIONS*******************************************************************
;*****************************************************************************
ADDLABEL:
mov al, cl
add al, bl
JMP DISPLAYOPERATION
SUBTRACTLABEL:
mov al, cl
sub al, bl
JMP DISPLAYOPERATION
MULTIPLICATIONLABEL:
mov al, cl
mul cl
JMP DISPLAYOPERATION
DIVISIONLABEL:
mov al, cl
div cl
JMP DISPLAYOPERATION
;*****************************************************************************
;DISPLAYOPERATION*************************************************************
;*****************************************************************************
DISPLAYOPERATION:
mov [Answer], eax
mov eax, 4
mov ebx, 1
mov ecx, Answer
mov edx, 1
int 80h
mov eax, 1
mov ebx, 0
int 80h