snq,
yes your code is an improvement for sure.
I wanted by my code just to give
idea about inner dependences in 16 bytes
table.
Firstly I tried to do it in math\logic way
but didn't see any reaction (might be my
explonation was akward one :) ?)
Then I tried to give sample code that used
what I meant.
And then reaction came :)
Might be coders better understand ideas through
code?
Thanks for taking part in the coding.
Posted on 2003-09-03 20:02:55 by The Svin
Thanks everyone, I merely christalized your ideas.
Svin, your point regarding and al, 4 is well taken. Therefore one
need only change mov al, dl to mov eax, edx.

snq, your variation of bitRAKE's last entry was what I used as a basis.
Posted on 2003-09-03 20:09:56 by Poimander
Incredible development Poimander. :)
Posted on 2003-09-03 21:36:49 by bitRAKE
Who would've thought.... 56 bytes! :grin:
C70 proc Flags


pop eax
xchg eax, [esp]

push esi
lea esi, [2*edx][OFFSET R70]
shl al, 7
jns short @F
jc @noE
mov al, 'E'
stosb

@noE:
movsw
jmp short @1

@@:
mov eax, edx
and al, 4
sub esi, eax
sub esi, eax
xor al, 'L'
movsb
stosb

@1:
pop esi
ret

R70 BYTE 'AXCXDXBX','SPBPSIDI'

C70 endp ; 40,16
Posted on 2003-09-04 04:31:21 by snq
55! :)
C71 proc Flags


pop eax
xchg eax, [esp]

push esi
lea esi, [2*edx][OFFSET R71]
rcr al, 1
jnc short @F
jp short @noE
mov al, 'E'
stosb

@noE:
movsw
jmp short @1

@@:
mov eax, edx
and al, 4
sub esi, eax
sub esi, eax
xor al, 'L'
movsb
stosb

@1:
pop esi
ret

R71 BYTE 'AXCXDXBX','SPBPSIDI'

C71 endp ; 39,16
Posted on 2003-09-04 05:36:13 by snq

Who would've thought.... 56 bytes

:)
If you ask me - I always had faith in your
bright head, and was sad to see when you were
about to give up
snq,
about last version(55 bytes):
Flags might have other then index 0,1 bits.
So rcr al,1 ..jp in not reliable.
Posted on 2003-09-04 08:33:01 by The Svin
Originally posted by The Svin Flags might have other then index 0,1 bits.
So rcr al,1 ..jp in not reliable.

Is too :)
I OR the flags with 11111100111111001111110011111100b to test and it works fine.. Makes sense :)
Let's see:


pop eax
xchg eax, [esp] ; CF=? AL=000000XYb <-- Flags in EAX
rcr al, 1 ; CF=Y AL=?000000Xb PF=X
So it doesn't matter what the other bits are set to because CF and PF will be the same..
Posted on 2003-09-04 10:14:02 by snq
al = 00000011b X = 1
rcr al,1 P=1
al = 00000101b X = 0
rcr al,1 P=1
Posted on 2003-09-04 13:21:50 by The Svin
Am I missing something here? PF equals the value in the least significant bit, right?
How would al=00000101b followed with rcl al,1 result in the least significant bit being set to 1?
As I said earlier most of the flags are quite new to me as I've never really used most of them but I tested the code and it works in every case, no matter what the values of the rest of the bits in the flags are.
Here's what I use to test, it runs the rCode2Str function for all possible registers..
.data?

thong db 1024 dup(?)

.code

start:

mov edi, offset thong

xor ecx, ecx
@loop:
mov edx, ecx
and edx, 7
mov eax, ecx
shr eax, 3
inc eax
; anything value here ending with 00b...
or eax, 11111111111111111111111111111100b
push eax
call C71

mov al, ' '
stosb

inc ecx
test cl, 7
jne @F
mov al, 0Dh
stosb
@@:
cmp ecx, 24
jnz short @loop

xor eax, eax
stosb

invoke MessageBox, 0, ADDR thong, 0, MB_TOPMOST
invoke ExitProcess, 0
Posted on 2003-09-04 16:21:51 by snq

PF equals the value in the least significant bit, right?

No.
PF is parity of 0s and 1s in low byte of result.
biside rcr doesn't change PF
Posted on 2003-09-04 17:12:02 by The Svin
How would al=00000101b followed with rcl al,1 result in the least significant bit being set to 1?


