11.07.2015 Views

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

PICBASIC PLUS LITE Manual - Profe Saul

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>PICBASIC</strong> <strong>PLUS</strong> Compiler6 - Incorporating Assembler into a BASIC program.This may come as a blow to any avid BASIC programmers out there, but assembly languagesubroutines are occasionally unavoidable. Especially when time-critical or ultraefficient code is required. Not everyone agrees on this, and I would be more than happyto be proved wrong. However, I urge you to gain even a rudimentary understanding ofassembler. You will achieve a greater insight into how the PIC functions at its core level,and it will also allow information to be gleaned from Microchip’s many datasheets andapp-notes (sometimes!). This will ultimately lead to better compiler programs being written.Because sometimes only assembler code will suffice, the <strong>PICBASIC</strong> <strong>PLUS</strong> compilerallows a seamless transition between BASIC commands and assembler mnemonics.Consider the following line of code: -IF VAR = 1 THEN MOVLW 10 : MOVWF VAR : ELSE VAR = 2As can be seen, the same line contains both BASIC and assembler commands. This isbecause the compiler treats assembler mnemonics as BASIC commands. Which meansthat they must follow the same rules as BASIC commands, such as a variable or labelmust exist if used.Of course, pure assembler can also be implemented by wrapping it inside an ASM-ENDASM construct, or preceding the mnemonic by an @ symbol. This will pass anyassembler mnemonic of directive straight to the assembler without the compiler interferingin any way. The above line of code in assembler is: -ASMMOVFW VARSUBLW 1BNZ LABEL2MOVWF VARGOTO LABEL3LABEL2 MOVLW 2MOVWF VARLABEL3ENDASMThis is very similar to the code produced by the compiler, but without any bank or pagemanipulating being carried out.Assembler LabelsAlso, you will notice that label names do not have a colon after them. If the same assemblercode was written without the ASM-ENDASM constructs in place, then the colonwill once again be required. However, each time a label is placed in the BASIC source,it is tagged for use with page manipulation. If the label is beyond the 2K barrier, then theRP0 and RP1 bits of STATUS will be set or cleared.134Copyright Crownhill 2001

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!