Ian.M
Super Member
- Total Posts : 13273
- Reward points : 0
- Joined: 2009/07/23 07:02:40
- Location: UK
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/01 16:55:07
(permalink)
Yes I copy/pasted the typo. Guilty as charged. I'm afraid I was too deep into the exact SWAPF sequance and fighting the formatting in this editor to notice that all the code managed to do was load the Z flag from the old result. Stefan, thanks for spotting the ****up. Hopefully Bonedoc hasn't wasted too much time wondering why it didn't work Ian --- Assemble your 'Air Code' before posting to avoid embarrasment
|
Stefan Uhlemayr
Super Member
- Total Posts : 4292
- Reward points : 0
- Joined: 2005/05/12 12:25:46
- Location: Germany
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 03:23:25
(permalink)
ORIGINAL: Ian.M Yes I copy/pasted the typo.  No problem. That just happens, especially, if one of these members, which are known to have pretty good knowledge, is doing one of his very few mistakes - you don't expect it... ORIGINAL: Ian.M I'm afraid I was too deep into the exact SWAPF sequance and fighting the formatting in this editor to notice that all the code managed to do was load the Z flag from the old result. Especially, if I want to highlight some parts of a posted code, I do it this way: I write the code with any editor (formatted with spaces only), copy it the into the forum-editor, where I format it with the "courier new"-font. This code you can now format with color, bold, etc. (I've learned this from " vloki", quite useful sometimes... ). ORIGINAL: Ian.M Assemble your 'Air Code' before posting to avoid embarrasment  I can't do this at home, as on my private pc I haven't installed mplab - and so you may find quite some "oops" in my history, too...[&:] Greetings, Stefan
|
MBedder
Circuit breaker
- Total Posts : 6973
- Reward points : 0
- Joined: 2008/05/30 11:24:01
- Location: Zelenograd, Russia
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 04:28:11
(permalink)
In addition to formatting - I use almost the same "technique" with an external editor configured to replace tabs with spaces ( AkelPad in my case), and after pasting the text to a forum message composition window I select the text block and set the font face to Courier New (it's a monospace font) to keep the original formatting intact. A color can then be added without problems unlike a <code> tagged text.
|
1and0
Access is Denied
- Total Posts : 12099
- Reward points : 0
- Joined: 2007/05/06 12:03:20
- Location: Harry's Gray Matter
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 10:50:05
(permalink)
ORIGINAL: Ian.M Its a litttle harder to deal with the 'False' value in another variable but it can be done. The desired output in Myvar if the test fails is in VarF, the one if it succeeds is in VarT : movf MainCnt,W xorlw .250 ;condition->status, Zero is True swapf VarF, F ;Swap nibbles in VarF in situ without wiping the STATUS swapf VarF, W ;and back the right way round into W Swapf VarF, F ;Unswap VarF btfss STATUS,Z ;deferred test of condition movf VarT,W;True value ; movf MyVar,F ;is *wrong* corrected below movwf MyVar ;Set MyVar to the correct result without glitches
This takes one less instruction: movf MainCnt,W xorlw .250 ;condition->status, Zero is True swapf VarF,W ;swap nibbles in false value btfss STATUS,Z ;deferred test of condition swapf VarT,W ;swap nibbles in true value movwf MyVar ;set MyVar swapf MyVar,F ;unswap MyVar
|
Ian.M
Super Member
- Total Posts : 13273
- Reward points : 0
- Joined: 2009/07/23 07:02:40
- Location: UK
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 11:27:56
(permalink)
it avoids glitching VarF!  but it does glitch MyVar, which was the reason for discarding the preload MyVar with VarF then replace with VarT if the condition is true method.  Its not appropriate if MyVar is volatile, but if you are just after determanism, its usefull Thank you 1and0, I'm adding that to my collection.
|
1and0
Access is Denied
- Total Posts : 12099
- Reward points : 0
- Joined: 2007/05/06 12:03:20
- Location: Harry's Gray Matter
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 12:25:07
(permalink)
This avoids glitching VarF and MyVar: movf MainCnt,W sublw .250 ;condition->status, Zero is True btfss STATUS,Z bcf STATUS,C ;Carry = Zero bit movf VarF,W btfss STATUS,C movf VarT,W movwf MyVar
|
Ian.M
Super Member
- Total Posts : 13273
- Reward points : 0
- Joined: 2009/07/23 07:02:40
- Location: UK
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 14:20:32
(permalink)
EDIT: I was wrong, see below. IT IS CUTE, 1and1 is a genius. I think you've just done IF MainCnt>=250 rather than IF MainCnt=250 Otherwise its cute. Easily fixed by: <UNNEEDED FIX REMOVED> EDIT: Unless you have an absolute requirement not to use GOTO, at this point it would be easier and no slower to revert to using gotos and balance the execution paths with nops. It is also far closer to a HLL IF ... THEN ... ELSE ... ENDIF which is no bad thing.: movf MainCnt,W sublw .250 ;condition->status, Zero is True btfss STATUS,Z goto skip67t ; true movf VarF,W goto skip67x skip67t: movf VarT,W nop skip67x: ...
post edited by Ian.M - 2009/12/02 16:02:45
|
1and0
Access is Denied
- Total Posts : 12099
- Reward points : 0
- Joined: 2007/05/06 12:03:20
- Location: Harry's Gray Matter
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 14:39:45
(permalink)
It does IF MainCnt == 250 SUBLW Result Zero Bit Carry Bit ------------------------------------- Positive 0 1 Zero 1 1 Negative 0 0 btfss STATUS,Z bcf STATUS,C ;Carry = Zero bit
The above two instructions make the Carry bit equal to the Zero bit (positive case).
|
Stefan Uhlemayr
Super Member
- Total Posts : 4292
- Reward points : 0
- Joined: 2005/05/12 12:25:46
- Location: Germany
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 15:27:50
(permalink)
ORIGINAL: 1and0 This avoids glitching VarF and MyVar: movf MainCnt,W sublw .250 ;condition->status, Zero is True btfss STATUS,Z bcf STATUS,C ;Carry = Zero bit movf VarF,W btfss STATUS,C movf VarT,W movwf MyVar
Well done!  I've added this to the "neat asm-tricks" in the Software-Gallery. Anyone who knows a better title then " Conditional (content of a register) register-copying:"? Thanks, Stefan
|
DarioG
Allmächtig.
- Total Posts : 54081
- Reward points : 0
- Joined: 2006/02/25 08:58:22
- Location: Oesterreich
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 17:07:02
(permalink)
Yup! sounds cool, will have to find an application for that thx to everybody
|
1and0
Access is Denied
- Total Posts : 12099
- Reward points : 0
- Joined: 2007/05/06 12:03:20
- Location: Harry's Gray Matter
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/02 21:18:15
(permalink)
|
1and0
Access is Denied
- Total Posts : 12099
- Reward points : 0
- Joined: 2007/05/06 12:03:20
- Location: Harry's Gray Matter
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/03 13:18:27
(permalink)
Here are improvements that use one less instruction: movf MainCnt,w ;do comparison test sublw .250 ;condition in Zero bit addlw 0xFF ;Carry = ~Zero bit movf VarEQ,w ;get value assuming condition is equal btfsc STATUS,C ;equal condition? yes, skip, else movf VarNE,w ;get value for condition is not equal movwf MyVar ;store value
and movf MainCnt,w ;do comparison test sublw .250 ;condition in Zero bit sublw 0 ;Carry = Zero bit movf VarEQ,w ;get value assuming condition is equal btfss STATUS,C ;equal condition? yes, skip, else movf VarNE,w ;get value for condition is not equal movwf MyVar ;store value
EDIT: Added "SUBLW 0" method.
post edited by 1and0 - 2009/12/06 14:43:20
|
Stefan Uhlemayr
Super Member
- Total Posts : 4292
- Reward points : 0
- Joined: 2005/05/12 12:25:46
- Location: Germany
- Status: offline
RE: A way to perform two lines with one conditional statements?
2009/12/03 14:23:13
(permalink)
I changed the link in the gallery to this improved one. In fact, both variants are interesting, because of the method to use the "C"-bit as zero-bit. As a lot of instructions aren't changing the "C"-bit, you may save an instruction here and there using this trick. Thanks again,  Stefan
|