mardi 30 novembre 2021

Why the answer always go greater in assembly [duplicate]

This is the code that I have I am trying to get a number input and check whether it is greater or smaller than 4. For some reason when I input 3, the code output "Greater". I checked the input, when I input 0 and minus 1, the result is '/', so I can sure if I input number 0 - 9, it must be in range 48 - 57(DEC).

section .data
    ques db "Enter a number:", 10
    queslen equ $- ques

    gt db "Greater", 10
    gtlen equ $- gt

    lt db "Smaller", 10
    ltlen equ $- lt

section .bss
    input resb 2

section .text
    global  _start

_start:
    call    _printQues
    call    _getInput
    mov rax, [input]
    cmp rax, '4'
    jg  _greater

    mov rax, 1
    mov rdi, 1
    mov rsi, lt
    mov rdx, ltlen
    syscall
    jmp _exit

_printQues:
    mov rax, 1
    mov rdi, 1
    mov rsi, ques
    mov rdx, queslen
    syscall
    ret

_getInput:
    mov rax, 0
    mov rdi, 0
    mov rsi, input
    mov rdx, 2
    syscall
    ret

_greater:
    mov rax, 1
    mov rdi, 1
    mov rsi, gt
    mov rdx, gtlen
    syscall
    jmp _exit

_exit:
    mov rax, 60
    mov rdi, 0
    syscall

Aucun commentaire:

Enregistrer un commentaire