Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
46 views

Assembly Programming Format

tatat

Uploaded by

saadmemon94
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Assembly Programming Format

tatat

Uploaded by

saadmemon94
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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.

Assembly Programming Format:

********************** 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

*SUBROUTINE/INTERRUPT SERVICE ROUTINE A*


****************************************
LABEL OPCODE OPERAND COMMENT

*SUBROUTINE/INTERRUPT SERVICE ROUTINE B*


****************************************
LABEL OPCODE OPERAND COMMENT

.....

*Reference the sample code provided on Page 3 for an example*

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.

Inadequate Comments: It is not necessary to make comments that


describe the opcode
ldy #N ; Put N in Y
loop1 ldx #6259 ; Put 6259 in X
loop2 dex
bne loop2
dey More descriptive labels are easier to
bne loop1 ; Start over follow than generic labels

Adequate Comments:

;The following section of code creates ~100ms delay


ldy #N ; Outer loop (N = 10) to create 100 ms delay
outer ldx #6259 ; Inner loop creates ~10ms delay
inner dex
bne inner
dey This describes exactly what the code is
bne outer ; Continue until Y = 0 supposed to do and why

This label is a little more descriptive than


the generic “loop1” label.

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
.....

*RTI_ISR (RTI Interrupt Service Routine)*


*****************************************
org RTI_ISR
ldaa rtictr ; Get current accumulation count
adda #1 ; Add 1 to the current count
staa rtictr ; Update accumulation counter
suba #$09C4 ; Subtract 2500 from current count
bne rtidone ; If it is not equal to 2500 then...
.....

ECE251 Page 3

You might also like