> a book i've read says to declare, then initialize, then other subroutines, > then start, then main functions. Some people do write that way. Personally I prefer my main code at the start and routines after. I have trouble wading through subroutines to get to what's calling them. Tidy code is a lot easier to debug So, with that bias, my layout preferences and Dr Bartfai's comments in mind - ( = indicates a space, I don't use tabs) ====list P=16F877 ====include "c:\P16F877.inc ;---------------------------- ;You can suppress error messages ; =errorlevel -305, -302, -306 ;---------------------------- ;You need to set CONFIG, eg (all on one line) =__CONFIG _CP_OFF & _XT_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _LVP_OFF ;Declarations d1====equ===20 d2====equ===21 d3====equ===22 ;------------------------------ ;You can also define variables in a block of memory ====cblock 0x20==========;this declares variable RAM address ====d1 ====d2 ====d3 ====endc ;specifically define port pins eg #define===led1====porta,0 #define===led2====porta,1 #define===led3====porta,2 #define===led4====porta,3 ;eg bsf led1 ;and make macros for bank selection (there is another way - Olin ?) bank0=macro =========bcf====status,rp0 =========bcf====status,rp1 =========bcf====status,irp =========endm bank1=macro =========bsf====status,rp0 =========bcf====status,rp1 =========bcf====status,irp =========endm ;------------------------------ ====org=0x000 ====goto=init ;----------------------------- ;If you're using interrupts ====org=0x004 ====goto=isr ;---------------------------- Init=====movlw==b'00000000'======;all porta low =======movwf==PORTA =======bsf====STATUS,RP0=====;bank 1 =======bcf====STATUS,RP1 ;or use the macro to change bank. Simply type =======bank1 =======movlw==b'11110000'======;0,1,2,3 of porta are output =======movwf==TRISA =======bcf==== STATUS,RP0=====;bank 0 ;or =======bank0 Main===bcf=====PORTA,1========;be aware of read-modify-write =======nop====================;problems that may occur when =======bcf=====PORTA,2========;changing port pin data =======nop =======bcf=====PORTA,3 =======nop =======bsf=====PORTA,0 =======call=====Delay =======goto====main Delay===movlw 0x2C===========;4999993 cycles =======return =end ======================================================= > I get a stack underflow error Because you had org 0x000 set to INIT, not START. The first piece of code encountered ended with a RETLW that had no CALL -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics