You are on page 1of 6

Digital Engineering Fundamentals

Assignment 7

Purpose
In this lab, youll be spending some time analyzing some assembly and then youll be creating a project which will
implement a C program that does math tricks.

You can choose to do this exercise with a partner if you wish or you can do it on your own.

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

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. Please ensure that the name(s) of the people who worked on
the assignment are found on the title page of the hardcopy submission.

Submit your report document as well as a ZIP file containing your CodeWarrior 6808 Project (from Question 2) into
the eConestoga dropbox no later than 2:00pm (i.e. end of the last lab) on the due date. As well, you will submit a
hardcopy (print out) of your Assignment answers by the same time. If you are doing this assignment with a partner,
only one hardcopy is necessary but please ensure that both partners names are on the document. Please use the
following ZIP file naming scheme when submitting your code:

If you did the assignment alone then name the ZIP file <lastname>-<firstname>-ALONE.zip
o e.g. SMITH-JOHN-ALONE.zip
If you did the assignment with a partner, then include both partners full names in the ZIP file name
o e.g. SMITH-JOHN-JONES-PETER.zip (where John Smith and Peter Jones worked on it together)
o only one of the partners needs to submit the ZIP file

Fall 2015 Due: Dec 11, 2015


Page 1 (by 2:00pm End of the last Lab)
Digital Engineering Fundamentals
Assignment 7

Question 1
Using the information contained in Table 4-10 (page 50) of the 6808 instruction manual in Module-07 of eConestoga. Using the code provided below
(which you may remember as an example used in Module-08) please create:

A table (labeled Table 1.1) showing the


mnemonic/instruction
the instruction argument (if any)
the addressing mode in use for that instruction
o If the mnemonic is accessing memory remember to ask yourself where in the 6808s memory is the argument located
o This will help you determine the addressing mode in use
o You may want / need to refer to the 6808s memory map on Slide 12 of Module-08 to do this effectively
the op-code for the instruction
the number of clock cycles to execute the instruction
the assembled instruction for (including op-code and argument)

Complete the information in this table for LINE-02, LINE-03, LINE-06, LINE-10, LINE-14, LINE-19 and LINE-21 of the following code. This table
will look similar in format and content to those shown in Module-09 on slides 13, 14, 15 and 16.

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 6 decimal places (round if necessary)

Where the events in Table 1.2 are given as:


EVENT-1 : Execute the convCelsius subroutine once
EVENT-2 : Execute the mainLoop region of code once (i.e. do one complete Celsius to Fahrenheit conversion)

NOTE: In order to do these calculations youll need to analyze all of the lines of code as to their addressing mode and # of clock cycles, but all
you need to record in Table 1.2 are the items requested above.

Fall 2015 Due: Dec 11, 2015


Page 2 (by 2:00pm End of the last Lab)
Digital Engineering Fundamentals
Assignment 7
Code to Analyze
; variable, constant and data section
CELSIUS_TEMP: EQU $80 ; temperature to convert is at address $80
ANSWER: EQU $100 ; where to store the answer

LINE-01 ; this subroutine is called in order to convert a Celsius temperature to Fahrenheit


