News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Odd or Even

Started by herge, October 13, 2008, 11:35:59 AM

Previous topic - Next topic

herge

 Hi DommyD:

See reply #11 ( Page 1)


.code
isOdd proc
push         ebx
rcr            ebx, 1
pop          ebx
ret
isOdd endp



Regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

jj2007

Quote from: NightWare on October 14, 2008, 10:05:24 PM

Quote from: MichaelW on October 14, 2008, 08:27:29 AM
Considering that this is the Laboratory, you should create a speed-optimized version that displays only the value of the last bit. It would still run slow on some systems, but for most it should be much faster.

:lol i have one !!! here => and eax,1
beside bogdan has said it's difficult to do it faster !

NightWare, you should carefully read zooba's post in order to understand what Michael means with "systems" :lol

jdoe



The kind of humour this topic is going throught made realize that we should free our hidden nerds inside... or die   :green2




DoomyD

hi herge,
rol ebx,31
test ebx,ebx
js _odd_
:U

Roger

For a really fast method eliminate the branch


               or ebx, 1
               print  "ebx is odd ", 0Dh, 0Ah



Regards Roger

sinsi

Quote from: Roger on October 15, 2008, 11:13:14 AM
For a really fast method eliminate the branch


               or ebx, 1
               print  "ebx is odd ", 0Dh, 0Ah



Regards Roger
:bg man, that is zen-like

  print "ebx is either odd or even", 0Dh, 0Ah
Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007

Quote from: Roger on October 15, 2008, 11:13:14 AM
For a really fast method eliminate the branch


               or ebx, 1
               print  "ebx is odd ", 0Dh, 0Ah



Regards Roger

Fast but not flexible enough!
     .if NeedOdd
               or ebx, 1
               print  "ebx is odd ", 0Dh, 0Ah
     .elseif NeedEven
               and ebx, 1111111111111110b
               print  "ebx is even ", 0Dh, 0Ah
     .else
               trash ebx
               print  "ebx is NaN ", 0Dh, 0Ah
     .endif

hutch--

Someone may like these two simple macros.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    jevn MACRO value, label
      mov eax, value
      and eax, 00000000000000000000000000000001b
      jz label
    ENDM

    jodd MACRO value, label
      mov eax, value
      and eax, 00000000000000000000000000000001b
      jnz label
    ENDM

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    mov eax, 99999992
    jevn eax, nxt

    print str$(eax)," odd",13,10
    jmp quit1

  nxt:
    print str$(eax)," even",13,10

  quit1:

    mov eax, 12345
    jodd eax, nxt1

    print str$(eax)," even",13,10
    jmp quit2

  nxt1:
    print str$(eax)," odd",13,10

  quit2:

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

DoomyD

#38
I think I've got a winner :green2push ebx
print "is ebx odd? let's find out =D",13,10
getkey
pop ebx
and ebx,1
div ebx
print "I guess it is =]",13,10

jj2007

Quote from: hutch-- on October 15, 2008, 12:47:51 PM
Someone may like these two simple macros.


    jevn MACRO value, label
      mov eax, value
      and eax, 00000000000000000000000000000001b
      jz label
    ENDM


Hutch, oh dear, highly destructive code!!! You are not scared of the CPU police??

Here are safe alternatives:

jevn MACRO value, label
      test value, 1
      jz label
ENDM

jodd MACRO value, label
      test value, 1
      jnz label
ENDM

zooba

print "ebx may be odd or even, but when you check the cat will be dead."

Now here's a nerdiness test. If you laugh at that... I've got bad news for you  :toothy

hutch--

 :bg

> Hutch, oh dear, highly destructive code!!! You are not scared of the CPU police??

Yep, this is deadly srerious stuff.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Mark Jones

I find it ODD that anyone is EVEN working on code for this... :bg
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

herge

 Hi zooba:

Do you mean Schrödinger's cat?
This is assembler ? not  quantum
mechanics.


int main(int)
    {
    cout << "\t\t\tThe Fibonacci Series\n";
    int X = 0;
    for ( int i = 0; i < 7; i++ ) { /* row*/
     for ( int j = 0; j < 6; j++, X++ ) { /* column */
      if ( ( X & 1 ) == 1 ) cout << left; /* Odd */
       else cout << right; /* Even */
      cout << setw(10) << FibX(X) << " ";
     }
      if ( i == 6 ) break; /* last row ? : Exit */
      cout << endl;
    }
    getch(); // Pause Wait for Keyboard



The Fibonacci Series
         1 1                   2 3                   5 8         
        13 21                 34 55                 89 144       
       233 377               610 987              1597 2584       
      4181 6765            10946 17711           28657 46368     
     75025 121393         196418 317811         514229 832040     
   1346269 2178309       3524578 5702887       9227465 14930352   
  24157817 39088169     63245986 102334155   165580141 267914296 


Regards herge
// Herge born  Brussels, Belgium May 22, 1907
// Died March 3, 1983
// Cartoonist of Tintin and Snowy

Roger

Quote from: jdoe on October 15, 2008, 06:45:53 AM
The kind of humour this topic is going throught made realize that we should free our hidden nerds inside... or die :

Good thing Schrödinger's cat wasn't a nerd or he, Schrödinger, would have been stuck.
Regards Roger