I’m making an Akinator-like game in NASM.
If I type the answer for the first question it makes it the answer for all the questions
It is a simple yes or no answer.
please help fix it and if you can give an explanation.
Below is the code.
section .data
; questions
q1 db 'Is your character real? (yes/no)', 0
q2 db 'Is your character human? (yes/no)', 0
q3 db 'Is your character male? (yes/no)', 0
q4 db 'Is your character fictional? (yes/no)', 0
q5 db 'Is your object/animal living? (yes/no)', 0
; answers
a1 db 'red', 0
a2 db 'jabol', 0
a3 db 'kuromi', 0
a4 db 'pencil', 0
section .bss
answer resb 2
section .text
global _start
_start:
; q1
mov eax, 4
mov ebx, 1
mov ecx, q1
mov edx, 24
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, answer
mov edx, 2
int 0x80
cmp byte [answer], 'yes'
je human
cmp word [answer], 'no'
je object_animal
human:
; Question 2
mov eax, 4
mov ebx, 1
mov ecx, q3
mov edx, 30
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, answer
mov edx, 2
int 0x80
cmp byte [answer], 'yes'
je male
cmp word [answer], 'no'
je female
male:
mov eax, 4
mov ebx, 1
mov ecx, a1
mov edx, 13
int 0x80
jmp exit
female:
mov eax, 4
mov ebx, 1
mov ecx, a2
mov edx, 8
int 0x80
jmp exit
object_animal:
; Question 3
mov eax, 4
mov ebx, 1
mov ecx, q5
mov edx, 30
int 0x80
mov eax, 3
mov ebx, 0
mov ecx, answer
mov edx, 2
int 0x80
cmp byte [answer], 'yes'
je living
cmp word [answer], 'no'
je non_living
living:
mov eax, 4
mov ebx, 1
mov ecx, a3
mov edx, 5
int 0x80
jmp exit
non_living:
mov eax, 4
mov ebx, 1
mov ecx, a4
mov edx, 6
int 0x80
jmp exit
exit:
mov eax, 1
xor ebx, ebx
int 0x80
New contributor
Duncan Red Benedict De Guzman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.