Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

The Art of Assembly Language Programming Using PIC® Technology: Core Fundamentals
The Art of Assembly Language Programming Using PIC® Technology: Core Fundamentals
The Art of Assembly Language Programming Using PIC® Technology: Core Fundamentals
Ebook666 pages5 hours

The Art of Assembly Language Programming Using PIC® Technology: Core Fundamentals

Rating: 0 out of 5 stars

()

Read preview

About this ebook

The Art of Assembly Language Programming using PIC® Technology thoroughly covers assembly language as used in programming the PIC® Microcontroller (MCU). Using the minimal instruction set, characteristic of most PIC® products, the author elaborates on the nuances of how to execute loops. Fundamental design practices are presented based on Orr’s Structured Systems Development using four logical control structures. These control structures are presented in Flowcharting, Warnier-Orr® diagrams, State Diagrams, Pseudocode, and an extended example using SysML®. Basic math instructions of Add and Subtract are presented, along with a cursory presentation of advanced math routines provided as proven Microchip® utility Application Notes.

Appendices are provided for completeness, especially for the advanced reader, including several Instruction Sets, ASCII character sets, Decimal-Binary-Hexadecimal conversion tables, and elaboration of ten ‘Best Practices.’ Two datasheets (one complete datasheet on the 10F20x series and one partial datasheet on the 16F88x series) are also provided in the Appendices to serve as an important reference, enabling the new embedded programmer to develop familiarity with the format of datasheets and the skills needed to assess the product datasheet for proper selection of a microcontroller family for any specific project.

The Art of Assembly Language Programming Using PIC® Technology is written for an audience with a broad variety of skill levels, ranging from the absolute beginner completely new to embedded control to the embedded C programmer new to assembly language.

With this book, you will be guided through the following areas:

  • Symbols and terminology used by programmers and engineers in microcontroller applications
  • Programming using assembly language through examples
  • Familiarity with design and development practices
  • Basics of mathematical knowledge in hexadecimal
  • Resources for advanced mathematical functions

Approaches to locate resources

  • Teaches how to start writing simple code, e.g., PICmicro® 10FXXX and 12FXXX
  • Offers unique and novel approaches on how to add your personal touch using PICmicro® ‘bread and butter’ enhanced mid-range 16FXXX and 18FXXX processors
  • Teaches new coding and math knowledge to help build skillsets
  • Shows how to dramatically reduce product cost by achieving 100% control
  • Demonstrates how to gain optimization over C programming, reduce code space, tighten up timing loops, reduce the size of microcontrollers required, and lower overall product cost
LanguageEnglish
Release dateApr 24, 2019
ISBN9780128126189
The Art of Assembly Language Programming Using PIC® Technology: Core Fundamentals
Author

Theresa Schousek

Theresa Schousek has been a Microchip (R) Design Partner for 20 years as President, Chief Engineer, and Owner of Vital Innovations LLC. She began her work with computers in 1983 with a Commodore (R) 64. Prior to working as an independent design consultant, she worked for nearly 10 years in the automotive industry for General Motors Delphi Delco Electronics. She thrives on innovative design and has three process and sensor patented designs, plus one international patent. She is the sole inventor of General Motor's first infant seat and occupant detection system to inhibit airbag deployment. This system, and its derivatives, have 223 citations and is currently in production, 22 years later. Theresa earned a BSCEE from Purdue University, a dual accredited degree in Electrical Engineering and Computer Engineering. She earned a Master of Business Administration, with a practicum in operational process design, from University of Wisconsin, River Falls, in 2011.

Related to The Art of Assembly Language Programming Using PIC® Technology

Related ebooks

Electrical Engineering & Electronics For You

View More

Related articles

