Pre-Lab 6: Teaching the Bear to Navigate the Maze

Part 1 – Stack Initialization

The stack pointer of the AVR processor is always pointing to the next available location in SRAM to store temporary data. In Lab 2, I moved the stack pointer to the top of memory with the following code snip-it.

ldi r16,low(RAMEND) // RAMEND address 0x08ff
out SPL,r16 // stack Pointer Low SPL at i/o address 0x3d
ldi r16,high(RAMEND)
out SPH,r16 // stack Pointer High SPH at i/o address 0x3e

As your code becomes more complex, the possibility of losing control of the stack becomes a very real possibility, resulting in a stack underflow or overflow condition.

Question 1 What is stack underflow and overflow?

Question 2 In Lab 3A Appendix A Rules for Working with Subroutines, I gave you a few rules to remember when writing your main program and subroutines, which of these rules, if not followed, would result in a stack underflow and/or overflow condition. Explain your answers.

Part 2 – Translating your flowchart from PreLab 1 into an assembly program

Question 3 One of the lab objectives is to see if the bear is in the forest (i.e., home). Your code will accomplish this by checking the row the bear is currently in. The rows and columns of the maze are numbered from 0 to 19 (0x13) starting in the upper left hand corner. When the bear has found his way out of the maze he is in row minus one (row < 0). How would you represent minus 1 in hexadecimal using 2’s complement notation?

Question 4 Translate your flowchart from PreLab 1 into an assembly program. If you were asked to plot a new path through the maze, and have not done so, please see me (lab instructor) as soon as possible. Note that if your path does not go through the target square corresponding to the last four digits of your student ID, you will receive a zero for lab 6. If you are not sure, you are responsible for asking.

In PreLab 1 you designed a flowchart for the WhichWay routine. This flowchart from PreLab 1 used subroutine names for sensor (used in a conditional expression) instructions Hitwall, RightPaw, and LeftPaw and actuator (take some action) instructions TurnLeft, TurnRight, TurnAround, InForest and CountBees. By the end of lab 3 most of these were no longer names, but working assembly subroutines. Working from your PreLab 1 flowchart, and incorporating calls to these subroutines, write an assembly program to implement the flowchart.

For help read Lab 6A which shows you how to translate the shortest path flowchart into an assembly program.

What Should I Turn In?

Turn in the following material three pages. Make sure all your original work is in your Lab Notebook. All written material must be typed or very neatly done in ink. Once again please do not copy.

Page

  1. Title page with the pre-lab number, your name, today’s date, and the day your lab meets.
  2. Answers to the four questions. Do not forget to summarize the question and highlight your answers.
  3. Your approved flowchart from Prelab 1.
  4. Your WhichWay subroutine. This may be done in AVR Studio (recommended).