samedi 29 août 2020

How to use AND to check condition in Assembly language?

I'm trying to check even odd in assembly, using a 32-bit NASM, the code is working fine for odd numbers, but for even numbers it is giving output

Even
Odd
Odd

My code is,

section .data
    even db "Even", 0xa;
    odd db "Odd", 0xa;
    lene equ $-even;
    leno equ $-odd;

section .text
    global _start;

_start:
    mov ax, 0x4;
    and ax, 1;
    jz evenn;
    jnz oddd;
    jmp outprog;

evenn:
    mov eax, 4;
    mov ebx, 1;
    mov ecx, even;
    mov edx, lene;
    int 0x80;

oddd:
    mov eax, 4;
    mov ebx, 1;
    mov ecx, odd;
    mov edx, leno;
    int 0x80;

outprog:
    mov eax, 1;
    int 0x80;

Aucun commentaire:

Enregistrer un commentaire