Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12141

NASM - Converting User Input To Integers

$
0
0

I want the user input to be compared with the "num" variable. it of course doesn't work as intended. when I debug it with gdb and observe the value it is something random like 0xa3404856 and I don't understand why.this is the code:

section .dataenter_msg                   DB      "Enter Your Guess : ", 0enter_msg_len               equ     $-enter_msginvalid_input_msg           DB      "Invalid Input !!!", 0x0a, 0invalid_input_msg_len       equ     $-invalid_input_msginput_out_of_range          DB      "Input Out Of Range !!!", 0x0a, 0input_out_of_range_len      equ     $-input_out_of_rangetoo_high_msg                DB      "Your Guess Is Too High !!!", 0x0a, 0too_high_msg_len            equ     $-too_high_msgtoo_low_msg                 DB      "Your Guess Is Too Low !!!", 0x0a, 0too_low_msg_len             equ     $-too_low_msgwin_msg_1                   DB      "You Won ! The Number Was ", 0win_msg_1_len               equ     $-win_msg_1win_msg_2                   DB      " And You Guessed It In ", 0win_msg_2_len               equ     $-win_msg_2win_msg_3                   DB      " Guesses !", 0x0a, 0win_msg_3_len               equ     $-win_msg_3num                         equ         64section .bss    guess resb 32    guesses resb 8section .textglobal _start_start:    %macro print 2        mov eax, 4        mov ebx, 1        mov ecx, %1        mov edx, %2        int 0x80    %endmacro    %macro input 2        mov eax, 3        mov ebx, 2        mov ecx, %1        mov edx, %2        int 0x80    %endmacro    %macro exit 0        mov eax, 1        mov ebx, 0        int 0x80    %endmacro    %macro compare 2        mov eax, %1        mov ebx, %2        cmp eax, ebx        jg higher        jl lower        je win    %endmacro    print enter_msg, enter_msg_len    input guess, 32     mov ebx, num    mov eax, [guess]    cmp eax, ebx    jl lower    jg higher    jz winlower:    print too_low_msg, too_low_msg_len    jmp _starthigher:    print too_high_msg, too_high_msg_len    jmp _startwin:    print win_msg_1, win_msg_1_len    print num, 2    print win_msg_2, win_msg_2_len    print guesses, 4    print win_msg_3, win_msg_3_len    jmp endend:    exit

The thing that makes me more confused is why the code above doesn't work but this code works :

print enter_msg, enter_msg_leninput num1, 8print enter_msg, enter_msg_leninput num2, 8mov eax, [num1]mov ebx, [num2]cmp eax, ebxjg higherjl lowerje win

Viewing all articles
Browse latest Browse all 12141

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>