I am very new to assembly and trying to create a very simple script to practice using stdout, stdin and cmp, I ran into the problem of my script not working when using cmp.
I have tried asking chatgpt but as you all know, it is not the most reliable tool when trying to fix errors in one´s code and I have tried some stuff that I saw online but nothing seems to work and as I am not very familiar with assembly’s syntax, I do not see any chance of me being able to fix the error on my own.
My code:
section .text
global _start
_start:
;print question using stdout
mov eax, 4
mov ebx, 1
mov ecx, question
mov edx, len_question
int 80h
;get answer using stdin
mov eax, 3
mov ebx, 1
mov ecx, input
mov edx, 1
int 80h
;compare answer to right answer
mov eax, byte input
mov ebx, byte yes
cmp eax, ebx
je _right ;jump to right if right
cmp ax, bx
jne _wrong ;jump to wrong if wrong
jmp _badinput ;jump to badinput if bad input
_right:
;print right message
mov eax, 4
mov ebx, 1
mov ecx, msg_right
mov edx, len_msg_right
int 80h
jmp _end ;jump to end
_wrong:
;print message for wrong answer
mov eax, 4
mov ebx, 1
mov ecx, msg_wrong
mov edx, len_msg_wrong
int 80h
jmp _end ;jump to end
_badinput:
;print message for bad input
mov eax, 4
mov ebx, 1
mov ecx, msg_badinput
mov edx, len_msg_badinput
int 80h
jmp _end ;jump to end
_end:
;end the program
mov eax, 1
mov ebx, 0
int 0x80
section .data
question db 'Is the world round?',0xa
msg_right db 'That´s right!'
msg_wrong db 'That´s wrong'
msg_badinput db 'Bad input! Choose yes (y) or no (n)!'
yes db 'y'
no db 'n'
len_question equ $ - question
len_msg_right equ $ - msg_right
len_msg_wrong equ $ - msg_wrong
len_msg_badinput equ $ - msg_badinput
section .bss
input resb 1
The error message is:
main.asm:17: error: mismatch in operand sizes
main.asm:18: error: mismatch in operand sizes
main.asm:65: error: symbol `msg' not defined