Pre-Lab 5: Add Bees to the Maze
Up to this point you have worked with an illustration of the maze. To describe a room you have had to manually enter the room number.
In this lab you will begin working with an encoded version of the maze located in a look-up table.
The green numbers across the top and right side of the encoded maze correspond to the columns and rows of the maze. Each entry in the table defines the room at that row and column address. The definition of the room, corresponds to the switch positions you have been manually entering up to this point in the course. For example; after taking his first step, the bear is in the room at column address 0016 and row address 1316. Looking at our maze (Figure 2), we see at these coordinates is a room with only a west facing wall. The Programmer’s Reference Card (see Figure 3), tells us that a room with only a west facing wall is encoded as 01002 = 0x04. Looking at the first entry in the last line of the table, we see our room encoded as 0x04.
Each entry in the maze only requires the least significant nibble (4 bits) of each byte in the table. In this table you will be updating the table to include the bees in the maze. For example, room 0x09 at coordinates row = 13, column = 3 has three 2 bees in it (see Figure 1). To include these bees in our table we would change the entry from 0x09 to 0x29.
You can find a text version of the maze with rooms named maze.inc here. Open this maze in notepad or AVR Studio and add the number of bees as defined in Figure 1.
For the following questions, refer to your textbook as well as lecture 13-1 on “Addressing Indirect.”
Question 1
The following code is used to initialize the Z pointer for indirect addressing:
ldi ZH, high(table<<1)
ldi ZL, low(table<<1)
- Why are two registers required to initialize the pointer to the correct address?
- If the address for the start of “table” is at 0x0A2C and the data that is saved at that flash address is 0x49 and 0x8A, what will the value in the Z register be (for ZH and ZL) after the two lines of code are executed? Explain.
- What does the expression table<<1 represent? Describe what action is taken or what it does with the example values from part b.
Question 2
table: .DB 0b01000001 0b01100000 0b00100011 0b00000001
After initializing the z pointer to the start of “table,” the following code is executed:
clr r1
add ZL, r0
adc ZH, r1
lpm r16, Z
- If the value in r0 is 0x03, and the beginning address for “table” is 0x00D7, what is the value that is in ZH and ZL?
- According to the code above, where is the data being loaded to (the destination for the data) in the lpm instruction?
What Should I Turn In?
Turn in the following material two pages.
Page
- Title page with the pre-lab number, your name and picture, today’s date, and the day your lab meets.
- Your Maze.inc file with modified cells highlighted.
- Problem statements and answers for questions 1 and 2.