The Student Room Group

PIC basic to ASM learning

Scroll to see replies

Reply 20
Original post by elohssa
It depends on platform but generally conditional branching is achieved in ASM via either conditional moves (efficient but not use-able in many situations) or conditional jumps (unpredictable conditional jumps lead to heavy branch mispredictions). Control flow in ASM is a bit nasty. I think PIC-Basic has a GOTO instruction. Basically try writing all your control flow logic using only GOTO (no for/while loops etc) and you will know roughly what it's like.

Comparison in ASM is done via instructions that set flags e.g. in x86/x64 there is a CMP instruction that is exactly the same as the subtract (SUB) instruction except it doesn't modify the destination operand...

mov r1, 14
mov r2, 14
mov r3, 14

sub r1, r2 ;sets r1 to 0 and thus sets the ZERO flag
jz label ;jump to label if ZERO flag is set

;random code here

label:

cmp r2, r3 ;sets the ZERO flag but r2 is still 14 as CMP differs from sub and doesn't modify the destination

jz label ;create infinite loop


Thanks Elohssa,

I'm at the ABC stage of ASM learning, and sentences like: (unpredictable conditional jumps lead to heavy branch mispredictions) send my head in a spin. Having said that I can almost understand what you say. I'm just leaving the bottom of the learning curve:smile:

I've enclosed the INSTRUCTION SET from the 18F2431 PIC and a section of code that I had help with to give you an idea. (This sets up the PWM motor control output in some way??) For some reason when putting a number into an address, it has to pass through the WREG.

The BASIC program simulator does not support certain modules on this PIC, so needs to be inserted as ASM section. I assume I need to set up the QUADRATURE ENCODING module by putting each byte of data from the sheet into their memory addresses using ASM.

C.

''PWMduty 2, 0
ASM: bcf CCP2CON,DC2B0
ASM: bcf ccp2con,dc2b1
ASM: movlw 0x00 'Move literal to WREG
ASM: movwf ccpr2l 'Move contents of WREG to Address ccpr2l
Reply 21
Original post by Camerart
For some reason when putting a number into an address, it has to pass through the WREG.


Yea you can't move constants directly into memory.

Original post by Camerart
The BASIC program simulator does not support certain modules on this PIC, so needs to be inserted as ASM section. I assume I need to set up the QUADRATURE ENCODING module by putting each byte of data from the sheet into their memory addresses using ASM.


I don't really know much about MCs but if your task it just to copy some data into a specific memory address then you have all you need in that example you posted.
Reply 22
Original post by elohssa
Yea you can't move constants directly into memory.



I don't really know much about MCs but if your task it just to copy some data into a specific memory address then you have all you need in that example you posted.


The example I posted is already in the basic code, and controls the motor drive module in the PIC. Now I need to be able to write the instructions for the quadrature encoder module in the PIC.
Reply 23
Original post by Camerart
The example I posted is already in the basic code, and controls the motor drive module in the PIC. Now I need to be able to write the instructions for the quadrature encoder module in the PIC.



Yea, I meant syntax wise you have all you need.
Reply 24
Original post by elohssa
Yea, I meant syntax wise you have all you need.


Ok thanks Elohssa,

Looking at it from my point of view: I also have all I need to learn Greek, but I can't.

Only joking mate, thanks for your input.

C.

Quick Reply

Latest

Trending

Trending