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 Roger:

I suspect the answer is going to be yes!
When it will be yes I don't knew.
They are trying to build computers that
can be both on and off at the same time.

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

hutch--

JJ,

I ask the question on the example for a reason.


    ; hex 7Bh
    ; bin 1111011
    ; dec 123


They are all the same number but in different radix. Decimal is easy but for a vast number of people hex and binary are not.

The idea of a general purpose macro is that it IS general purpose, as soon as you make exceptions you may as well code it manually.

Try this one.

  ; --------------------

    mov value, 3
    mov ecx, 2

    mov eax, value
    test eax, 00000000000000000000000000000001b       ; test trailing bit.
    cmovnz eax, ecx

    print str$(eax),13,10

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

jj2007

Quote from: hutch-- on October 19, 2008, 07:19:54 AM
Decimal is easy but for a vast number of people hex and binary are not.

You are right. Remember I always take the side of the noobs, so a cute simple little macro may really be the best solution. What about this one?

include \masm32\include\masm32rt.inc

odd MACRO value
  mov eax, value
  and eax, 1
  EXITM <eax>
ENDM

.code
start:
.if odd(123)
print "123 is odd"
.else
print "Hooray, I just won the Nobel Prize in mathematics!"
.endif
getkey
exit

end start

hutch--

Would I really get the Nobel prize in mathematics ?  :bg

It looks OK but I would still use the binary notation instead of 1 so that the viewer knew what was being done with the AND/TEST mask.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Roger

Hi Hutch,

Quote from: hutch-- on October 19, 2008, 07:19:54 AM
They are all the same number but in different radix. Decimal is easy but for a vast number of people hex and binary are not.

What you need is a 4-function calculator that works in any radix and converts between them.

Regards Roger

hutch--

Roger,

Windows CALC comes pretty close.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Farabi

Quote from: hutch-- on October 19, 2008, 12:57:54 PM
Would I really get the Nobel prize in mathematics ?  :bg

...

:bg You will, so do I because I help clean your cloth and serve you a coffee.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

Mark Jones

Quote from: Roger on October 19, 2008, 11:58:40 PM
What you need is a 4-function calculator that works in any radix and converts between them.

What? All assembly programmers don't think in binary? :wink
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

herge

 Hi All:

So the end result is:

    if ( ( j & 1 ) == 1 ) cout << left;
    else cout << right;


The original was:


   if ( j % 2 == 0 ) cout << right;
   else cout << left;



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

Farabi

Quote from: herge on October 29, 2008, 10:44:51 PM
Hi All:

So the end result is:

    if ( ( j & 1 ) == 1 ) cout << left;
    else cout << right;


The original was:


   if ( j % 2 == 0 ) cout << right;
   else cout << left;



Regards herge
Hi herge, Im curious about the speed and the code size generated by C compared to asm.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

sinsi

Hi herge:

Wasn't there something on the daily wtf about this?
Light travels faster than sound, that's why some people seem bright until you hear them.

herge

 Hi Farabi:


10/30/2008  10:59 AM               874 fib.cpp
10/30/2008  10:59 AM           142,848 fib.exe
10/30/2008  10:59 AM             9,606 fib.obj
10/30/2008  10:59 AM           393,216 fib.tds

10/31/2008  03:18 AM             1,768 fib.asm
10/21/2008  03:55 PM             3,382 fib.exe
10/21/2008  03:55 PM           288,289 fib.obj
10/21/2008  03:55 PM           353,280 fib.pdb


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