LINE-02 0x1000 convCelsius: PSHA ; why should we push the current accumulator value onto the stack ?
LINE-03 0x1001 LDA 4, SP ; load the Celsius temperature into the accumulator
LINE-04 ; going to index 4 on the stack ?
LINE-05 0x1003 ASLA ; shift 1 bit to the left what does this do ?
LINE-06 0x1004 ADD #32 ; add 32 to the value in the accumulator
LINE-07 0x1006 STA 4, SP ; well return the Fahrenheit value on the stack in the
LINE-08 ; same place as the Celsius value came in why ?
LINE-09 0x1008 PULA ; pop the saved A value off the stack
LINE-10 0x1009 RTS ; return to where we came from
LINE-11
LINE-12
LINE-13 main:
LINE-14 0x2000 mainLoop: LDA CELSIUS_TEMP ; get the temperature to convert into the accumulator
LINE-15 0x2002 PSHA ; push numerator onto the stack to be used in subroutine
LINE-16 0x2003 CLRA ; zero out the accumulator to make a point
LINE-17 0x2004 JSR convCelsius ; call the routine
LINE-18 0x2007` PULA ; pop the Fahrenheit temperature off the stack and
LINE-19 0x2008 STA ANSWER ; store it into memory where it is supposed to be stored
LINE-20 ; any clean up to do on the stack ??
LINE-21 0x200B BRA mainLoop

Fall 2015 Due: Dec 11, 2015


Page 3 (by 2:00pm End of the last Lab)
Digital Engineering Fundamentals
Assignment 7

Question 2
At the end of this document some C source code. Transform the program from the C code 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

NOTES:
1. You may be able to re-use some of your assembly code from Assignment 06 here like I say in SEF, code re-use is a good thing!
2. 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. Try executing your assembly program with different starting values
3. Remember to properly comment your final assembly code (with header comments and line comments if you like, you can re-use the
comments that Ive provided in the C program! Comment re-use who ever thought of that ?!? )
4. In your hardcopy submission format your final commented assembly code as I did in the sample code from Question 1.

Fall 2015 Due: Dec 11, 2015


Page 4 (by 2:00pm End of the last Lab)
Digital Engineering Fundamentals
Assignment 7

#include <stdio.h>
#include <string.h>

// some prototypes of functions found below main() in this source module


int squareIt(int numToSquare);
int addThem(int numOne, int numTwo);
int divideNumOneByNumTwo(int numOne, int numTwo);

/* =======================================================================================
The purpose of this program is to perform a "magical" number trick ...

Tell someone to pick a random number between 1 and 15 and you will get
them to do some simple math using that number ... at the end of the trick,
you will tell them what number they ended up at. The answer will ALWAYS be
3!!

The steps to the trick are:


1) Get them to pick a random number between 1 and 15 (let's refer to this as X)
2) Get them to square X
3) Now tell them to add X to the answer from (2) above
4) Now tell them to divide the answer from (3) above by X
5) Now get them to add 17 to the answer from (4) above
6) Now get them to subtract X from the answer from (5) above
7) Finally - have them divide the answer from (6) above by 6

ANSWER: 3!!!
====================================================================================== */
void main(void)
{
int originalSecretNumberPicked = 8; // choose number between 1 and 15 - found at $80 in the 6808
int intermediateCalc = 0; // if you want / need to store this number - place it at $81
int finalAnswer = 0; // store the final result at $84 in the 6808

intermediateCalc = squareIt(originalSecretNumberPicked);
// STEP 2
intermediateCalc = addThem(intermediateCalc, originalSecretNumberPicked); // STEP 3
intermediateCalc = divideNumOneByNumTwo(intermediateCalc, originalSecretNumberPicked); // STEP 4
Fall 2015 Due: Dec 11, 2015
Page 5 (by 2:00pm End of the last Lab)
Digital Engineering Fundamentals
Assignment 7
intermediateCalc = addThem(intermediateCalc, 17);
// STEP 5
intermediateCalc = addThem(intermediateCalc, -originalSecretNumberPicked); // STEP 6

finalAnswer = divideNumOneByNumTwo(intermediateCalc, 6);


// STEP 7

// is your answer 3 ?!?! Pick another starting number and try again ...

/* -------------------------------------------------------- */
/* The following three functions are simple supporting */
/* mathematical functions - for SQUARING a number, ADDING */
/* two numbers together and DIVIDING one number by another */
/* -------------------------------------------------------- */
int squareIt(int numToSquare)
{
return(numToSquare * numToSquare);
}

int addThem(int numOne, int numTwo)


{
return (numOne + numTwo);
}

int divideNumOneByNumTwo(int numOne, int numTwo)


{
return (numOne / numTwo);
}

Fall 2015 Due: Dec 11, 2015


Page 6 (by 2:00pm End of the last Lab)

You might also like