Reputation: 1
How to compare two char, the first one is user input.
include 'emu8086.inc'
#make_COM#
ORG 100h
answer DW ?
score DW ?
MOV score, 0
PRINT "This is a 10 question Exam"
PUTC 13
PUTC 10
PUTC 13
PUTC 10
PRINT "1.) A is the Answer"
PUTC 13
PUTC 10
PRINT " A.)"
PUTC 13
PUTC 10
PRINT " B.)"
PUTC 13
PUTC 10
PRINT " C.)"
PUTC 13
PUTC 10
PRINT " D.)"
PUTC 13
PUTC 10
PRINT "Your Answer: "
LEA DI, buffer
MOV DX, 10
CALL GET_STRING
MOV answer, AX
PUTC 13
PUTC 10
MOV SI, answer
CALL print_string
CMP SI, answer
JE Correct
JMP result
Correct:
ADD score, 1
JMP result
result:
PRINT "Your Score: "
CALL PRINT_NUM
RET
buffer DB "x"
DEFINE_SCAN_NUM
DEFINE_PRINT_NUM
DEFINE_PRINT_NUM_UNS
DEFINE_PRINT_STRING
DEFINE_GET_STRING
END
Upvotes: 0
Views: 197
Reputation: 9899
buffer DB "x"
This will not give you enough buffer space! If you stick with your definition of mov dx, 10
then you need to change this into: buffer db "1234567890"
. Since as I will explain 2 bytes will be enough this can become buffer db "12"
LEA DI, buffer MOV DX, 10 CALL GET_STRING MOV answer, AX
You don't seem to know how the GET_STRING procedure works! It stores your input zero-terminated in the DX bytes buffer at DS:DI. Since your answer will be a single character, you need to define DX=2 and you can retrieve the answer through mov ax, [di]
mov answer, ax
. Hereafter answer is a zero-terminated string having a single character for its contents.
MOV SI, answer CALL print_string
Here you moved the contents of answer in SI. You need the address of a zero-terminated string to be passed to the PRINT_STRING procedure, so write: lea si, answer
call PRINT_STRING
CMP SI, answer JE Correct JMP result
Because of how you setup SI
this compare will always return Correct. You have to compare the contents with a defined value: mov al, [si]
cmp al, "A"
(Hint: you wrote "A is the Answer")
Upvotes: 1