You are on page 1of 6

Department of Computer Science, University of Adelaide

Computer Systems Practical 2 Microwave oven controller


David Knight

Aim

The aim of this practical is for you to practice dealing with control structures at the machine level. We will be using again the DLX assembler (dasm) and the simulator (dsim), but this time we will create a relocatable program. Your task for this practical is to develop an assembly language program to control a microwave oven. Our oven is similar to one you might have used at home, except that it probably has fewer features. Once again, we expect you to use the SVN version control system as you develop your program. The instruction for creating the required repository are on the web-site.

The microwave oven device

The oven is controlled through four registers: ovenKey, ovenDsp, ovenCtrl, and ovenT mr.

2.1

The ovenKey register

A bit is set in the ovenKey register whenever a button on the keypad is pressed. Reading the register causes all the bits to be cleared. The bits are arranged as follows:
31 15 14 door 13 stop 12 start 11 10 9 9 8 8 7 7 6 6 5 5 4 4 3 3 2 2 1 1 0 0

For example, if the 4 key is pressed, the register will contain the value 16#00000010. If the door key is pressed, the register will contain 16#00004000. Note that it is possible for more than one bit to be set. This will occur if the user is able to press two or more keys before the program reads the ovenKey register.

2.2

The ovenDsp register

Bits in the ovenDsp register control the display on the oven. There are four digits on the display, and each digit is controlled by a byte in the ovenDsp register, like this:
31 24 23 16 15 8 7 0

Left-most digit

next digit

next digit

Right-most digit

Each digit of the display is a seven-segment display, with a decimal point. The segments are (traditionally) named a to g, as shown in the diagram below. The program has control of each individual segment, so it is possible to display numbers, some letters, and a few other characters by illuminating appropriate segments. Each bit in the byte for a digit controls one segment. Setting a bit to one illuminates that segment of the display. Within each byte, the bits are arranged like this:

f g 7 dot 6 g 5 f 4 e 3 d 2 c 1 b 0 e a d c

dot

For example, storing the value 16#0000005B in the register will cause it to illuminate segments a, b, d, e, and g, of the right-hand digit, thus displaying 2. Storing 16#06DB4F66 will display 12.34.

2.3

The ovenCtrl register

The ovenCtrl register contains bits that control the remaining oven hardware:
31 4 3 door lock 2 magne tron 1 light 0 turn table

You can enable the turntable motor (to rotate the food), turn on the interior light (so you can see), enable the magnetron (the microwave generator that cooks the food), and unlock the door. For example, storing the value 16#00000003 in the ovenCtrl register will turn on the light, and cause the turntable to rotate.

2.4

The ovenTmr register

The ovenT mr register contains a bit that is set to one every 200 milliseconds by the oven hardware.
31 8 7 tick 6 0

This enables your program to time the cooking-cycles. Whenever you read the ovenT mr register, the timer bit is automatically cleared to zero.

Memory available for your program


Addresses FFFFFFFF to FFFFFF30 FFFFFF2C FFFFFF28 FFFFFF24 FFFFFF20 FFFFFF1F to 00007E00 00007DFF to 00007D00 00007CFF to 00002000 00001FFF to 00000000 Contents Non-existent memory OvenTmr register OvenKey register OvenDsp register OvenCtrl register Non-existent memory

The memory map of the computer system you are using is given in the diagram to the right. You will need this information to make your program work correctly on the dsim simulator we have provided. If you attempt to execute a load or store instruction that refers to an address in the regions marked non-existent memory, the dsim simulator will stop, and report a non-existent memory error. Obviously, regions marked Read-only memory cannot be used to store data!

Random-access memory

Non-existent memory

Read-only memory

Finite state machines

Computer systems that are hidden inside items of electronic equipment are known as embedded systems, and the programs for such systems are usually best designed as Finite State Machines (FSMs).
Initialise: scaler= 5 timer= 0 stop-button

tick: timer++

stop-button: scaler= 5 timer= 0

stopped

running

start-button

Figure 1: The stopwatch nite state machine We have provided an example program that behaves as a simple stop-watch. The state-diagram for the stopwatch is shown in g. 1. When the machine starts, it enters the stopped state, and displays the timer (which is initialised to zero). When the user presses the start button, the machine transitions to the running state. In the running state, the machine regularly updates the timer. When the stop button is pressed, the machine transitions back to the stopped state. If the stop button is pressed when the machine is in the stopped state, the timer is cleared to zero.

4.1

Running the stopwatch program

The stopwatch program is in a le named stopwatch.dls. You will also need the le named stopwatch.dla. You can assemble the program with the command: dasm -r stopwatch Notice that this is a relocatable assembly. You can relocate the program with the command: dloc -m stopwatch You are now ready to execute the program using dsim. If you click on the oven show button, and select Oven controls, you will see the buttons and the display, and will be able to operate the stopwatch. If you take the time to understand how this program works, you will nd that writing the oven program mostly involves translating the state diagram in g. 2.

What must the oven program do?

