News:

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

Maybe I'm missing the obvious but...

Started by oex, November 15, 2009, 01:12:34 PM

Previous topic - Next topic

oex

bin2byte_ex returns -1 for 00000000 and 1 for 00000001?

Just what to know what I have to enter to return 0

I'm assuming I can just:
   cmp eax, -1
   jne NotMinusOne
   mov al, 0
NotMinusOne:

Result to return true result without issues like al=255

Then on second reflection I realise an error in input also returns -1 so to be on the safe side maybe szCmp first for "00000000" instead?
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

jj2007

A complete example helps to get answers. Here is one:

include \masm32\include\masm32rt.inc

.code
start:
invoke bin2byte_ex, chr$("00000000")
print str$(eax), 13, 10
invoke bin2byte_ex, chr$("11111111")
print str$(eax), 13, 10
inkey "Press any key"
exit
end start


The behaviour is indeed not intuitive. Your workaround seems Ok, as it returns 255 for 11111111.
Here is a slightly shorter version:

   cmp eax, -1
   jne NotMinusOne
   inc eax
NotMinusOne:

dedndave

how about...

        cmp     eax,0
        adc     eax,0

same length as Jochen's, i think - but no branch

looking at the code - that thing seems a little silly to me - lol
but, the -1 is returned as an error

bin2byte_ex proc lpword:DWORD

    mov eax, [esp+4]
   
    cmp BYTE PTR [eax+0], '0'
    jne lbl0
    cmp BYTE PTR [eax+1], '0'
    jne lbl1
    cmp BYTE PTR [eax+2], '0'
    jne lbl2
    cmp BYTE PTR [eax+3], '0'
    jne lbl3
    cmp BYTE PTR [eax+4], '0'
    jne lbl4
    cmp BYTE PTR [eax+5], '0'
    jne lbl5
    cmp BYTE PTR [eax+6], '0'
    jne lbl6
    cmp BYTE PTR [eax+7], '0'
    jne lbl7                                    ;i guess this instruction is for aesthetics
  lbl7:
    cmp BYTE PTR [eax+7], '1'
    jne notfound
    cmp BYTE PTR [eax+8], 0
    jne notfound
    mov eax, 1
    ret 4
  lbl6:
    cmp BYTE PTR [eax+6], '1'
.
.
.
  notfound:
    mov eax, -1
    ret 4

i think i would write my own code

oex

 :lol a 'bit' unintuitive yep, 'not' quite what I expected :lol, but yeah I have written my own code also now so may use that :) ty for your help on that
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

Jochen caught me on a mistake - lol
cmp eax,0; adc eax,0 does not work
but this should.....

        sub     al,ah

well - at least the contents of AL are right - lol
if you want the rest of EAX to be right, continue with....

        and     eax,0FFh

5 bytes - no branch

oex

Ty I wouldnt have known  :U... I esp like the no branching stuff, havent explored this much yet :)
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

jj2007


oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

yes - Jochen has on his "Men At Work" t-shirt   :bg

jj2007

Quote from: dedndave on November 16, 2009, 11:30:49 PM
yes - Jochen has on his "Men At Work" t-shirt   :bg

Hey, you are kidding. It's 01:16 a.m. here, and I just wanted to drink a cup of tea to find some sleep. But then qWord showed up... I just hope Lingo is not around, otherwise it might be a sleepless night :bg

oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

dedndave

lol - in Italy, they must sleep late
haven't seen much of Lingo lately - too bad - i was hoping to learn stuff from him
but, Drizz may pop in with a super-fast routine   :U

oex

I take it 01010101010101010101010101010101y 32y is 8b equiv? Are there any others in the series?
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

jj2007

Quote from: oex on November 17, 2009, 01:40:12 PM
I take it 01010101010101010101010101010101y 32y is 8b equiv? Are there any others in the series?

Numbers ending with y or b are binary coded. 01010101010101010101010101010101y is 55555555h or 1431655765 decimal.

oex

We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv