I am trying to create a switch statement in assembly; however, I seem to always get stuck on the first case, no matter what the value is:
SECTION .data
newLine db 0xA,0xD
NewLen equ $- newLine
nvalue dw 2 ; nth number for case
msg0 db 'a', 0xa
msg1 db 'b', 0xa
msg2 db 'c', 0xa
msg3 db 'd', 0xa
defaultMsg db 'e'
SECTION .text
global _start
_start:
mov eax, nvalue
cmp eax, 0
je case0
cmp eax, 1
je case1
cmp eax, 2
je case2
cmp eax, 3
je case3
case0:
mov edx, 2
mov eax, 4
mov ebx, 1
mov ecx, msg0
mov edx, 1
int 80h
call printNL
call quit
case1:
mov edx, 2
mov eax, 4
mov ebx, 1
mov ecx, msg1
mov edx, 1
int 80h
call printNL
call quit
case2:
mov edx, 2
mov eax, 4
mov ebx, 1
mov ecx, msg2
mov edx, 1
int 80h
call printNL
call quit
case3:
mov edx, 2
mov eax, 4
mov ebx, 1
mov ecx, msg3
mov edx, 1
int 80h
call printNL
call quit
mov edx, 2
mov eax, 4
mov ebx, 1
mov ecx, defaultMsg
mov edx, 1
int 80h
call printNL
call quit
printNL:
mov edx, NewLen
mov ecx, newLine
mov ebx, 1
mov eax, 4
int 80h
quit:
mov ebx, 0
mov eax, 1
int 80h
ret
The string output is always 'a' (case0 for when the nvalue variable is 0). Why is it doing this when nvalue is 2?