Hi all...

Is it possible to use MASM's High Level Syntax (.IF nr1 > nr2 ) to compare Floating Point data?

I tried to do it with jumps and compares... but that's a real pain to do.


TIA,

Locu
Posted on 2002-02-13 06:20:12 by Locu
1. No you can not
2. You can not it with cmp jcc either.
3. Why do you need to use machine language if couple
esiest machine opcode is real pain to you?
Use VB.
Posted on 2002-02-13 08:01:20 by The Svin
Huuuh....

Correction... FCompares,fstsw ax, sahf,(je,ja,jb,etc).

It's a pain to do because:
To convert a complex algorithm to asm this way, takes allot of time... and it isn't easy to make it readable for someone else.

And if it's so weird to use MASM's HLS... why does allmost every piece of MASM-code that I've seen contain some HLS.





BBye,

Locu
Posted on 2002-02-13 09:06:59 by Locu
There are a set of macros on XCalibre's
web site that handle all the details for you.

Look here:http://scali.eu.org/~xcalibre/Computers/SourceVault.html

The readablity of ASM is based on your comprehesion level of the language coupled with the complexity of the code.
Posted on 2002-02-13 10:02:48 by bitRAKE
It's inderect comparesion.
As to what you've seen - it's clear that you've seen code of
those who can't create effective control blocks.
Those more than ones who can.
So it's sign of weekness and nothing more.
First you use HLL statment, then use tools wich writes code for
you etc.
My question was simple, why do you need write machine language if all you are trying to do is to avoid writing it?
Here is contradiction.
It's OKAY if somebody just can not do something yet - that's
how he comes to learn something.
But if you just do not want to learn how to handle machine code - why you use machine language?
You like how compilers do it for you for HLL staments?
It's OKAY.
I must say that masm one of the worst compilers from optimizing
HLL control code. Any VC could do better.
MASM for writing machine code, not for code generating from HLL.
Posted on 2002-02-13 10:29:04 by The Svin
The Svin,

I didn't say that I didn't knew how to write the code to compare FP data... I said it was a pain to do it for complex algo's.

And I'll bet that you can't produce a very complex FP-algortihm coded in plain ASM that is readable to a mathematician that has no ASM-knowledge.



Greetings to ya all From the lowlands,

Locu
Posted on 2002-02-13 16:39:22 by Locu
Afternoon, Locu.

The only solution would be to create the macros yourself.
It'd be quite useful, though...


.FIF fpRoll > fpHalfPI
; blah blah
.FELSE
; blah blah
.FENDIF


cheers,
Scronty
Posted on 2002-02-13 17:02:27 by Scronty
Svin,

You are right about the HLL statements : I actually avoid them as much I can (I conserve some of them for readability), but they are useful to understand the basics of some things in assembly... they can concentrate on some other code and not the boring one they will learn easier after some more experience (I don't speak specifically about Locu here)... what I say is the HLL statements can help the *beginner*... and once he's experienced enough... he can avoid them and code by comparison and branching i.e once he has gotten used to some other things in assembly...

You are for sure an assembly purist and very experienced in this area but before a person can run, he has to learn how to walk...
Posted on 2002-02-14 01:23:02 by JCP
didn't say that I didn't knew how to write the code to compare FP data... I said it was a pain to do it for complex algo's.

The Svins point here I believe is that theres little point using the HLL statements in a complex algo. They'll slow things down and defeat the purpose of using assembly

And I'll bet that you can't produce a very complex FP-algortihm coded in plain ASM that is readable to a mathematician that has no ASM-knowledge.

I doubt you could code anything complex in asm which would be readable to someone who knows no assembly. But if you're going to destroy the speed of you algo just to make it readable, then why bother use asm at all. Badly written asm can be worse than a compiler.

In fact what you've just said is equlivant to "I bet you can't write an essay in plain English which is legible to someone who knows no English." :grin:

If you want to make it legible use comments. :)
Posted on 2002-02-14 02:44:25 by Eóin

