PURPOSE
Now that you’ve spent some time walking through some assembly given to you and familiarizing yourself with the CodeWarrior tool … it’s time to try coding something on your own. In this assignment, you’ll be spending some time examining some assembly (to calculate execution times) and then you’ll be creating a project which will implement a small “C” program.
OBJECTIVE
This assignment will make you familiar with:
- Looking up and reading the instruction sheets for the 6808 – to determine clock cycles, addressing modes, …
- The craft of taking code developed in the C programming language and implementing it in 6808 assembly through proper assembly code design practices (i.e. through the use of developing and calling subroutines)
SUBMISSION GUIDELINES
PLEASE READ AND UNDERSTAND THE SUBMISSION GUIDELINES BELOW. FAILURE TO CORRECTLY SUBMIT ANY REQUIRED COMPONENT WILL RESULT IN 20% PENALTY PER MISSING OR INCORRECT COMPONENT.
WHAT TO SUBMIT
Your report-like submission will include the 2 required tables for Question 1 as well as a nicely formatted (and commented) copy of your source code for Question 2. If your code is not in your document, it will not be marked.
Submit your report document as well as a ZIP file containing your CodeWarrior 6808 Project (from Question 2) into the eConestoga assignment submission folder by the posted deadline.
Ensure your name is included at the top of your assignment, as shown in the template at the end of this document.
Please use the template sheet supplied at the end of this document – be sure to include your name and student number. IF YOU DO NOT USE THE PROVIDED FORMAT, YOU WILL RECEIVE A 40% PENALTY.
DO NOT SUBMIT THIS ASSIGNMENT SPECIFICATION AS A PART OF YOUR DOCUMENT OR YOU WILL GET ZERO.
PAPER SUBMISSION
There is no paper submission required for this assignment.
ELECTRONIC SUBMISSION
Exactly TWO items will be submitted electronically.
- Upload your complete assignment document as a SINGLE document in PDF format.
- Upload a zip of your complete CodeWarrior project
All files should be named with your user ID – if your email is [email protected], the file name must be
jsmith1234_a5.pdf and jsmith1234_a5.zip. Please note – changing the extension of a file does not make it a PDF. Do not put your document inside your zip file.
QUESTION 1
Using the information contained in Table 4-10 (page 50) of the “All about the HCS08 (6808) Instruction Set, Registers, Addressing Modes, Execution Times, etc.” document in Module-06 of eConestoga. Using the code provided below (which you may recognize from the examples in Module-07) – please create:
A table (labeled Table 1.1) showing the
- mnemonic/instruction
- the addressing mode in use for that instruction
- the number of clock cycles to execute the instruction
A second table (labeled Table 1.2) showing the
- event
- total number of clock cycles
- elapsed wall-clock time in seconds to execute (remembering that the 6808 we are using is clocked at 16 kHZ)
o please calculate the elapsed wall-clock time to 5 decimal places (round if necessary)
Where the events in Table 1.2 are given as:
- EVENT-1 : Execute the IOSetup region of code once
- EVENT-2 : Execute the MainLoop region of code once
- EVENT-3 : Execute 10 iterations of the MainLoop region of code (as executed from the start of the program)
Code to Analyze
main:
_Startup:
IOSetup:
| CLRA | ; special instruction to load a ZERO value into A |
| STA $03 | ; configure PORT A data direction (all bits INPUT) |
| LDA #$FF | ; enable pull-up (all bits have pull up enabled) |
| STA $01 | ; configure PORT A pull ups |
| STA $43
MainLoop: |
; configure PORT F data direction (all bits OUTPUT) |
| LDA $00 | ; read switches – upper nibble holds switch values! |
| NSA | ; get upper 4 bits to lower 4 bits |
| STA $40 | ; write to the LEDs |
| JMP MainLoop | ; repeat forever! |
QUESTION 2
Transform the following “C” program into assembly for the 6808 Microcontroller.
- Remember when converting this “C” code to follow best practices covered in DEF in terms of implementing subroutines in assembly o This means that parameters are passed on the stack to subroutines o Return values are passed back on the stack
o You clean up the stack after every use (every subroutine call) to prepare it for the next call
Keep in mind that once your translated this program into assembly – you can step through it to ensure that it behaves correctly and calculates the expected results.
/* ————————————————————- PURPOSE: This program will take 2 operand values and calculate the sum and difference of the values
————————————————————- */
// This function calculates the sum of 2 operands called “A” and “B”
Int calculateSum(int A, int B)
{
return (A + B);
}
// This function calculates the difference between 2 operands by negating B and adding it to A int calculateDifference(int A, int B)
{ return (calculateSum(A, -B)); // You MUST reuse the calculateSum function!! }
void main(void)
{
int firstOperand = 18; // to be stored at address $80 within the 6808 int secondOperand = 8; // to be stored at address $81 within the 6808 int sum = 0; // to be stored at address $84 within the 6808 int difference = 0; // to be stored at address $86 within the 6808
// call the calculateSum function in order to calculate the total
// and store it in the “sum” variable sum = calculateSum(firstOperand, secondOperand);
// call the calculateDifference function in order to calculate the
// difference and store it in the “difference” variable difference = calculateDifference(firstOperand, secondOperand);
}
SENG1040 – ASSIGNMENT 5
<< Your registered name here >>
TABLE 1.1
<< Place table 1.1 here >>
TABLE 1.2
<< Place table 1.2 here >>
QUESTION 2
<< Place the nicely formatted 6808 assembly code for question 2 here >>


