I'm trying to make a guessing game in NASM assembly using a kernel. The boot loader just points to the kernel file. The kernel file stores everything. All the functions and variables for the game; while Ive gotten as far to print instructions for the game out. The problem arises; when I use an if statement. It prints out the winning message whether it's the correct number or not. I want the kernel to print the correct winning message, when the correct number is chosen. My code for the kernel is below ....
org 0
bits 16
_start:
push cs
pop ds
mov si, msg
jmp BeginLoop
PrintLoop:
mov ah, 0x0E
int 0x10
BeginLoop:
mov al, [si]
inc si
or al, al
jz GameLoop
test al, al
jnz PrintLoop
GameLoop:
xor ax, ax
int 16h
mov ah, 0x0E
int 0x10
cmp ax, 0x5
jne GameWon
GameWon:
mov si, won
mov al, [si]
inc si
or al, al
jz GameLoop
test al, al
jnz PrintLoop
cli
hlt
jmp $-2
msg db 'Welcome To My Guessing Game: ', 10, 13, 'Pick A Number Between 1 - 10 ', 10, 13, 0
won db 'You Guessed The Correct Number!', 10, 13, 0
loss db 'You Guessed The Incorrect Number!' 10, 13
TIMES 512 - ($ - $$) db 0
Updated code that works
org 0
bits 16
_.start:
push cs
pop ds
mov si, msg
jmp Print
GameLoop:
mov ah, 00h
int 1ah
mov ax, dx
xor dx, dx
mov cx, 10
div cx
add dl, '0'
mov ah, 0x00
int 16h
mov ah, 0x0E
int 0x10
GameCondition:
mov si, won
cmp al, dl
je GameWon
jmp GameLost
GameLost:
mov si, loss
jmp Print
GameWon:
jmp Print
Print:
jmp BeginLoop
PrintLoop:
mov ah, 0x0E
int 0x10
BeginLoop:
mov al, [si]
inc si
or al, al
jz GameLoop
test al, al
jnz PrintLoop
ret
; -------------------
msg db 'Welcome To My Guessing Game: ', 10, 13, 'Pick A Number Between 0 - 9 ', 10, 13, 0
won db 'You Guessed The Correct Number!', 10, 13, 0
loss db 'You Guessed The Incorrect Number!', 10, 13, 0
times 512 - ($-$$) db 0