Pic asm

Páginas: 44 (10829 palabras) Publicado: 1 de diciembre de 2010
A Guide to Common PIC Assembly Programming Constructs
Jason Thweatt 0 Preliminary Information 0.1 0.2 0.3 1 What this guide is, and what it is not Changes and Editions Editorial and Acknowledgement Credits 1 1 1 2 3 3 3 4 6 7 8 9 9 10 11 11 12 14 17 19 23 23 25 28

Initializing a File Register 1.1 1.2 Initializing a File Register (with a literal) Initializing a File Register (with a value froma different file register)

2

IF-THEN-ELSE statements 2.1 2.2 2.3 2.4 2.5 2.6 IF A > 0 IF A = 0 IF A > B (A and B are stored in file memory) IF A > X (A is stored in file memory, X is a constant) IF A = B (A and B are stored in file memory) IF A = X (A is stored in file memory, X is a constant)

3

FOR loops 3.1 3.2 Executing the FOR loop Nested-FOR loops

4 5 6 7

SWITCH / CASEstatements Direct addressing vs. Indirect addressing GOTO statements vs. CALL statements Full Program Code Examples 7.1 7.2 7.3 Direct Addressing Example Indirect Addressing Example IF-THEN-ELSE structure

Copyright © 2004, 2005 Jason S. Thweatt

1

0
0.1

Preliminary Information
What this guide is, and what it is not

The purpose of this guide is not to teach you how to program inAssembly. There is no substitute in that regard aside from understanding the instruction set and knowing how to write an algorithm. I am fond of telling students that if you can write an algorithm whose steps are fine enough, that writing an Assembly program becomes a matter of simply translating the steps of your algorithm into the Assembly statements of your processor. That is perhaps the greatestskill that you can develop in this part of the course, because you will eventually work with a different processor, and a different Assembly standard. But this will only be a matter of learning a new set of Assembly mnemonics, and not one of having to relearn Assembly. In using this guide, you should also note that while it may give information on how to use the constructs, it is mostly up to you tounderstand when and why you should be using them. This will require you to have a mastery of the algorithm that implements a given program, and to understand the sometimes-subtle differences that exist between two constructs. Finally, I am sure that if you have programmed before, you know that programming is at least as much an art as it is a science. The information presented here is not meant tosubstitute for either your analytic ability or your creativity in designing a particular algorithm. These are tools, and nothing more. I have tried to present these constructs in a logical order; if construct B uses construct A, then construct A is presented first. As far as usage is concerned, when a label is shown without brackets in a comment: FIRST equ 0x20 ; FIRST = 0x20

then it is thelabel that has that value. When a label is shown in brackets: MOVLW MOVWF FIRST FSR ; [W] = 0x20 ; [FSR] = 0x20

then it is the contents of the address having that symbolic label as its name that has the value. This convention also applies to numeric values. 0x10 is the literal value hex 10. [0x10] describes the contents of memory address 0x10.

0.2

Changes and Editions

This document willcontinue to evolve as more people read it, and suggest changes that will make it more appropriate for their needs. Version number 1.5 of this document was first generated on 01 August 2005. The version number is for editorial purposes only, as I expect this document to be a continually changing draft. All questions and comments concerning the information presented herein should be forwarded to theauthor, Jason Thweatt. Professor Thweatt can be reached most easily via e-mail at jthweatt@vt.edu. All constructive criticism and suggestions for additions and editions are greatly appreciated

2

0.3

Editorial and Acknowledgement Credits

My greatest thanks go to Bob Lineberry, who helps me to keep this document current by supporting the Computer Engineering Laboratory and its...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • CICLO ASM
  • Pica Pica
  • Pice
  • los picos
  • pico
  • pico
  • Pico
  • El Pic

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS