You must do every programming assignment by yourself. You are permitted to get help ONLY from the TAs and the instructor. When you have completed the program, and tested it sufficiently so that you are comfortable that it works on any input (i.e., values initially stored in the arrays starting in x3100 and x3200), submit it for grading according to the submission instructions at the end of this handout.
Scheduling a room on campus
In this assignment, you will write a program to schedule access to a particular room on campus. The room is available to the public only on Saturdays but is available for the entire day (i.e. for all 24 hours on Saturday). Throughout the week, users who wish to reserve the room submit a request through a online reservation system. The reservation system then encodes each request into a 16-bit word:
So 01101 10011 100101 would represent a request from user 37 for the room from 13:00 (1:00pm) to 19:00 (7:00pm). Note that with our scheme, the start and end times of a reservation have to be at hourly boundaries (e.g. you cannot book a room just from 1:00pm to 1:30pm).
Requests for the room are accepted throughout the week, Sunday through Friday. During the day, incoming requests for the room are stored into an array starting at memory location x3200. The requests in the array are ordered by time of request reception, so the request at location x3200 was received before the request at location x3201, which was received before the request at location x3202, and so on. The end of the array is marked by the special value x0000.
The current state of the room is stored in an array starting at memory location x3100. The 24 memory locations starting from location x3100 represent the existing reservations for the room: location x3100 holds the ID of the user occupying the room from 00:00 to 01:00; location x3101 holds the ID of the user occupying the room from 01:00 to 02:00, and so forth. Location x3117 will hold the ID of the user occupying the room for the last time slot, 23:00 to 24:00 (note: 24:00 is 00:00 of the next day). If a room is available (i.e. unbooked) for a given hourly slot, then the memory location for that slot will simply contain the value x0000. For example, if memory location x3104 contained the value x0000, then this means the slot from 04:00 to 05:00 is available. Remember we restricted the range of valid user IDs from 1 to 63, so we can safely use the value x0000 to denote an available time slot. Note that there may already be reservations in place (from previous days) before you even begin to process requests for today; that is, you *cannot* assume that the memory locations x3100 through to x3117 will all initially contain x0000.
Your job: At the end of the day, your program will run and process through all the received requests for that day, starting in order from the earliest request at location x3200. For each request, your program will check if the request conflicts with any existing reservations for the room. If any of the requested time slots is already taken by another user, then the entire request is ignored and you move on to the next request; otherwise, if there is no conflict (meaning all the requested time slots are either unoccupied or occupied by the same user making the request), then the array starting at location x3100 is updated to reflect the new state of the room after the reservation. Once your program has processed all the requests and updated the array at x3100 accordingly, it should halt. Your program will start at location x3000 as usual.
For example, if the initial state of the room is as follows:
Address | Value | Meaning |
x3100 | x0000 | 00:00 to 01:00 unoccupied |
x3101 | x0000 | 01:00 to 02:00 unoccupied |
x3102 | x0000 | 02:00 to 03:00 unoccupied |
x3103 | x0000 | 03:00 to 04:00 unoccupied |
x3104 | x0001 | 04:00 to 05:00 occupied by user 1 |
x3105 | x0001 | 05:00 to 06:00 occupied by user 1 |
x3106 | x0000 | 06:00 to 07:00 unoccupied |
x3107 | x0000 | 07:00 to 08:00 unoccupied |
x3108 | x0000 | 08:00 to 09:00 unoccupied |
x3109 | x0000 | 09:00 to 10:00 unoccupied |
x310A | x0000 | 10:00 to 11:00 unoccupied |
x310B | x0000 | 11:00 to 12:00 unoccupied |
x310C | x0000 | 12:00 to 13:00 unoccupied |
x310D | x0000 | 13:00 to 14:00 unoccupied |
x310E | x0000 | 14:00 to 15:00 unoccupied |
x310F | x0000 | 15:00 to 16:00 unoccupied |
x3110 | x0000 | 16:00 to 17:00 unoccupied |
x3111 | x0002 | 17:00 to 18:00 occupied by user 2 |
x3112 | x0000 | 18:00 to 19:00 unoccupied |
x3113 | x0000 | 19:00 to 20:00 unoccupied |
x3114 | x0000 | 20:00 to 21:00 unoccupied |
x3115 | x0000 | 21:00 to 22:00 unoccupied |
x3116 | x0000 | 22:00 to 23:00 unoccupied |
x3117 | x0000 | 23:00 to 24:00 unoccupied |
Then this means that the room is occupied by user 1 from 04:00 to 06:00, and by user 2 from 17:00 to 18:00. All other time slots are available and unoccupied.
Now, given the following requests starting at location x3200, the results are shown:
Address | Value | Description | Results |
x3200 | 00101 00111 000011 (x29C3) | User 3 wishes to reserve from 05:00 to 07:00 | Ignored because 05:00 to 06:00 already occupied by user 1 |
x3201 | 00111 01001 000011 (x3A43) | User 3 wishes to reserve from 07:00 to 09:00 | Succeeds because 07:00 to 09:00 is unoccupied; locations x3107 and x3108 set to x0003 |
x3202 | 01010 10100 000100 (x5504) | User 4 wishes to reserve from 10:00 to 20:00 | Ignored because 17:00 to 18:00 already occupied by user 2 |
x3203 | 10001 10100 000010 (x8D02) | User 2 wishes to reserve from 17:00 to 20:00 | Succeeds because 17:00 to 18:00 is occupied by the same user making the request (user 2), and because 18:00 to 20:00 is unoccupied; locations x3111 through x3113 set to x0002 |
x3204 | 10100 11000 000100 (xA604) | User 4 wishes to reserve from 20:00 to 24:00 | Succeeds because 20:00 to 24:00 is unoccupied; locations x3114 through x3117 set to x0004 |
x3205 | 00000 00000 000000 (x0000) | end of requests | - |
The array at x3100 is now:
Address | Value | Meaning |
x3100 | x0000 | 00:00 to 01:00 unoccupied |
x3101 | x0000 | 01:00 to 02:00 unoccupied |
x3102 | x0000 | 02:00 to 03:00 unoccupied |
x3103 | x0000 | 03:00 to 04:00 unoccupied |
x3104 | x0001 | 04:00 to 05:00 occupied by user 1 |
x3105 | x0001 | 05:00 to 06:00 occupied by user 1 |
x3106 | x0000 | 06:00 to 07:00 unoccupied |
x3107 | x0003 | 07:00 to 08:00 occupied by user 3 |
x3108 | x0003 | 08:00 to 09:00 occupied by user 3 |
x3109 | x0000 | 09:00 to 10:00 unoccupied |
x310A | x0000 | 10:00 to 11:00 unoccupied |
x310B | x0000 | 11:00 to 12:00 unoccupied |
x310C | x0000 | 12:00 to 13:00 unoccupied |
x310D | x0000 | 13:00 to 14:00 unoccupied |
x310E | x0000 | 14:00 to 15:00 unoccupied |
x310F | x0000 | 15:00 to 16:00 unoccupied |
x3110 | x0000 | 16:00 to 17:00 unoccupied |
x3111 | x0002 | 17:00 to 18:00 occupied by user 2 |
x3112 | x0002 | 18:00 to 19:00 occupied by user 2 |
x3113 | x0002 | 19:00 to 20:00 occupied by user 2 |
x3114 | x0004 | 20:00 to 21:00 occupied by user 4 |
x3115 | x0004 | 21:00 to 22:00 occupied by user 4 |
x3116 | x0004 | 22:00 to 23:00 occupied by user 4 |
x3117 | x0004 | 23:00 to 24:00 occupied by user 4 |
Hints:
Submit your Program:. Read the submission instructions and follow the Updating Your submission Directory instructions to obtain a "project2" directory for your programming assignment 2. The program you submit is the .asm file. Save your .asm file, and give it the name "schedule.asm". "schedule.asm" should be saved inside your project2 directory. When you feel you are ready to submit your assignment, follow the Submitting Your Program instructions to upload your schedule.asm file for grading.