Myke's Home Page

Book CD-ROM Home

File Copying/Harddrive Setup

Development Tools

Experiments

Projects

Useful Code Snippets and Macros

Introduction to Electronics

Introduction to Programming

Datasheets

PCBs

Links

McGraw-Hill Professional Publishing

"VarArray" Experiment

Array elements are accessed using the FSR register of the PICmicro MCU. This experiment shows how arrays can be initialized and accessed in PICmicro MCU assembler. When accessing PICmicro assembler using the instruction format:

  movlw  Element#			;  Get the Offset to the Element
  addwf  FSR, f
 
;  read/write/process Element pointed to by FSR

  movlw  Element#			;  Restore FSR to start of Array
  subwf  FSR, f
              

The experiment also shows how array access can be modelled as high level language statements.

The source code listed below can be accessed from the CD-ROM by clicking Here.

 title  "VarArray - Simulating an Array."
;
;  This Program shows how a single-dimensional array can be implemented
;   on a PIC using the "FSR" and "INDF" Registers.
;
;  99.11.13 - Updated for Second Edition
;
;  Myke Predko
;  96.05.10 - Original Version
;
  LIST P=16F84, F=INHX8M, R=DEC
  INCLUDE "p16f84.inc"

;  Registers
i     equ 12
Array equ 13                    ;  Four Bytes of an Array

 __CONFIG _CP_OFF & _WDT_OFF & _RC_OSC

  PAGE
;  Mainline of VarArray

  org 0

  movlw  3                      ;  Initialized the Variables
  movwf  i

  movlw  Array                  ;  Set up the Array Pointer to Start
  movwf  FSR

  movlw  'm'                    ;  Initialize the Array
  movwf  Array                  ;  Put in "myke".
  movlw  'y'
  movwf  Array + 1
  movlw  'k'
  movwf  Array + 2
  movlw  'e'
  movwf  Array + 3

;  i = Array[ 2 ] - Get the third element in the Array

  movlw  2                      ;  Move the Array to the Character
  addwf  FSR, f

  movf   INDF, w                ;  Get the Character at third Elemement
  movwf  i                      ;   and Store it

  movlw  2                      ;  Restore the Pointer to the start of the
  subwf  FSR, f                 ;   Array

;  Array[ 0 ] = 'M' - Change the high byte of the Array

  movlw  0                      ;  Move the Array to the Character
  addwf  FSR, f

  movlw  'M'                    ;  Store the New Value
  movwf  INDF

  movlw  0                      ;  Restore the Pointer to the start of the
  subwf  FSR, f                 ;   Array

Finished                        ;  Finished, Just Loop Around Forever
  goto  $
  end
              

Click Here to look at the tenth experiment - StackOps