Author Topic: asembler  (Read 3916 times)

0 Members and 1 Guest are viewing this topic.

Offline g44Topic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
asembler
« on: March 27, 2010, 01:05:24 PM »
asembler . 
« Last Edit: May 05, 2010, 06:46:04 AM by g44 »

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: asembler
« Reply #1 on: March 27, 2010, 01:12:53 PM »
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.

Offline g44Topic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
Re: asembler
« Reply #2 on: March 27, 2010, 02:22:25 PM »
asembler .
« Last Edit: May 05, 2010, 06:46:29 AM by g44 »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: asembler
« Reply #3 on: March 27, 2010, 02:44:39 PM »
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.

Code: [Select]
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

Offline g44Topic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
Re: asembler
« Reply #4 on: March 27, 2010, 04:14:03 PM »
asembler .
« Last Edit: May 05, 2010, 06:46:58 AM by g44 »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: asembler
« Reply #5 on: March 27, 2010, 05:38:44 PM »
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
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.

Offline g44Topic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
Re: asembler
« Reply #6 on: March 28, 2010, 07:28:08 AM »
Thanks waltr.
« Last Edit: May 05, 2010, 06:47:42 AM by g44 »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: asembler
« Reply #7 on: March 28, 2010, 10:36:17 AM »

movf 0x5e, w  ; moves the value store at 0x5e into w reg

Offline g44Topic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
Re: asembler
« Reply #8 on: March 28, 2010, 11:18:55 AM »
Thanks waltr.
« Last Edit: May 05, 2010, 06:48:12 AM by g44 »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: asembler
« Reply #9 on: March 28, 2010, 12:17:57 PM »
Look in the data sheet at the PIC instruction set or in the tutorial I post earlier. It is explained in both places.

Offline g44Topic starter

  • Jr. Member
  • **
  • Posts: 38
  • Helpful? 0
Re: asembler
« Reply #10 on: March 28, 2010, 06:35:12 PM »
Thanks waltr.
« Last Edit: May 05, 2010, 06:48:49 AM by g44 »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: asembler
« Reply #11 on: March 28, 2010, 06:57:36 PM »
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.

 

SMF spam blocked by CleanTalk