Electronics > Microcontrollers

Creation of a variable in ASM file for PIC 12F675



I am busy getting familiar with the whole ASM  SW for programming the pic PIC 12F675 in my PIC KIT 1 demo board. I am a first time programmer.

In one of the demo files they create two variables as shown below (question follows afterwards):

;************************** VARIABLE DEFINITIONS ******************************

      cblock   0x20         
   STATE_LED         ; LED state machine counter
   STATE_DEBOUNCE         ; button debounce state machine counter


1. What does cblock 0x20 exactly do?

2. How does one ascertain how big the variable is? In notherwords, when I create a variable, is it 8bits wide? Or 16 bits wide?

3. Suppose I wanted to create a variable that was 32bits wide, how does one do this?

cblock/endc allocates the following variables at the address 0x20, see MPASM help or any decent tutorial. All registers, and hence assembly variables, are 8 bit wide on 8-bit PICs. Longer variables will have to be split across several registers, and for arithmetic you'll have to do something like this.

Higher level programming languages like C will do this automatically.

You'll want to look at http://ww1.microchip.com/downloads/en/DeviceDoc/33014K.pdf
The manual for the assembler.  This is often neglected in between the device datasheets and architecture descriptions and "make it work" tutorials, but you need it to explain the details of the tools.

Here are answers to your questions 2 and 3.


Var1:1 ; 8-bit wide variable
Var2:2 ; 16-bit
Var3:4 ; 32-bit


PIC Assembler is very easy!


[0] Message Index

There was an error while thanking
Go to full version