If you want to make it legible use comments. :)


I thought this was so profound I thought it should be said again :) I've very rarely seen code that has "too many comments"...

If your willing to put time into the comments then there isn't any reason why someone shouldn't follow even the most complicated of algorithms...

Also liked the analogy Eoin... :)

Sliver
Posted on 2002-02-14 03:18:34 by Sliver
To Locu:
I haven't meant to hurt you filling, and if did - I'm sorry.
I'm sorry but I do not appolagize, 'cause my words were direct and honest and all I wished - to help you.
You don't want such a help - I can do nothing.
You may proceed your way to nowhere.
To Readiosys:
Learning basic opcode + JCC + Flags is right start point.
It is alphabet, if you don't know it - you know nothing.
You should start learning asm without input and output
but with debuger, creating simple constructions and observing
what happens in CPU.

The other thing is that it is not your fault - all recent asm books
is another example of mass stupidity, description of flags and jcc
write the worst possible way.
Almost no step by step training of control block creation.
The result is many programmers treat HLL logic of block controling
as the only possible and the only existing.
What I see in many programms is not control blocks based on
machine logic but translation of HLL control blocks logic to machine
the worst possible way.

A week of proper and concentrated training is enough to learn
basics of flags and JCC.
This training will reward you with clear understanding, selfconfidence and good results in your code every next day after
it. Getting better in will reflect ALL YOUR CODE.

I say it again - IT IS ALPHABET!
2. Cmp and JCC is not the only way to make control block
3. Cmp and JCC produced by MASM with .IF .ELSE .WHILE are
the worst possible cmp jcc.

4. For start to begin you need to know just 4 flags! ZF OF SF CF
Don't say me, please, that it is super hard job.

JCCs needed to know as determination of value comp after
sub (cmp) just 9!
CF=0 & ZF=0		JA

JNBE
---------------------------------------------
CF=0 JAE
JNB
JNC
---------------------------------------------
CF=1 JB
JNAE
JC
---------------------------------------------
CF=1 || ZF =1 JBE
JNA
---------------------------------------------
ZF=1 JE
JZ
---------------------------------------------
ZF=0 and SF=OF JG
JNLE
---------------------------------------------
SF<>OF JNGE
JL
---------------------------------------------
ZF=1 or SF<>OF JLE
JNG
---------------------------------------------
ZF=0 JNE
JNZ
---------------------------------------------

All this 9 JCC can be devided into 3 groups
for signed and unsigned and common (check if equal) you can firstly learn one group then next.

4 Unsigned:
CF=0 & ZF=0		JA

JNBE
---------------------------------------------
CF=0 JAE
JNB
JNC
---------------------------------------------
CF=1 JB
JNAE
JC
---------------------------------------------
CF=1 || ZF =1 JBE
JNA
---------------------------------------------

3 Signed:
ZF=0 and SF=OF	JG

JNLE
---------------------------------------------
SF<>OF JNGE
JL
---------------------------------------------
ZF=1 or SF<>OF JLE
JNG
---------------------------------------------

and
2 Common:
ZF=0			JNE

JNZ
---------------------------------------------
ZF=1 JE
JZ
---------------------------------------------

Names just aliases.
Common group uses just one(!) FLAG ZF
'cause
IF a = b THEN a - b = 0
Unsigned group uses just two(!) FLAGS ZF and CF
'cause
IF a < b then a - b < 0 end if result is less then zero borrowing
happens to compelemet result and CF indicates it.

01h
- --- < 0
02h
then machine comlement 01h to 101h and sets CF to report
abou it
so 01h - 02h = 101h - 02h = 0FFh and carry is set.

then
cmp 1,2 ;cmp = sub sets CF cause there was borrowing
cmp 2,2 ; sets ZF cause 2-2=0

jbe ; IF ZF (sub a - b was 0) or IF CF (sub a - b needed borrow to finish operation and it means that a was less then b)