Reviews for The Art of Assembly Language Programming Using PIC® Technology

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    The Art of Assembly Language Programming Using PIC® Technology - Theresa Schousek

    The Art of Assembly Language Programming Using PIC® Technology

    Core Fundamentals

    First Edition

    Theresa Schousek

    Table of Contents

    Cover image

    Title page

    Copyright

    Dedication

    Preface

    Abstract

    Purpose and Scope

    Author’s Note

    Dare We Call It Fun?

    Chapter 1: Introduction

    Abstract

    Practical Applications

    Why Assembly?

    Core Families (Baseline, Midrange, Enhanced Midrange, High Performance)

    Data Sheet—Walk Through

    Straight Line Program Implementation

    Looped Code Implementation

    Microchip Tools

    Microchip Microcontroller Course Information

    Jargon Note—Italics

    Word Search

    Binary Puzzle

    Further Reading

    Chapter 2: Microchip 8-bit architecture

    Abstract

    The Microprocessor

    System Clock

    Execution Cycle

    Instruction Flow Pipelining

    Bus for Data and Program

    Hardware Interfaces

    Hardware Organization of Memory Address Space

    Data Memory and File Registers

    Arithmetic Logic Unit (ALU) and the W Register

    Prototyping

    Word Search

    Puzzle: Oscillator

    Further Reading

    Chapter 3: Instruction sets

    Abstract

    Instruction Set Comparison for PICmicro 10F, 12F, 16F, 18F Controllers

    Common 33 Instruction Set for PICmicro Controllers

    Addressing

    Code Example

    Paging Consideration

    Word Search: Instruction Set

    Puzzle: Instruction Set

    Further Reading

    Chapter 4: Beginning code

    Abstract

    Subroutines

    Macros

    Elementary Programs

    Program Counter Addressing

    Application Notes

    Interrupts and Jump Tables (AN514)

    Stacks (AN534)

    Calculate Timing

    Word Search: Beginning Code

    Puzzle: Number Square

    Further Reading

    Chapter 5: Looping code

    Abstract

    Loops Introduction

    8-Bit Sum of Data

    Looped Code Example

    Partial Straight Line Code Example

    Macros for Page and Bank Switching (AN586)

    Long Conditional Branch Vectors (AN581)

    Word Search: Loops Code

    Puzzle: Loops Code

    Further Reading

    Chapter 6: Embedded control fundamentals

    Abstract

    Embedded Control

    Electrical Wiring Diagrams

    Breadboards

    Basic Input and Output (I/O)

    Specialized Input/Output

    Timer Modules and Registers

    Development Boards

    Word Search: Embedded Control

    Puzzle: Flustered

    Further Reading

    Chapter 7: Fundamentals of good practice

    Abstract

    Structured Programming

    Software Design Patterns

    Reusable Code Guidelines

    Ordered Lists

    Structured Systems Development (SSD): Four Basic Structures

    Word Search: Program Design and Development

    Puzzle: Spiral

    Further Reading

    Chapter 8: Data and control structures

    Abstract

    Assembly Language Concepts

    Program Structures

    Data Structures

    Control Structures

    Word Search: Data Structures

    Puzzle: Jigsaw Sudoku 66h

    Further Reading

    Chapter 9: Logic and numbering systems

    Abstract

    Boolean Algebra

    Polynomial Systems

    Multibyte Integers

    Signed and Unsigned Integers

    Floating Point

    BCD as a Type

    ASCII—Single-Byte Characters

    Unicode—Multibyte Characters

    Word Search

    Puzzle: Diamond 22h

    Further Reading

    Chapter 10: Mathematical operations

    Abstract

    #Include Mathematical Routines

    Application Notes in Standard and High Performance Microprocessors

    Specific Math Utility Routines

    Featured 8-Bit MCU Boards

    Word Search: Mathematical Operations

    Puzzle: Number Tower

    Further Reading

    Chapter 11: Word search solution

    Chapter 1

    Chapter 2

    Chapter 3

    Chapter 4

    Chapter 5

    Chapter 6

    Chapter 7

    Chapter 8

    Chapter 9

    Chapter 10

    Puzzle Solutions

    Chapter 1

    Chapter 2

    Chapter 3

    Chapter 4

    Chapter 5

    Chapter 6

    Chapter 7

    Chapter 8

    Chapter 9

    Chapter 10

    Appendix A: Instruction Sets

    Baseline PIC MCU Instruction Set

    Comparison Table

    Appendix B: ASCII characters

    Appendix C: Decimal-binary-hexadecimal characters

    Appendix D: Best practices

    Appendix E

    Appendix F

    Index

    Copyright

    Newnes is an imprint of Elsevier

    The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, United Kingdom

    50 Hampshire Street, 5th Floor, Cambridge, MA 02139, United States

    © 2018 Elsevier Inc. All rights reserved.

    No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission in writing from the publisher. Details on how to seek permission, further information about the Publisher’s permissions policies and our arrangements with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency, can be found at our website: www.elsevier.com/permissions.

    This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may be noted herein).

    Notices

    Knowledge and best practice in this field are constantly changing. As new research and experience broaden our understanding, changes in research methods, professional practices, or medical treatment may become necessary.

    Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any information, methods, compounds, or experiments described herein. In using such information or methods they should be mindful of their own safety and the safety of others, including parties for whom they have a professional responsibility.

    To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products, instructions, or ideas contained in the material herein.

    Library of Congress Cataloging-in-Publication Data

    A catalog record for this book is available from the Library of Congress

    British Library Cataloguing-in-Publication Data

    A catalogue record for this book is available from the British Library

    ISBN: 978-0-12-812617-2

    For information on all Newnes publications visit our website at https://www.elsevier.com/books-and-journals

    Publisher: Mara Conner

    Acquisition Editor: Tim Pitts

    Editorial Project Manager: Charlotte Kent

    Production Project Manager: Vijay Bharath R.

    Cover Designer: Mark Rogers

    Typeset by SPi Global, India

    Dedication

    To Brian Walter, Elizabeth Margaret, and Victoria Rose

    In Memory of Zachary James and Nathaniel Howard

    With special thanks to Keith Curtis at Microchip Technologies for his assistance throughout this book

    Preface

    Theresas Schousek

    Abstract

    The purpose of the preface is to give a brief synopsis of the textbook and provide a light opening to the book. Two diagrams present the reader with an intro as to how assembly language fits within the larger scheme of programs. The author recalls her first foray into assembly language and its tight tie to the microcontroller’s architecture. The author reflects upon difficult and challenging work as actually fun and interesting, as well.

    Keywords

    Purpose; Scope; Program; Conversion; Mathematical; Numbering; Practical; Cost; Embedded; Control

    Purpose and Scope

    The purpose of this textbook is to give a thorough introduction to Microchip Assembly Language Programming for a wide range of users. Microchip’s most basic 33 instructions are used heavily throughout the text. It is recommended that the new user, regardless of 8-bit processor selection, self-restrict their use to the basic 33 instructions until these are second nature. This will prove to be the best approach to learning assembly language. This book provides a basic introduction to get the reader up to speed quickly. It provides beginning code development chapters on such things as basic data transfers, addition, and subtraction. Application notes for more complex mathematical routines, multiplication and division are presented for use as a practical solution. For the novice and returning programmers, there is also a chapter on Mathematical Numbering Systems. The chapters on arithmetic are reserved for the end of the book so as to not overwhelm the newest of users. Practical use and selection of specific evaluation boards, recommended by Microchip, is briefly presented with a cost, and feature, analysis.

    Fundamentals of good design practice are presented using tried and true approaches of flowcharting, Warnier-Orr diagrams, and State Machines. In addition, a separate chapter is dedicated to SysML, by way of introduction, with a thorough case example. A new text on the market is recommended for those expecting to use SysML daily in their business.

    The hardware interface is presented in a chapter on Embedded Control. Focus is on basic electronic glue used on 8-bit processors. Most of the interfaces can be used directly from this text. With only a modicum of electronic hardware changes, such as actual values of components, that will be required.

    Program Conversion Process; from Program to Individual Bits

    Complexity of computer programs is shown in Fig. 1. This diagram starts with the most fundamental element of a computer; the two states of 5 and 0 V. These are interpreted by the computer as a logical 1, for 5 V, and a logical 0, for 0 V or ground. The logical bits are then grouped by sequences of 8 bits, known as bytes. The binary strings are then grouped as clusters of 8 bits, or 1 byte; each byte defined by two hexadecimal digits from 0 through F. These binary strings are organized in groups of two nybbles; known as Machine Language. Each successive bubble, in Fig. 1, then introduces a higher level of programming. Assembly Language occupies the sweet spot between Machine Language and High level Language where knowledge of the embedded device is required and optimal efficient code can be produced.

    Fig. 1 The circle of languages and their position on the complexity scale.

    The compiler converts a high level language such as C, C ++, FORTRAN, and Python into machine language. Each level of programming then requires translation ultimately to Machine Language, as shown in Fig. 2. This begins with Assembly Language, which is converted to Machine Language by the use of an assembler and linker. The linker is not a separate language, per se. It is a necessary step in the process of converting the program, as written by the user, into nybbles to be read by the computer.

    Fig. 2 Relationship between compiler, assembler, machine language, and linker.

    Author’s Note

    Congratulations, you have arrived! This is the greeting that I anticipated when first starting my journey into Assembly Language. Those who came before me learned assembly as their first language. Assembly was a rite of passage. I started programming with Basic, for the Commodore 64. Data Processing Class taught me FORTRAN, RPG II, COBOL, and Pascal.

    There was a thirst for assembly, as some of us undertook manipulation of bits. I inherited a survey program. I was to expand the program so they could ask more questions. However, after pouring over the details in the program, I learned that the original author had taken the Yes/No questions, treated the answers as bit responses and made a single byte hold eight questions worth of binary answers. There would be no easy means of just adding a couple more questions.

    I would not be given the opportunity to learn assembly in detail until my 4th year as a double major in Computer Engineering and Electrical Engineering. We emulated the PDP 11 with our programs. We learned the details of how a microprocessor works. Within this class, we wrote in assembly as we could gain unfettered access to control our micro. When you are seeking control of your processor, there is no better way to control it than to use Assembly Language.

    However you come by this text, you will learn a new way of thinking before you are done. Assembly requires some nominal electrical engineering knowledge, in that you are intimately meshing your code with the operation of the processor. Electronic glue is introduced and fundamental electrical interface circuitry is presented. Usually, this takes the form of communication with a sensor or input from a switch. This is the heart of the microcontrollers’ functionality.

    My approach is to be as thorough as possible, presuming no prior knowledge. Feel free to jump ahead if you have more background than the absolute beginner.

    Dare We Call It Fun?

    A few months back, I had the opportunity to talk with a neurologist. We happened upon a brief discussion of this text when I shared information on my work. He chuckled and then said he had programmed in assembly many years back. He even recalled the use of a rotate function to complete a multiply by two. Wistfully, he said That was fun, really fun stuff.

    In recollection of this exchange, I have pondered this notion. Dare we call it fun? Throughout college engineering courses, I was so wrapped up in getting the next project done. I do not believe that I ever stopped to think of just how much fun I had in this course. I also really enjoyed Digital Logic; a course that I would later teach at a community college. Always remember, a course can be both difficult and fun.

    Enjoy!

    Chapter 1

    Introduction

    Abstract

    This chapter explores practical applications, explains the concept of core families, initiates perusal of the PIC 10F data sheet to locate information, and provides a light introduction to program pseudocode and algorithm development.

    Keywords

    Pseudocode; Algorithm; Program; Development; Core family; Practical; Data sheet; Embedded control; Assembly; Implementation

    Chapter Outline

    Practical Applications

    Why Assembly?

    Core Families (Baseline, Midrange, Enhanced Midrange, High Performance)

    Baseline

    Midrange

    Enhanced Midrange

    High

    Enjoying the preview?
    Page 1 of 1