Question

i am trying to get input from the user and then i would like to output some text depending on what the user put in.

my issue is for some reason it always thinks it is A and i dont know why. you can find my code below:

            bits 16
            org 0x100
            jmp main
message:    db 'Please enter a A or B:',0ah,0dh,'$'
character:  db 1
outp_a:     db 'IT IS A',0ah,0dh,'$'
outp_b:     db 'IT IS B',0ah,0dh,'$'
finish      db 'good bye',0ah,0dh,'$'

clearscreen:
            mov dx, 10 
            mov bh, 0
            mov ah, 2
            int 10h
            mov cx, 2000 
            mov bh, 0
            mov bl, 01Eh 
            mov al, 20h 
            mov ah, 09h
            int 10h
            ret

disply:     
            mov ah,09h
            int 21h
            ret

get_input:  mov ah,01h
            int 21h
            ret

input_a:    mov dx,outp_a
            call disply
            ret
input_b:    mov dx,outp_b
            call disply
            ret

compare:    mov cl,'A'
            cmp [character],cl
            JAE input_a
            mov cl,'B'
            cmp [character],cl
            JAE input_b 
            ret

main:       call clearscreen
            mov dx,message
            call disply
            call get_input
            mov [character],ax
            call compare
            mov dx,finish
            call disply
            int 20h
Was it helpful?

Solution

JAE means jump if above or equal, that is to say when you compare to 'A', the jump will be taken for any character with an encoding greater or equal to 'A'.

What you want instead is JE, which means jump only if the values are exactly the same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top