News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

I got some question

Started by allen, February 20, 2014, 08:55:22 PM

Previous topic - Next topic

allen

i got a question about how to display odd even and i was wondering if you help me out

this i want one it to display

1 is odd
2 is even
3 is odd
4 is even
5 is odd

but my output is this
1 is odd 2 is even 3 is odd 4 is even 5 is odd

here my code

.386
.model flat, stdcall
option casemap :none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib


.data


            Message1 db "Please Enter the first number: ", 0
            Message2 db "Please Enter the second number : ", 0
Message3 db "Please Enter the Third number : ", 0
Message4 db "Please Enter the Four number : ", 0
Message5 db "Please Enter the Fifth number : ", 0
            Message6 db " EVEN ",0
            Message7 db " ODD  ",0
            Message8 db 20,0
            Message9 db 40,40,0

.data?

      Number1 dd 2 dup(?)
            Number2 dd 2 dup(?)
Number3 dd 2 dup(?)
Number4 dd 2 dup(?)
Number5 dd 2 dup(?)



.code
start:

        invoke StdOut, addr Message1
        invoke StdIn, addr Number1, 100
        invoke StripLF, addr Number1
        invoke StdOut, addr Message2
        invoke StdIn, addr Number2, 100
        invoke StripLF, addr Number2
        invoke StdOut, addr Message3
        invoke StdIn, addr Number3, 100
        invoke StripLF, addr Number3
        invoke StdOut, addr Message4
        invoke StdIn, addr Number4, 100
        invoke StripLF, addr Number4
        invoke StdOut, addr Message5
        invoke StdIn, addr Number5, 100
        invoke StripLF, addr Number
       
        invoke StdOut, addr Message8
        invoke StdOut, addr Message8

       
       
    invoke atodw, addr Number1
    mov ecx, eax
    mov ebx, 2
    mov eax,ecx
    idiv ebx
    cmp edx, 0
    jne ODD1
   
    invoke StdOut, addr Number1
    invoke StdOut, addr Message6
   
    jmp NUM2
   
ODD1:
   
    invoke StdOut, addr Number1
    invoke StdOut, addr Message7
     
NUM2:
    invoke atodw, addr Number2
    mov ecx, eax
    mov ebx, 2
    mov eax,ecx
    idiv ebx
    cmp edx, 0
    jne ODD2
   
    invoke StdOut, addr Number2
    invoke StdOut, addr Message6
   
    jmp NUM3
   
ODD2:
   
    invoke StdOut, addr Number2
    invoke StdOut, addr Message7
   
NUM3:
    invoke atodw, addr Number3
    mov ecx, eax
    mov ebx, 2
    mov eax,ecx
    idiv ebx
    cmp edx, 0
    jne ODD3
    invoke StdOut, addr Number3
    invoke StdOut, addr Message6
    jmp NUM4

ODD3:
 
    invoke StdOut, addr Number3
    invoke StdOut, addr Message7
   
   
NUM4:
    invoke atodw, addr Number4
    mov ecx, eax
    mov ebx, 2
    mov eax,ecx
    idiv ebx
    cmp edx, 0
    jne ODD4
    invoke StdOut, addr Number4
    invoke StdOut, addr Message6
    jmp NUM5
ODD4: 
    invoke StdOut, addr Number4
    invoke StdOut, addr Message7
   
NUM5:
    invoke atodw, addr Number5
    mov ecx, eax
    mov ebx, 2
    mov eax,ecx
    idiv ebx
    cmp edx, 0
    jne ODD5
   
    invoke StdOut, addr Number5
    invoke StdOut, addr Message6
   
    jmp EXT
ODD5:
   
    invoke StdOut, addr Number5
    invoke StdOut, addr Message7
   

EXT:




    invoke ExitProcess,0



End start











jj2007

            Message6 db " EVEN", 13, 10, 0
            Message7 db " ODD", 13, 10, 0

MichaelW

Where 13 = carriage return (moves text cursor to start of current line) and 10 = line feed (moves text cursor to next line).
Well Microsoft, here's another nice mess you've gotten us into.

K_F

Not sure on the speed factor, but after atodw you could always test Bit-1 or Rotate right/shiftR eax right 1x into the carry flag... to check for odd/even
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'