The behaviour of the oven can be described by the nite-state machine diagram shown in g. 2. Your program must work like a normal microwave oven! In particular: When the oven is rst started, it must display idlE. This indicates that the oven is ready. To enter a cooking time, simply press the number keys. If you keep on pressing number keys, the display shows only the last four keys you pressed. Your program must suppress leading zeros from the display (i.e. show the number 12 as 12, not 0012). To clear the displayed value, press the Stop/Clear key, and the display will return to idlE. To start cooking the food, press the Start key. Your program must cause the turntable to rotate, the interior light to be turned on, and the magnetron to be activated. While the timer value is non-zero, your program should decrement the displayed value once each second. When the timer reaches zero, your program must stop the turntable, and turn o the magnetron. The display must then show the word bEEP for three seconds, then turn o the light and return the display to idlE. If you press the Stop/Clear button during cooking, your program must stop the turntable, and turn o the magnetron. The light must remain on, and the timer should hold its present value. If you press the Stop/Clear button a second time, your program must clear the timer, turn the light o, and return the display to idlE. If instead you press Start, your program should resume cooking at the current timer setting.

Initialise: cookTime=0 door-button digit-button: append to cook-time Idle

IdleOpen

door closed

stop-button start-button & cookTime>0

door-button

15 ticks

tick & cookTime==0 Beeping Run

stop-button

Hold

start-button tick & cookTime>0: cookTime-door-button

door-button

door closed

HoldOpen

Figure 2: The oven nite state machine

If you press the Door button, when the oven is idle, your program should unlock the door, turn on the light, and display door on the display. When the door is closed again (by clicking on the door with the mouse), your program should turn o the light, and display idlE. If you press the Door button during a cooking cycle, your program must turn of the magnetron, stop the turntable, unlock the door, and display PAus. (The value of the timer must be preserved.) When the door is closed again, your program should display the value of the time remaining, and leave the light on. Cooking can be resumed by pressing the Start button, or ended by pressing the Stop/Clear button.

What do we give you?

We have provided a source le, skeleton.dls, that contains denitions of a few useful symbols. Copy this le to your directory and call it prac2.dls. We have also provided the le dsim.cfg. You will need this le to congure dsim to include the oven device. Copy it into the directory you are using for this practical exercise. Notice that this dsim.cfg is not the same as the one used for prac1.

Requirements for a relocatable program

You must write a relocatable program. To do this, you will need to put .seg directives in your program, and create a relocation address le, called prac2.dla, for the relocater. Documentation on the relocater is in Appendix E of the notes. Place all DLX machine instructions in a segment named code. Place all constant data used by your program in a segment named const, and all remaining data in a segment named data.

Writing your Program


1. Develop some subroutine(s) for driving the display. Test your program by displaying simple values on the display. To ensure that the digits displayed by your program will be the same as those expected by the tester, we have provided a subroutine dspHex that converts a binary number into the corresponding segment pattern. Make sure you understand how it works! 2. Develop subroutine(s) to look after the keypad. Test your subroutines by writing a trivial main program that reads in a key, and displays its key-value on the display. 3. Write the code for controlling the microwave oven itself, but omit the timer functions. Do not write all the code at once, but rather code, test, and rene your program, a little at a time, until the microwave oven performs as described in the state-diagram. Hint: You will need to think very carefully about how to store the timer value. If you make a bad decision, your oven will not be able to keep correct time, because the program will be too slow. Choose your representation so that each of the operations you need to do with the timer is fairly simple to perform. (These are, of course, exactly the same guidelines for designing a class in a high-level language.) 4. Write the code to handle the timer, add it to your microwave oven, and test it thoroughly. 5. Thats it! You are ready to hand in your program.

We suggest the following major development steps:

Working at home

You will need to copy the le dsim.cfg into your working directory to congure dsim to include the microwave oven and memory. If you are working at home, you will need to down-load the dloc.jar le from the CS tools web-page.

10

Hints on using dasm, dloc, and dsim

You will nd the listing le produced by dasm is vital in helping you to debug your program. You can display it in another window on the screen, so you can see where you are during debugging. The location map produced by dloc will also be essential to allow you to debug your program, since it shows where each segments has actually been loaded, and thus allows you to nd where your data is actually stored in memory. The breakpoint facility of dsim is very useful in this practical exercise, since your program is eectively executing in an innite loop. You can use breakpoints to stop your program at places of interest during debugging. The DLX tutorial (available on the tools page) can be down-loaded, and shows how breakpoints are used.

11

Handing in your program

When you have completed and tested your program, hand it in for assessment. Submit your program using the web-handin system with the key 12s1-cs-prac2. Please note: The web-handin key will NOT be available until Saturday 5th May. We want you to test your own program thoroughly rst!

12

Assessment

Marks will be awarded for clear and well-formatted code, and for intelligible and concise comments (5 marks total). While you write your program, put yourself in the position of another programmer who needs to understand what you have written and how it works. This should guide you in working out how to format and comment your program. The bulk of the marks will be awarded for getting the program to work properly (20 marks). We will use an automatic test procedure to verify that your program produces the correct results. The test script is very throrough...

You will lose marks if your program displays messages that are dierent from those specied in the description above. For example, if you display 0012 instead of 12. It is possible for a single error to cause you to fail several consecutive tests x early errors before later ones! Deadline: You should hand in your program by midnight Sunday 13th May. Start work as soon as you can!

You might also like