user1306751
user1306751

Reputation: 11

x86 NASM Assembly - Comparing the input with integer values

I am trying to compare an input data with a integer value

here the basic code I am using

section .bss
    input resb 2

section .text
global _start
_start:
    mov eax, 3
    mov ebx, 1
    mov ecx, input
    mov edx, 5
    int 0x80
    mov eax, [input]
    cmp eax, 20 // This is what I cannot get to work, it never compares it to 20 even if i enter 20 as input
    je next

All I really want to know is how to do the If statement in Assembly to compare input with an integer.

I would really apprecaite any help with this, thank you.

Upvotes: 1

Views: 3847

Answers (2)

Suraj Kadam
Suraj Kadam

Reputation: 1

Try using this code...

section .bss
    input resb 2

section .text
global _start
_start:
    mov eax, 3
    mov ebx, 1
    mov ecx, input
    mov edx, 5
    int 0x80
    mov eax, dword[input];dword is require for double word size
    cmp eax, 20 
    je next

Upvotes: 0

user149341
user149341

Reputation:

You are comparing eax (the first byte of input) with the integer20`. This is the DC4 control character, which is almost certainly not your input.

If you want to compare to the number 20, then you will need to convert input to a number first (and accept more than one character of input).

Upvotes: 2

Related Questions