Exiting a subroutine without using return?

Status
Not open for further replies.

davepusey

Member
I am writing a program for the PIC16F84A. What i need to do is at the end of my subroutine return to a specific place in the code instead of the line after that which called the subroutine. Can i do this using a GOTO instruction instead of the RETURN instruction? If not, then how?

Thanks in advance.
 

If you're calling a subroutine (using call) the return address is pushed onto the stack, so if you don't execute a return (which pops the return address off the stack), the stack will soon overflow.

If you want to do this, don't use a subroutine, and don't use 'call', simply use 'goto' to call the routine, and another 'goto' to return where you want.
 
Right ok that's fine.

One other thing, im using the BTFSC instruction but an not sure if i have to write the bit numbers as 0,1,2,3,4,5,6,7 or 1,2,4,8,16,32,64,128. Which is it please?
 
BTFSS REGISTER, <bit>

<bit> = 0,1,2,3,4,5,6,7

Look at the instruction set in the datasheet of your PIC.
 
that's strange. I'll upload this to my site for ya...hang on.

here you go....

**broken link removed**

Will be uploaded in a few minutes.
 
Check the Datasheet. It think memory starts @ 0Ch. yes just doubled checked.



Code:
cblock    0Ch

var1
var2

endc

That'll do it.
 
bsodmike said:
Check the Datasheet. It think memory starts @ 0Ch. yes just doubled checked.



Code:
cblock    0Ch

var1
var2

endc

That'll do it.

Oh. I was just gonna do

RUNSEQ1 EQU 0Ch
RUNSEQ2 EQU 0Dh

Also how do i do a "if RUNSEQ1=<decimalnumber> then do the next line, overwise skip it" statement?

Sorry for all these odd questions but this is my first ever PIC program.
 

That's perfectly OK, but using cblock/endc just makes it simpler (and shorter to type).

Also how do i do a "if RUNSEQ1=<decimalnumber> then do the next line, overwise skip it" statement?

You don't in assembler, that's a high level language command. In assembler you need to compare two values, either by subtraction or XOR, then check the status flag values. If you consult the PICList there is a complete section on various methods of doing this.
 

I knew that . I just writing it like pseudo code.

Here's what i want to do... perhaps you can help me convert this to assembler...

If RUNSEQ1 == .17 then C=0
If RUNSEQ1 == .136 then C=1
 
Code:
     MOVLW    .17
     XORWF    RUNSEQ1, W
     BTFSC    STATUS, Z
     CLRF     C

This loads W (the accumulator) with 17 decimal. and does a exclusive or of this value with the value in runseq1. If both are identical then the result of this operation will be 0. So we check the Z(ero) flag in status register and if set, we clear C...

Do something similar for the second compare
 

Getting an error...

Symbol not previously defined (Z)

Also how do i convert my code to a .hex file?
 
Now i need to superimpose RUNSEQ and RUNSEQ2 storing result in W. By superimpose i mean like this...

Code:
RUNSEQ        10001000
RUNSEQ2       01000100

Result in W   11001100

I thought i could use an OR but i cant seem to figure it out. Your help would be helpful (yet again)!
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…