Another demo and reference utility.
The application show
1. real flag condition
2. math condition
3. opcode of jcc for condition
4. all mnemonics for the condition
(usualy there are several mnemonics for the same JCC opcode
for example JC,JNAE,JB - they are all the same)
For any choosen condition it shows all four infos for:
1. The condition itself
2. Reverse comparing (determination if X ? Y by cmp Y,X)
3. Not condition (for example if not X < Y; X >=Y)

For those who are experienced enough -
look at code.
There if absolutly no data about opcode and no referrence
what for some condition is reverse or negative condition.
All this determined in run time by logical operation.
I tried to explain the method in Algo section,
but nobody seemed to understand.
Now you can see it in working programm.

Inside zip RadAsm project.
KetiIO, I finally tried your shell you are in title.
Posted on 2002-04-13 21:32:52 by The Svin
I don't understand... what's the purpose of this program?
Posted on 2002-04-13 22:18:23 by iblis

I don't understand... what's the purpose of this program?


:)
Posted on 2002-04-13 22:24:17 by The Svin
Gee, thanks for clearing that up.
Posted on 2002-04-13 23:49:08 by iblis
I thought you were jocking.
OK I'll explain.
It is a tool to serve as a mantra for zen contemplation.
For those who are not feel themselves with JCC as fish in water.
They slowly press up and down arrow keys...
Looking in goupped JCC , flags conditions, math conditions.
And how they are changed with each keystroke in each group.
Until they are enlightened.
They also look look how opcode changed and in a few minute could
understand whole machine logic with jcc in bynary level.

I see you don't need all this ****. You are already know it all.
I see it in your question, it's funny I didn't see it in your code.
I'm jocking too.
Posted on 2002-04-14 01:11:12 by The Svin
That's what I initially suspected, but I was curious if there was more to it than what I saw.

To a newbie it would be a useful tool and I can see where it would be useful beyond that, good job. ;)
Posted on 2002-04-14 03:32:17 by iblis
Alex,

Congratulation, this is a good tool that will be useful to many people. It will help to produce better optimised code that uses the flag conditions in a more efficient way.

Regards,

hutch@movsd.com
Posted on 2002-04-14 03:42:47 by hutch--
Its a neat little program... Im forgetful of what i dont use alot so im sure it can have its momentary uses... (Can you make one for the PIC microprocessors :grin: ~ I find X>Y a pain in the arse to get right with their architecture)

Nice job Svin.
Posted on 2002-04-14 03:45:43 by NaN
Haven't checked this program yet but, by the way, for who may be interested (surely beginners), here is my JCC table I wrote when I just started to code in x86, I hope it can be useful to anybody:



;Branch:
;
;unsigned <= JBE JNA .. (C|Z)=1
;unsigned < JB JNAE JC .. C=1
;unsigned > JA JNBE .. (C|Z)=0
;unsigned >= JAE JNB JNC .. C=0

;signed <= JLE JNG .. ((S^O)|Z)=1
;signed < JL JNGE .. (S^O)=1
;signed > JG JNLE .. ((S^O)|Z)=0
;signed >= JGE JNL .. (S^O)=0

;equal JE JZ .. Z=1
;not equal JNE JNZ .. Z=0

;zero JZ JE .. Z=1
;not zero JNZ JNE .. Z=0

;sign JS .. S=1
;not sign JNS .. S=0

;carry JC .. C=1
;not carry JNC .. C=0

;overflow JO .. O=1
;not overflow JNO .. O=0

;parity (even) JP JPE .. P=1
;not parity (odd) JNP JPO .. P=0

;ecx=0 JECXZ .. ECX=0
;cx=0 JCXZ .. CX=0
Posted on 2002-04-14 04:22:49 by Maverick
Thanx, guys.
I was so buffled by iblis question that thought
might be I'd done something wrong having posted this :)
iblis,
yes there is some more about this app. It is in code of
how it was implemented.
But in order to understand this you need deep understanding
what is JCC and how it's done.
I tried to make move like in chess, where setting position of
figure might have several purposes: to attack some fields and
to defend someones.
Studing how the app works will help you to understand (among
other things) what is JCC in depth, and studing JCC by the same
app (but now in performence not in code) will help you understand
the tecnique used in it.

