CS 61 – Programming Assignment 5

CS 61 – Programming Assignment 5

A. What bit mask value and what operation would one use to set machine 2 from free (1) to busy (0)? (Without changing the state of the other machines, obviously!)
B. What bit mask value and what operation would one use to set machines 2 and 6 to free (1)?
(Again, without changing the state of the other machines).
Note: This can be done with a single boolean operation, but it cannot be implemented in LC-3 assembly language with a single instruction!
C. What bit mask value and what operation would one use to set all machines to busy (0)?
D. What bit mask value and what operation would one use to set all machines to free (1)?
E. Develop a procedure to “interrogate” the status of machine 2 by isolating it as the “sign bit” (i.e. the msb).
For example, if the BUSYNESS pattern is 0101 1100, then the output of this procedure is 10000000. If the BUSYNESS pattern is 0111 0011, then the output is 0110 0000. In general, if the BUSYNESS pattern is:

CS 61 – Programming Assignment 5

Question 5.6
Recall the machine busy example from Section 2.7.1. Assuming the BUSYNESS bit vector is stored in R2, we can use the LC3 instruction AND R3, R2, #1 to determine whether machine 0 is busy or not.
If the result of this instruction is 0, then machine 0 is busy.
A. Write an LC3 instruction that determines whether machine 2 is busy.
B. Write an LC3 instruction that determines whether both machines 2 and 3 are busy.
C. Write an LC3 instruction that indicates whether none of the machines are busy.
D. Can you write a single LC3 instruction that determines whether machine 6 is busy? Is there a problem here?
The variation of Question 9.9 that you will implement in this assignment:
(remember – 0 = busy; 1 = free)
A. Check if all machines are busy; return 1 if all are busy (0), 0 otherwise (i.e. if any are free).
B. Check if all machines are free; return 1 if all are free (1), 0 otherwise (i.e. if any are busy).
C. Check how many machines are busy (0); return the number of busy machines.
D. Check how many machines are free (1); return the number of free machines.
E. Check the status of a specific machine whose number is passed as an argument in R1; return 1 if that machine is free (1), 0 if it is busy (0).
F. Return the number of the first (lowest numbered, or rightmost) machine that is free (1) – i.e. a number between 0 and 15. If no machine is free, return -1 (= xFFFF)
e.g. if the busyness vector is 0101 0100, then the first available machine is #2
(Remember – the lsb is always considered bit 0)

CS 61 – Programming Assignment 5

Your Tasks
The assignment can be broken down into the following tasks:

1. Your main code block should call a MENU subroutine, which prints out a fancy looking menu
with numerical options, invites the user to input a choice, and returns in R1 the user’s selection
{1, 2, 3, 4, 5, 6, 7} If the user inputs a non-existent option, output an error message and re-print
the menu; repeat until a valid entry is obtained. In other words, there is no way of getting out
of the subroutine with anything other than a number in the correct range.
Here is the menu that you will be using for the assignment:
(it is given to you in the starter code as a single long string located at memory address x6400)
***********************
* The Busyness Server *
***********************
1. Check to see whether all machines are busy
2. Check to see whether all machines are free
3. Report the number of busy machines
4. Report the number of free machines
5. Report the status of machine n
6. Report the number of the first available machine
7. Quit
2. Write the following corresponding subroutines:
A. MENU
B. ALL_MACHINES_BUSY
C. ALL_MACHINES_FREE
D. NUM_BUSY_MACHINES
E. NUM_FREE_MACHINES

F. MACHINE_STATUS
G. FIRST_FREE
plus the two helper subroutines:
GET_MACHINE_NUM
PRINT_NUM

DETAILED ASSIGNMENT

20210208215157programming_assignment_5

Powered by WordPress