Author Topic: Odd or even number  (Read 7576 times)

Offline wezzazzew

  • Jr. Member
  • *
  • Posts: 2
Odd or even number
« on: December 27, 2015, 11:56:58 PM »
For my project, i'm trying to make a program that can tell if a number is odd or even
Code: [Select]
global _start

section .data
org 100h
message   dd  13, "Enter a number", 13, 10, '$'
even_msg  dd  13, "Even Number! $", 13, 10, '$'
odd_msg   dd  13, "Odd Number! $", 13, 10, '$'

section .text


_start:

mov ah, 09h
mov dx, message
int 21h
mov ah, 01h
int 21h
and al, 1
je even
jne odd

odd:
mov ah,09h
mov dx, odd_msg
int 21h
jmp exit

even:
mov ah,09h
mov dx, even_msg
int 21h
jmp exit

exit:
mov ah,00h
int 16h
ret


when i use this code, it only accepts numbers from 0 to 9, because ii used the funtion 01h in int 21h, but when i chang it to the function 0Ah in int 21h, even tho it accepts all numbers no matter how many digits are in it, it always says that it's an even number!
i'm fairly new to nasm, i would appreciate some help, thank you!

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: Odd or even number
« Reply #1 on: January 01, 2016, 01:38:27 PM »
Read last bit of the number and the last bit indicates if the number is odd or even.
Encryptor256's Investigation \ Research Department.