Zone compare range check small demo program...
Hi Fellow Proppers..
Customer support for a local here in OZ.
Wanted a simple but fast range compare .. if value is between 2 values..output on..
Attache a quick knock up..in asm.
See file attached.
Dare to share if you can do it better..or if you have any suggestions .. please fire away.
Cheers· Ron Mel OZ
Customer support for a local here in OZ.
Wanted a simple but fast range compare .. if value is between 2 values..output on..
Attache a quick knock up..in asm.
See file attached.
Dare to share if you can do it better..or if you have any suggestions .. please fire away.
Cheers· Ron Mel OZ

Comments
Cheers,
Shane. (Perth WA)
But... well done, Ron! The very first result from an unexperienced machine code programmer
If this is what you took from my tutorial I am really proud of you - but now comes the second level...
I inserted comments with some hints for improvement:
DAT org 0 go1 mov dira,pins 'set pin 0..3 to output ' deSilva: It will do no harm to repeat this MOV as well, so saving a label loop mov store,#0 'reload store with zero mov temp,ina 'get value from ina and temp,#%11110000 'only interested in bits 7..4 ' deSilva: Now this is between 16 and 240, with increments of 16 ' deSilva: Very unconvenient, so one generally shifts it ' SHR temp, #4 ' deSilva: value in TEMP is now between 0 and 15 cmp lo,temp wc 'compare write C only if lo is < set C ' deSilva: It is good practice to comment such check as 'formula' ' deSilva: i.e.: "lo < temp sets C" ; you did this nearly that way! IF_C add store,#1 'add 1 to store if C set from above cmp temp,hi wc 'do another compare on hi value ' deSilva: i.e.: "temp < hi sets C" IF_C add store,#1 'check for C flag again add 1 again to store ' deSilva: Accumulating "knowledge" is good idea... ' deSilva: .. however "advanced programmers" try to use the FLAGs only ' deSilva: See alternative in follow-up posting. cmp equal,store wz 'now compare again to see if both satisfied (in range) ' deSilva: using a variable "equal" obfuscates the idea behind "2" ' CMP store, #2 WZ ' deSilva will look much better IF_Z or outa,#1 'turn output P0 on if value is 2 ' deSilva: OR is very defensive, but not always needed.. ' deSilva: See, you have guarded it by DIRA, and you are in your own COG IF_Z jmp #loop 'go again if Z was set (values equal) and outa,#%11110000 'or else turn outputs off ( 4 leds on P3..P0) ' deSilva: Generally you "Invert" this logic; above two instructions can be ' deSilva: simplified to: ' IF_NZ ANDN OUTA, PINS ' deSilva: See what I've done here? Main thing is I re-used PINS for consistency! ' deSilva: ANDN is VERY handy - it's the opposite of OR! jmp #loop 'jmp loop go again pins long %10000000_00000000_00000000_00001111 '1>output I have 4leds on P3..P0 hi long 143 'some arbitrary setpoint high level lo long 15 'some arb level setpoint low.. ' deSilva: change the above to... OOPS! Those values were no good idea at all!!! equal long 2 'equal means value 2 in store temp res 1 'temp register .. store res 1Post Edited (deSilva) : 2/25/2008 4:57:51 AM GMT
Thanks for the pointers..
I can get most things happening in asm but it takes some effort.
Spent the last 30 years of my life programming PLC's so the logic part of it is easy
just getting used to all the instructions is the biggest issue with me..
Thats why I try and disect snippets /blocks of code to see what happens..
I will type your code in and disect .. do you ever sleep ?.. it must be early morning now..
It is school/uni holiday time at the moment ??
The value by the way can be and will be totally variable so the shift method you indicated
may well work for certain value's but probably won't satisfy it totally...
The values are most likey in the 1000-4000 range (high speed A/D chip read/compare)
Anyway as alway's thnks for the pointers and take care.
Ron Mel Oz
Edit: And yes! It was!! And a very common mistake!! See NO/YES below!
CON firstInputPin = 4 firstOutputPin = 0 DAT org 0 go1 mov dira, oPins 'set pin 0..3 to output mov temp, ina 'get value from ina SHR temp, #firstInputPin and temp, #%1111 'only interested in bits 7..4 ' C will now be used to indicate a "good" situation cmp lo, temp wc 'lo < temp sets C IF_C cmp temp, hi wc 'temp < hi confirms C 'NO! IF_C or outa, #firstOutputPin 'turn output P0 on if in range IF_C or outa, firstOutputPinMask ' YES! IF_NC ANDN OUTA, oPins jmp #go1 'jmp loop go again firstOutputPinMask long |< firstOutputPin| oPins long %1111 << firstOutputPin '1>output I have 4leds on P3..P0 hi long 6 'some arbitrary setpoint high level lo long 2 'some arb level setpoint low.. temp res 1 'temp register .. ' Fit 496Post Edited (deSilva) : 2/25/2008 2:55:38 PM GMT
Then your program had been faulty!
You should understand that my shifting did not change anything within your logic! It has just made it cleaner!
Maybe we'll have to start our own forum
Sorry (to the rest of the world)... off topic and only (possibly) of interest to four of us here!
Cheers,
Shane.
This is very cool idea. MUX is generally not a necessary instruction,
as you can always replace it by something as the above two instructions, but it will
shorten the program!!!
Edit: deSilva is still blushing...
The OR must be with #|<firstOutputPin or course
But everything will be mended by the MUX!!
As an exercise, here is a use of MUX to simulate a SaveFlags and a RestoreFlags operation,
which do not exist on the Prop
Post Edited (deSilva) : 2/25/2008 3:30:04 PM GMT
go1 mov dira, oPins 'set pin 0..3 to output mov temp, ina 'get value from ina SHR temp, #firstInputPin and temp, #%1111 'only interested in bits 7..4 ' C will now be used to indicate a "good" situation cmp lo, temp wc 'lo < temp sets C IF_C cmp temp, hi wc 'temp < hi confirms C MUXC outa, firstOutputPinMask 'turn output P0 on if in range jmp #go1 'go againPost Edited (deSilva) : 2/25/2008 3:33:33 PM GMT
but... we wouldn't have seen the other bit of code about saving the z and c flags
Steve I make five, but currently in Pula Penang Malaysia ATM, been here two years and will for another year at this stage.
Dont ask for any help though... I'm just starting out [noparse]:)[/noparse]
Sevs
Perth(WA)