Society of Robots - Robot Forum
Software => Software => Topic started by: g44 on March 27, 2010, 01:05:24 PM
-
asembler .
-
I don't know this specific assembler, but often to do a comparison you compute the difference and look at the sign of the result.
Look for conditional jump instruction in the datasheet.
Hope this helps,
Chelmi.
-
asembler .
-
With a PIC there is another way to do a "Look up Table" when the values to be looked up are 01, 02, 03, etc.
movf temp, wreg ; get value
andlw 0x07 ; limit to 3 bits so not to over jump table
addwf PCL ; add to program counter
goto state0 ; PC + 0
goto state5 ; PC + 1
goto state2 ; PC + 2
goto state7
goto state0
goto state1
goto state2
goto state3 ; PC + 7
Do use the simulator in MPLAB to step through the code to see how it works.
Good luck and have fun
-
asembler .
-
Ok, You just need to learn assembler and the PIC assembly instructions in particular. The data sheet for the PIC you are using does have the assembly instruction and how they are used. A good starting out tutorial is here:
http://www.gooligum.com.au/tutorials.html (http://www.gooligum.com.au/tutorials.html)
This will go through the basics.
Which PIC are you using?
JNE? Is this 'Jump Not Equal'?
The base-line and mid-range PICs do not have this instruction, but it can be done like this:
You have two values as:
;value1
;value2
movf value1, w ; move value1 into the W register
subwf value2, w ; subtract value1 from value2 (now in wReg)
btfsc STATUS, Z ; "bit test f and skip if clear". Tests the zero bit in the status register, if zero is set (=1) then the two values are equal
goto values_equal ; executes this line if the values are equal
nop ; skips to here if the values are not equal
All of the above instructions are explained in any mid-range PIC data sheet
Beside reading and studying the tutorials you need to use MPLAB simulator and step through pieces of code to see how they work.
-
Thanks waltr.
-
movf 0x5e, w ; moves the value store at 0x5e into w reg
-
Thanks waltr.
-
Look in the data sheet at the PIC instruction set or in the tutorial I post earlier. It is explained in both places.
-
Thanks waltr.
-
This line:
btfss comparereg,0
is testing bit 0 of value comparereg so your results are exactly as expected.
I assume you did this first:
movf compareref, 0 ; move compareref to w reg
Then:
subwf comparereg,1
A subwf and other instructions set FLAG bits in the STATUS register (do read the data sheet, it is explained)
so you need to test the ZERO bit of the STATUS register to see how if two values are equal.
You should be able to figure out how to write that.