I have a problem in getcombo
function. I want to check if the value entered by the user is within the menu option range (1-4). So I compare the value entered by the user with integer values such as 1, 2, 3 and 4 with an if else
statement. But even when the user enter correct value the programm still ask the user to enter the value again.
INCLUDE Irvine32.inc
.data
MAX = 80
userInput BYTE MAX+1 DUP (?)
msgName BYTE 'Enter Your Name : ' ,0
msgPass BYTE 'Enter Your Password : ' , 0
comboTitle BYTE'COMBO Meals',0
line1 BYTE'==================',0
line2 BYTE'==================',0
comboMeal1 BYTE '1) Chicken Burger + Coca Cola + Cheesy Wedges | RM 15.00',0
comboMeal2 BYTE '2) Grilled Beef Burger + Pepsi + French Fries | RM 17.00',0
comboMeal3 BYTE '3) Spicy Korean Wings + Coca Cola + salad | RM 10.00',0
comboMeal4 BYTE '4) Chicken Pizza + mountain dew + minched Potato | RM 20.00',0
selectedCombo BYTE ' ',0
prompt1 BYTE 'Please select a Combo Meal : ',0
mealPrice1 dword 15.00
mealPrice2 dword 17.00
mealPrice3 dword 10.00
mealPrice4 dword 20.00
invalidLogin BYTE 'Invalid' , 0
invalidSelection BYTE'Please select within given menu option',0
validPass BYTE 'Valid Password' , 0
loginPassword BYTE "123" , 0
loginName BYTE "bob" , 0
.code
main PROC
Login :
;---------------- Display "Enter Your Name"
mov edx,OFFSET msgName
call WriteString
;---------------- Get name input
call GetInput
;---------------- compare user input and name
mov ebx , OFFSET loginName
.IF eax == [ebx]
;--------------- Correct input
;---------------- Display "Enter Your Password"
mov edx,OFFSET msgPass
call WriteString
;---------------- Get password input
call GetInput
;--------------- compare user input and password
mov ebx , OFFSET loginPassword
.IF eax == [ebx]
;--------------Correct input
jmp displayMenu
.ELSE
;--------------- Incorrect input
jmp InvalidInput
.ENDIF
;---------------
.ELSE
;-------------- Incorrect input
jmp InvalidInput
.ENDIF
InvalidInput :
;---------------Display "Invalid"
mov edx,OFFSET invalidLogin
call WriteString
call Crlf
;--------------- Repeat process
jmp Login
invalidMenuSelect:
xor edx,edx
mov edx, OFFSET invalidSelection
call WriteString
call Crlf
jmp getCombo
display:
mov edx,OFFSET validPass
call WriteString
displayMenu :
mov edx,OFFSET line1
call WriteString
call Crlf
xor edx,edx
mov edx,OFFSET comboTitle
call WriteString
call Crlf
xor edx,edx
mov edx,OFFSET line1
call WriteString
call Crlf
xor edx,edx
mov edx,OFFSET comboMeal1
call WriteString
call Crlf
xor edx,edx
mov edx,OFFSET comboMeal2
call WriteString
call Crlf
xor edx,edx
mov edx,OFFSET comboMeal3
call WriteString
call Crlf
xor edx,edx
mov edx,OFFSET comboMeal4
call WriteString
call Crlf
xor edx,edx
call Crlf
mov edx,OFFSET prompt1
call WriteString
call Crlf
xor edx,edx
jmp getCombo
exit
getCombo :
call GetInput
.IF eax == '1'
xor edx,edx
mov edx, OFFSET comboMeal1
;mov selectedCombo , edx
.ELSEIF eax == '2'
xor edx,edx
mov edx, OFFSET comboMeal2
;mov selectedCombo , edx
.ELSEIF eax == '3'
xor edx,edx
mov edx, OFFSET comboMeal3
;mov selectedCombo , edx
.ELSEIF eax == '4'
xor edx,edx
mov edx, OFFSET comboMeal4
;mov selectedCombo , edx
.ELSE
jmp invalidMenuSelect
.ENDIF
main ENDP
GetInput PROC
;-------------
;Get User input
;-------------
xor eax,eax
mov edx,OFFSET userInput
mov ecx,MAX
call ReadString
mov eax,[edx]
ret
GetInput ENDP
END main
The problem with your code is that the ReadString function you are using for input is adding the new line feed character to the eax register. To fix your issue, you can just check .IF al == '1'
and so on. A better approach would be to use the Irvine library function ReadChar
then check the al register.