add cY0,3
cmp cY0,84 ;compare cY0 with 84
jnge ct0 ; jump to ct0 if cY0 >= 84
mov cY0,84 ; else set limit



add cY0,3
.IF cY0 >= 84 ; if cY0 >= 84 then...
mov cY0,84 ; set limit

Readability is one advantage.. am I turning into a bean counter here?
Posted on 2003-09-17 19:00:07 by drarem
the if then style can be harder to debug. not for the debugger but the person... so its up to you
Posted on 2003-09-17 19:10:16 by devilsclaw
Sometimes you could save some space replacing:
	.IF [myvar ]
	or	[myvar], 0

Posted on 2003-09-17 19:47:10 by S.T.A.S.
readability. once you start using .if/.then and .while, etc. asm is pretty much on par with C for ease of coding, gleaning the purpose of a block of code, managing. in terms of debugging you could always preserve the original structure by using symbolic debugging.
Posted on 2003-09-17 20:56:56 by grv575

Readability is one advantage.. am I turning into a bean counter here?

Well, if making your assembly code more readable is turning you into a bean counter, then we should all start counting beans :-).

Seriously, though, it is not possible to make a general recommendation which way to go; you have to consider the use of HLL-like control structures on a case-by-case basis. Most of the time, the readability of the HLL-like control structures is a *very* big win with little loss in efficiency. However, if you get carried away and start writing "C programs with MOV statements" then the code you write will be no better than that produced by a C compiler (indeed, it will probably be worse than what a good C compiler produces), so you don't won't to take this to an extreme if you care about the performance or size of your code.
Randy Hyde
Posted on 2003-09-18 10:56:19 by rhyde
aaaah, .IF .THEN .ELSE... as someone said some time ago...

are we asm coders or what ?

i only use cmp ;)
Posted on 2003-09-18 12:18:15 by Bit7
:) I use IF/THEN/ELSE, it is functionally the same as compare but I don't spend hours and hours figuring out the cmp section of my message loop. Currently Toolbar Paint has an incredibly complicated message loop, it would be insane to have to deal with cmp/jnz, I would spend more time debugging the message loop than the tools.
Posted on 2003-09-18 12:32:21 by donkey
There are times when you want a pure optimization (where you have no assembler provided constructs and do all the jumping, branching, comparing yourself) such as if you are making a video encoder or comlex realtime radiosity rendering engine :grin: and then other times when you are making a macro optimisation (as I call it) where you know the performance of you code will still be excellent but you're focusing more on making your design work and easily maintainable (such is the case with making some Utitily, like Doney's toolbar builder). In this case, it's okay to let the assembler decide how to manage the cmp/jxx automatically because you know it won't effect the performance enough to make a difference. Instead, you get to spend your time making a product rather than debugging difficult to undertand jmp, cmp, and branching tables.

So you have "pure optimization" where you need absolute control and performance, and you have "macro optimization" where you are more concerned with making the design work and making it readable. In the second case, is 3 clock cylces gonna make a difference if there is 90% idle time anyway waiting for the user response, then it's moot.

The author of the book "Inner Loops" makes a good case that using the .if .else. .while constructs in MASM produces equally efficient code as if it was hand optimized. So it may still not be a major issue.

Posted on 2003-09-18 13:55:08 by _Shawn
thanks for all the insight, I went with a macro. I figure a macro would help me further when it comes time to optimize the section.

;Usage: CMPMAX A,B - if A >=B then A=B
.IF A >= B
push B
pop A

;Usage: CMPMIN A,B - if A <=B then A=B
.IF A <= B
push B
pop A

How would I do jump-to labels within the macro so it is not errored out as a redefinition of the label?
Posted on 2003-09-18 20:44:26 by drarem
Define the label as local:

jmp lbl
;nothing happens here
Posted on 2003-09-18 20:52:37 by donkey