First thing it's absolutly real and show first nessesary things to understand,
1. there are a lot of mnemonics but a few real conditions.
2. processor doesn't care making JCC if X < Y of X > Y, it cares only for
current flags position.
Assume you in block of code at the end of some loop making
shr eax,1
dec ecx
and you want exit the loop if either last bit in eax before shifting was 1
or if ecx is now 0

dec doesn't change CF so you can
@@:
...
...
shr eax,1
dec ecx
jump again if CF = 1(after shr eax,1) or ZF = 1 (after dec ecx)
there is such opcode but mnemonics for the opcode tell absolutly nothing of the flags condition.
open the app
find condition CF = 1 or ZF = 1
look for menmonics for it:
it's JNA and JBE so in your code you can write
@@:
...
...
shr eax,1
dec ecx
jna @B

Does it make sence for you after shr eax,1 :)?
The mnemonics names have sence only if they are used in pare of cmp (or sub).
In other case they can in oposite trap you.
But cmp is just one of many instruction that can set flags, and many other instruction
doing in fact something usefull may be also used (even more than one in a raw)
for JCC.

3. The app reminds you in visible manner that there is ofter chance to determine
conditions in optional ways - and at once shows you all these ways with all nessesary
data to use them.

4. tttn - is unic ID for condition in JCC I tell about it a little bit later.
For now - use it just for thought provoking :)
Try to group what you see in different ways
(note for example that both signed and unsigned use ZF ; but for determine
wich is bigger unsign use just CF while sign comparing SF ans OV against each other -
try to understand why)
BTW - do you know how tecniqualy processor knows that overflow has happend?
(it can lead to very usefull notions)
Posted on 2002-04-14 05:03:53 by The Svin
Svin,

I am not a complete stranger to JCC. I know that conditional jumps are flag-based, and I am familiar with what the flags represent and which instructions modify them, and I have used them in some odd optimisation situations myself.

Here is why I was confused:
I am not accustomed to seeing "reference tools". All of the references I use are in text/help documents, and so when I ran your program and saw a dialog box with JCC info, it took me by surprise. I was expecting it to do something else - therein lies my confusion. That is why I asked if there was a purpose to your program. Perhaps I should have worded it better; I did not intend for it to come accross as insulting. I simply had not ever seen a reference app.

My apologies, and again very nice work! :D
Posted on 2002-04-14 06:11:50 by iblis
Explonation of JCC opcode. TTTN
Actaully there are just 8 conditions in jcc it coded in ttt field of opcode
binary by 3 bits field called TTT
000 001 010 011 100 101...
the other 8 conditions is NOT conditions of the first 8 and which condition the
current one is deterimed by 1 bit field called N
for example
0000 - is if OF = 1 0001 - is if NOT OF = 1 in other words if OF = 0

whole format for JCC opcode is
short:

0111TTTN:offset 8

let's stop on the short format for full unberstanding
short JCC is 2 bytes opcode, so you probably like it more than far one.
you see in the above TTTN for OF = 1 and OF = 0 so let's put them inside.
first tetrada of first byte always 0111 (7) next tetrada TTTN so we get for

OF=1 - 01110000 :offset 8
OF=0 - 01110001 :offset 8

We just coded in binary - as you see nothing to be afraid of.
now what is offset 8?
it is 8 bits(one byte) signed value. Sure you can see it is not address of anything -
it 's too small for it.
offset 8 is offset from next to the JCC command.
Let me demonstrate it very simple example:

01110000:00000000 ; hex: 7000h - jo to offset 0
mov eax,ebx ;addr mov eax,ebx - is offset 0,zero point
----------
01110001b, -2h ;jump onto itself

