HCS12 assembly golf program

EE 3170 Programming Assignment 2
Arrays and Control Structures

Problem Speci cation
Golf is one of the world's most popular participant sports. Various sources put the number
of golfers worldwide between 26 and 30 million. Perhaps its popularity has to do with
being one of the few sports which actively supports the consumption of alcoholic beverages
during its play. In any case, people from all over the world of all ages enjoy what Mark
Twain called, a good walk spoiled." (Incidentally, it's also one of the only sports played
o the world too. Astronaut Alan Shepard hit a 6-iron shot that traveled miles and
miles" on the surface of the moon.)
If you are not aware of the basic scorekeeping of golf, here are the basics:
 Each time you hit the ball, that counts as one stroke. The goal is to strike the ball
such that it goes into the hole.
 The course designers have determined how many strokes should be taken, on average,
before the ball is in the hole. This value is called par. This value is determined
primarily by the distance from the tee (where the player starts) to the hole. The
traditional values are 3, 4 and 5. It is assumed in the determination of par for any
given hole that the player will require two putts.
 Completing the hole in fewer strokes is called under par." Taking more strokes is
over par."
 The traditional number of strokes for an 18-hole round of golf is 72. This generally
translates to four Par 3's, four Par 5's and ten Par 4's.
 There are terms for the stroke count, relative to par:
{ 3 under par: Double Eagle
{ 2 under par: Eagle
{ 1 under par: Birdie
{ 1 over par: Bogey
1
{ 2 over par: Double Bogey
 Another relevant metric golfers care about is called Greens in Regulation." Recall
that par assumes that two strokes will be used up putting. If a player's final score
on a hole is less than or equal to par minus 2, it means the player reached the green
in regulation.
 The last metric especially relevant to amateur golfers is their handicap." This is
the di fference between par and the actual score the player achieved. It's always
a positive value, ranging from zero and up. (A zero handicap is referred to as a
scratch" handicap.) Normally the handicap is calculated over several rounds, but
we will calcuate it on a single game.
In this application, we're going to exercise our HCS12 programming skills to analyze
a golfer's scorecard, saved in the device's memory as an array and generate a variety of
statistics and metrics. Speci cally, we will:
1. Calculate the player's final score
2. Calculate the number of Greens in Regulation
3. Populate an array indicating the type of score achieved on each hole
4. Calculate the player's handicap.
Software Requirements
You have been supplied with two files. One is the mostly incomplete program in the file
userid pa2.asm that includes structure to make my task of grading easier and gives a
basic structure for all other programs you might write in this class. You may not alter
the location or names of any variables under any circumstances! Most importantly, do not
modify the #include lines. These lines let me modify the input values for grading. The
other fi le is the TestInput.asm fi le. This file contains the input arrays as well as locations
for storing the results of your analysis. You can feel free to adjust these values to test your
program. I will use di fferent versions of this fi le to grade your program. Do not submit
this file.
Your tasks will be to:
 Write four subroutines to calculate the four statistics. You can use any calling con-
vention you would like. You must use subroutines in this assignment.
 In the main program, call each subroutine in turn, being sure to save the results to
the appropriate labels.
2
Suggested Procedure
Begin by declaring and initializing all the variables you think you will need. The skeleton
code provided only has the minimally required variables. You may fi nd you want/need
more. You can feel free to add them, but do not change any of the predefined variables.
Here's a high-level view of how to calculate each of the four results.
Final Score
Load the address of strokes into the X register. Use a standard loop construct to sum up
all of the values and store the results to the finalScore variable. See Lecture 6 for the
structure of a for loop.
Handicap
Using the final score you calculated previously, simply subtract the value of par. Remember
this should be a positive integer. If the diff erence is actually negative, the handicap should
be set to 0. This will look similar to the safe" subtraction algorithm from Lecture 4.
Greens in Regulation
Pass the fi rst address of both the par array and the putts array to the subroutine. Then,
perform the following:
 Load an element from the par arrray. Subtract 2 to determine what the intended
number of putts is.
 Load the element from the putts array and see if it is less than or equal to the value
calculated in the last step.
 If yes, increase a count of the GIR.
 If not, do nothing.
 Move on to the next hole (or the next element in the array).
When all is done, return the value to the main program.
Score Type
This task will be the hardest, as it requires holding on to the address of three arrays |
unfortunately, we only have two registers that are useful for holding these. Here's a basic
rundown on how to do that.
 Use one of the accumulators to hold onto the loop count.
3
 Load the addresses of the strokes and par arrays into appropriate registers.
 Compare the value at each index of the arrays to determine which type of score
the player achieved (e.g., birdie, bogey). Plan on using accumulator o set indexed
addressing.
 Use some kind of temporary storage to move the strokes or par address out of one
of the registers. Load the rst address of the scoreType array into whichever register
you just vacated. If you continue to use accumulator-o set indexed addressing, you
can save the appropriate character into the slot in the scoreType array.
 Get that rst address back of the array you temporarily moved.
 Increment your count, determine if the loop is over and either quit or do it all over
again.
Grading
There is a point allocation schedule listed below. I will run your program to verify correct
operation. I will run 2 tests on your submission. They will be two sets of scores that
will have all types of scores, including handicaps that need to be normalized to zero. If
everything matches, you get the points. If not, you will receive some portion of the points.
Considerations
When submitting your homework, explicitly answer the following questions:
1. Did you use a fixed location in memory to swap out one array address when calculating the score type? If not, where did you store it temporarily?
2. We can perform indexed addressing using the stack pointer as a base register. Why
is that not an option when calculating the score type?
3. Is it reasonable to assume that all variables in this assignment will be 8-bit values?
Why or why not?
4. What was the hardest part of this assignment?

Deliverables
When submitting your assignment, you must turn in:
 An electronic
flowchart describing the behavior of your program as a PDF.
4
 Electronic, typed answers to the questions posed in the Considerations" section
submitted via Canvas, also as a PDF
 An electronic version of your assembly code, submitted via Canvas
Grading
Points for this assignment will be assigned as follows:
 Flowchart | 5 points
 Successfully assembles | 5 points
 Uses subroutines | 10 points
 Passes test 1 | 20 points (5 points per correct calculated result)
 Passes test 2 | 20 points
 Software Engineering | 5 points. This is largely subjective, based on the quality of
your code. Higher scores in this category will be earned by commenting well, using
meaningful variable and subroutine names and selecting meaningful test cases.
 Consideration Questions | 5 points
5











heres the code you are given





;/************************************************
;| Author: Obi-Wan Kenobi |
;| Program: PA2 |
;| Purpose: |
;| This program does stuff. If you want all 5 pts|
;| for software engineering, you should tell me |
;| what it is. |
;************************************************/

org $1000 ; Variables go here
#include TestInput.asm
; If you need more variables, add them here.

; Test inputs for PA2, EE 3170 Fall 2012
; These scores are from Tiger Woods final round at the 2012 Masters.
; Feel free to change these to test your code. I will run a couple of different tests.
strokes: db 4,4,4,3,5,3,4,6,4,5,4,2,5,4,5,4,5,3
par: db 4,5,4,3,4,3,4,5,4,4,4,3,5,4,5,3,4,4
putts: db 2,1,2,2,1,2,2,2,2,3,2,1,2,2,2,3,3,1

; These are the output values. *Do not change the labels.*
; GIR is the Greens in Regulation value. Just one number between 0 and 18.
GIR: ds 1

; finalScore is the total of all the values in "strokes". Should be between 18 and 255.
finalScore: ds 1

; handicap is the difference between par and finalScore.
handicap: ds 1

; scoreType is populated by ASCII characters indicating the type of score on each hole.
; See the table below for equivalencies.
scoreType: ds 18

; par is just a constant for your convenience.
finalPar: equ 72

; Double Eagle, both a long and short form for your convenience.
DE: equ 'A'
DoubleEagle: equ 'A'
; Eagle
Eagle: equ 'E'
; Birdie
Birdie: equ 'B'
; Bogey
Bogey: equ 'O'
; Double Bogey, long and short form
DB: equ 'D'
DoubleBogey: equ 'D'

org $2000 ; Code goes here
main: lds #$2000
; Add your code after this line.




; You shouldn't need to modify these lines of code either.
; jmp PA2Verifier
;#include PA2Verifier.asm
Finish: bgnd

org $FFFE
dw main
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories