在第一次2次呼叫後,沒有什麼不好的事情發生,但只要按下回車鍵選擇菜單,它會輸出兩個提示,要求用戶輸入,而不是在每次提示時暫停輸入操作數。納斯姆中斷呼叫跳過並輸出多行
爲什麼中斷會跳過?
我現在很困惑。
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
是的,我應該移動al而不是eax。而當減去'0'時,我發現當我的輸出是笑臉時。 – Kelvin
感謝您的幫助 – Kelvin
您是否推薦過關於如何正確設計/構造組裝程序的書籍?因爲我知道基本的功能/寄存器,但我不知道如何正確地把它們放在一起。我一步一步地使用匯編語言,這是偉大的,但它沒有足夠深入我的口味。 – Kelvin