The format for short fist 7 then tttn then explained offset
So far the format is

00001111 1000TTTN:offset 32
hex 0F8(tttn):offset 32

one note you can make: if you jump more far then 127 bytes from zero point -
you get 6 bytes instruction instead of 2 :)

Check it with help of the app:
Look att opcode field (on the left of boxes)
and compare opcodes for condition and NOT condition - they always differ by 1 in
the only figure of opcode that is being changing.
It because the only difference of them in TTTN is N bit and 'cause it least bit
the difference in digit for TTTN is always 1.

It's very simple to code in binary as you see.
When you understand and systemize those bits :)
Posted on 2002-04-14 06:13:53 by The Svin
Yes the TTTN stuff I didn't know. I normally don't worry about opcodes, but it is a very interesting read. Thank you for explaining it. ;)
Posted on 2002-04-14 06:16:40 by iblis
You are wellcome.
So what do you know of how processor determines if there is
overflow?
Posted on 2002-04-14 06:21:19 by The Svin
I'm not sure what you mean. Do you just want me to tell you what the overflow flag is for?

Okay well the CPU sets the overflow flag if the result of the operation produces a value that overflows into the sign bit. Example, mov eax, 7FFFFFFFh; inc eax; would set the overflow flag. Edit for clarity: If two positives produce a negative, or if two negatives produce a positive.

As for how exactly the CPU does it internally... i.e. how the wiring and stuff is set up on the chip itself, I don't know.
Posted on 2002-04-14 06:48:02 by iblis
I am not accustomed to seeing "reference tools".

I understand what you mean.
And that what I have to say:
I'm sure that a lot of great ideas died just 'cause creators were not sure "if it suppose to be that way" and they tried to keep up with what they see, killing the best original thoughts they have.
I write anytime anything when I want it, and the way I want it,
the other users can always decide for themselves if they need it.

That's why I just love Hutch and Betov approach - they are both sure they do great thing - and do it without hesitation.
Had they keep there job relying only on others oppinion they would have never done what they've done. And people whould
never knew that there were some ideas.

At short as a beginner I was f*cking tyred looking at JCC reference every minute, opening and scrolling those docs, systemizing what I didn't understand yet etc. etc. I spent 100 more time they I actually needed to get used to jcc if had the apps in those days, it's easy to talk and systemize it when you know it already but when you don't know it - to get know you need to systemize it and to systemize it you need to get know it.

The same reason I wrote styles utility, you can find it all in Win32.hlp but slower, and while scrolling and searching, you may
lost your thoughts, get tyred etc. etc.
Posted on 2002-04-14 07:00:11 by The Svin
Do you just want me to tell you what the overflow flag is for?

No :)
I'm sure you know what OF is for.
And it's not actually about wiring.
I have ~ 25 different asm books in paper, not talking of electronic versions. And practically none of them explain how it works.
Actually it may lead to usefull notions and of course to deeper understanding of system.
Processor work with bits, it is the only way to know for him about anithing, and in case of flags he works with bits which produced under programmer control (not inner ones)
OF is set if carry TO sign bit and OUT from it (to CF) are not the same.
Posted on 2002-04-14 07:10:09 by The Svin
Your tool is a keeper. Belongs in MASM8.


It also a good avertisement for RadAsm. I have not even looked at RadAsm, but I will now.


Thanks for sharing with us.
Posted on 2002-04-14 08:00:55 by ThoughtCriminal
I forgot to write code to generate opcode for equal-not equal cases :)
Here is fixed version.
Let me know if anybody care for code. There were just 6 lines added to previous code.
Posted on 2002-04-21 15:09:52 by The Svin
Hi The Svin

Please post the code as I would like to include it in RadASM projects on my next release. Besides beeing a useful tool for beginners it also shows an exelent and efficent coding style.

KetilO
Posted on 2002-04-24 19:34:36 by KetilO