Shall I continue?
Was all the above superhard to understand?

Agrhhh!
This edit window makes me crazy!
I aligned opcodes conditions and names of JCC into two columns -
why the names shifted two left!

Locu! Can you teach me how to arrange two columns in this message editor?
Posted on 2002-02-14 16:48:55 by The Svin
wow Svin ... you sure are 3l33t!! :)
I mean ... only stupid, ignorant and hypocrites really use .IF.ELSE.ENDIF, or masm for that matter (hear that hutch?)
I mean, when avoiding them might translate in a couple of CPU cycles less ...
As the saying goes ... real man code in HEX

Ok sorry, maybe it's a bit harsh. It's just that it's not a good morning today ;)

Seriously, only one question, you are coding for a platform like Windows right? and the days of the 8086 are long gone. What is exactly the advantage of using jz,je etc instead of .IF.ENDIF in say the main window procedure to sort out the wmsg? I agree that is better to avoid HLS in algorithms where speed is critical, but otherwise I think is overshooting a bit.
It's called 80/20 ... focus on the 20% that gives you the 80% of results.

Unless of course you have lots of spare time and really don't care about deadlines (please note that I write asm for hobby in the very little free time I have and not as a professional ... I would use something like C++ otherwise ... it's just a theoretical discussion on priorities here)

If you really like super-efficient/tight/illegible code, why not code for a microcontroller instead of a modern day PC?

But maybe it's just that I don't have the mindset of a computer programmer and can't understand the subtleties :) Guess that?s why I?m in a different business ;)

This is just my 2cents.
Nothing personal.

cheers
Randomizer
Posted on 2002-02-15 03:19:14 by random
Svin,

I agree totally with you : jcc are not hard...

The point is .IF macros instructions preserve source codes readability while the jcc makes the source look *dirty* are painful to (re)read and leads to the symptom better known under the name of "spaghetti code".

It can help beginners that are not used to it in the first time... not because jcc are that hard, but they preserve source readility and IMHO, it is important to understand his own program...

I am not meaning that a program with jcc is impossible to read : I now code all my branching using them and no longer use the .IF... but the sources are messier and it can confuse the beginners...
Posted on 2002-02-15 03:56:39 by JCP
What is exactly the advantage of using jz,je etc instead of .IF.ENDIF in say the main window procedure to sort out the wmsg?

What is .ENDIF?
My machine has not such an opcode.
It's funny, I ask simple direct question and for for the second time
I'm reading answer on anything else but the question :)

You think .IF .ELSEIF .ENDIF are better for you then even simple opcode?
It's OK. It is your choise.
You think that speed doesn't such a matter on modern PC?
It's OK - you free to think so, I have no wish to talk you out of it.
But it wasn't my question.

The question was - if HLL is more convinient to you why do your
use machine language?
Be happy with your C++.
(hear that hutch?)

Barking for help? ;)
You make me sick.
We discussed it with Steve. And respect each other enough to
be honest, and exchange thoughts, proves and arguments.
So he is well awared of MHO.

You see, for us the most interesting thing was topic itself,
for you as I see is more interesting that may be in my question
I somehow inderectly called you LAMER.
Or may be I tried to say that my dick was bigger.
Common, I'm beyond such childish problems.

My message was clear and direct.
1. If you know machine, then use of opcodes is EASIER and more flexible than HLL statement.
2. Flags and JCC is very easy to learn if you learn it right way.
3. If you still don't agree with 1. and 2. then I, respecting YOUR
OPINION could only recommend you to keep your faith and proceed, according your princeples with HLL.

BTW Hutch knows how to handle conrol blocks in mnemomics much better than with HLL.
I may give you a lot of examples when HLL statemets buffled him
and he wrote very funny code:) Wich almost never happened when he made algos in mnemonics only.

The only use of it that it produce more easier anonimous labels.
@@: has to little ability in it. And the only problem in complex algos to create a lot of names for labels.
Posted on 2002-02-15 05:43:18 by The Svin