Assembly Programming Format
Assembly Programming Format
Objective:
The purpose of this handout is to set a standard assembly language programming format for you
to follow this semester. This will not only make the labs easier to grade and follow, but will also help
prevent simple and common software bugs that can otherwise be difficult to detect.
********************** Note:
*Student's Name *
*Date * You are not required to include sections
*Lab # - Lab Title *
that are not used in your program. For
*Program Description *
********************** example, you will not need the INCLUDES
section for the first several assignments.
*INCLUDES*
**********
INCLUDE “FILENAME”
*SYMBOL DEFINITIONS*
********************
LABEL DIRECTIVE VALUE COMMENT
*DATA STORAGE*
**************
LABEL DIRECTIVE VALUE COMMENT
*MAIN PROGRAM*
**************
LABEL OPCODE OPERAND COMMENT
.....
ECE251 Page 1
Programming Comments:
Providing informative and descriptive programming comments in your code is not only good
programming practice, but essential for other programmers to understand your code. Comments also
are a great way to self-check the correctness of your code. Informative and descriptive comments
should act as pseudo code and describe the purpose or action of a particular section of code. Below are
two examples of adequate and inadequate comments.
Adequate Comments:
Programming Tips:
When writing a subroutine that performs a series of operations, it is often useful to place a new
line between each sub-operation. This will become more apparent when your programs are
several pages of code and will also allow you to write a brief comment description of that block
of code.
When writing a subroutine, consider if it might be useful in other programs. Reusability of code
can save you a considerable amount of time. For instance, writing a subroutine to convert a two
byte hex digit to a BCD equivalent could be useful in other programs and it might be better in
the long-run to pass parameters to the subroutine instead of using hard-coded parameters for
that specific application.
Descriptive and Informative Comments!!! It can’t be said enough, but commenting and
documenting your code appropriately will be a life-saver! It is very common for a student who
didn’t document appropriately to spend hours searching for a bug that was as simple as a single
instruction change!
ECE251 Page 2
Example Code:
*************************************************
*John Doe *
*1/1/2000 * It is not important that you understand this
*Lab 11 - PWM BLDC Motor Speed Control * code at this point in time. The important
*The following program will speed control a 12V * take-away is the programming format and
*BLDC motor via a PWM control signal to a quad * flow of code.
*half-H driver (SN754410) using a simple PI *
*control strategy. *
*************************************************
*INCLUDES*
**********
NOLIST
#include "9S12CREG.inc" ; Register symbols
LIST
*SYMBOL DEFINITIONS*
********************
DATASTORE equ $0780 ; Data Storage
MAIN equ $0800 ; Main Program
RTI_INI equ $0900 ; Real Time Interrupt Initialization
TIM_INI equ $0980 ; Timer Module Initialization
RTI_ISR equ $0A00 ; Real Time Interrupt Service Routine
.....
*DATA STORAGE*
**************
org DATASTORE
dspeed ds.w 1 ; 2 byte speed setpoint storage
rtictr ds.b 1 ; 1 byte interrupt accumulations storage
spdmsg dc.b "Input desired speed (RPM):",$04 ; Input message
.....
*MAIN PROGRAM*
**************
org MAIN
lds #TOS ; Initialize stack
clr rtictr ; Clear the RTI accumulation counter
jsr RTI_INI ; Initialize RTI
.....
ECE251 Page 3