Actually rcl al, 1 rotates al 9 bits to the left via the CF flag as an extension. In other words the most significant bit is rotated through CF and CF on through to the least significant bit.

Well, in anycase, kudos to you snq, your 56 byte version does work.

Kudos to you bitRAKE, your solution had become a template on which further reduction was made possible.

Kudos to you Svin for the fruitful discussion.
Posted on 2003-09-04 19:45:41 by Poimander
Right :) I was a bit too quick when reading about the parity flag.. I was just bladdring around in my new intel books and came past this page where eflags is described and I read PF -> "lowest significant", my brain told me hmm shifting with 1 is small, I threw away the book, ran to my pc, edited the code and yess! it worked :) by coincidence hehe.. Thanks for clarifying!

Kudos to everyone, this is a great thread.. I've even learned a bit! :)

I'm still looking into squeezing out more bytes.. Perhaps this gives someone a bright idea:
C70 proc Flags


pop eax
xchg eax, [esp]

push esi
lea esi, [2*edx][OFFSET R70]
shl al, 7
jns short @F
jc @noE
mov al, 'E'
stosb

@noE:
movsb
lodsb
jmp short @1

@@:
mov eax, edx
and al, 4
sub esi, eax
sub esi, eax
xor al, 'L'
movsb
@1:
stosb

pop esi
ret

R70 BYTE 'AXCXDXBX','SPBPSIDI'

C70 endp ; 40,16
I guess regs named "EXA" or "XA" are not approved ;)
Posted on 2003-09-05 06:37:50 by snq
54 anyone? :grin:
Still working on it...
C72 proc Flags


pop eax
xchg eax, [esp]

push esi
mov esi, offset R72
shl al, 7
mov eax, edx
jns short @F
; jc short @noE
mov byte ptr [edi], 'E'
; inc edi
sbb edi, -1

;@noE:
shr eax, 1
mov al, byte ptr [esi+8+eax]
jmp short @1

@@:
and al, 4
sub esi, eax
xor al, 'L'

@1:
add esi, edx
movsb
stosb

pop esi
ret

R72 BYTE 'ACDBSBSD', 'XXPI'

C72 endp ; 43,12
Posted on 2003-09-05 11:59:46 by snq
Svin, I know you said don't change any registers other than EDI.. But what about changing EBP?
In that case there's another byte to strip here ;)
Posted on 2003-09-05 16:27:35 by snq
55 bytes, SLICK!
Posted on 2003-09-05 17:43:11 by Poimander

Svin, I know you said don't change any registers other than EDI.. But what about changing EBP?
In that case there's another byte to strip here ;)

Oh, no!
Posted on 2003-09-05 18:02:05 by The Svin
It turns out 55 bytes is achieveable with a 16-byte table, to wit (there are at least three other variations):


OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
C74 proc Flags
pop eax
xchg eax, [esp]

push esi
lea esi, [edx][OFFSET R74][8]
shl al, 7
js short @F

mov eax, edx
and al, 4
sub esi, eax
xor al, 'L'
jmp short @1

@@:
mov BYTE PTR [edi], 'E'
sbb edi, -1
mov al, BYTE PTR [esi-8]

@1:
movsb
stosb

pop esi
ret

R74 BYTE 'XXXXPPII','ACDBSBSD'

C74 endp ; 39,16
OPTION PROLOGUE:PROLOGUEDEF
OPTION EPILOGUE:EPILOGUEDEF
Posted on 2003-09-06 11:45:53 by Poimander
Very nice Poimander :)
How about reversing the 'XXXXPPII' table (make it IIPPXXXX) and put it in front of the proc. saves an X, because pop eax happens to be X :grin:
I didn't get it smaller (yet) tho but it might be possible...
Posted on 2003-09-07 05:52:05 by snq
That would save one byte, but then you would need two bytes for a jump. But again there may be an unforseen advantage to reversing the entire table.
Posted on 2003-09-07 14:37:53 by Poimander
No extra jump.. I meant like this:
R74 BYTE 'ACDBSBSD','IIPPXXX'

C74 proc Flags
pop eax
xchg eax, [esp]
.... etc
Posted on 2003-09-08 06:04:16 by snq