Write the boolean function as boolean algebra terms first


1 Boolean Algebra and Logisim Task

The following truth table describes a Boolean function with four input values X1, X2, X3, X4 and two output values Z1, Z2.

The main result of this task will be a logical circuit correctly implementing this Boolean function in the logisim simulator. Each step as defined in the following sub-tasks needs to be documented and explained.

Step 1: Boolean Algebra Expressions

Write the Boolean function as Boolean algebra terms. First, think about how to deal with the two outputs. Then, describe each single row in terms of Boolean algebra. Finally, combine the terms for all of the single rows into larger terms.

Step 2: Logical circuit in Logisim

Model the resulting Boolean terms from Step 1 in a single Logisim circuit, using the basic gates AND, OR, NOT.

Test your circuit using values from the truth table and document the tests.

Step 3: Optimised circuit

Using the truth table and Boolean algebra terms from Step 1, optimise the function to be able to build a circuit with a smaller number of AND, OR, and NOT gates. Don't use any other gates. You need to use Boolean algebra laws and explain each step of the optimisation.

The goal is to find a circuit that has less gates than the circuit in Step 2. It is not required to find the minimal circuit.

Test your optimized circuit using values from the truth table.

2 A MARIE calculator

In this task you will develop a MARIE calculator application. We will break it down into small steps for you.

Most of the tasks require you to write code, test cases and some small analysis. The code must contain comments, and you submit it as .mas files together with the rest of your assignment. The test cases should also be working, self-contained MARIE assembly files. The analysis needs to be submitted as part of the main PDF file you submit for this assignment.

Note that all tasks below only need to work for positive numbers. If you want a challenge, you can try and make your calculator work for negative numbers, but it's not required to get full marks.

In-class interviews: You will be required to demonstrate your code to your tutor after the submission deadline. Failure to demonstrate will lead to zero marks being awarded to the entire programming part of this assignment.

MARIE integer multiplication and division

Multiplication

Implement a subroutine for multiplication (based on the multiplication code you wrote in the labs - you can use the sample solution as a guideline). Test your subroutine by writing a test program that calls the subroutine with different arguments, and then step through the programs in the MARIE simulator.

You need to submit at least one MARIE file that contains the subroutine and a test case.

Division

The following code is a poor attempt at implementing a division subroutine in MARIE. It contains a number of errors (both in the assembly syntax and in the program logic). Find and fix these errors, and produce a list that documents for each error how you found it and how you fixed it.

Write a test program that calls the subroutine with different arguments, and then step through the programs in the MARIE simulator. Don't try to just re-implement division

- the point of this task is to identify and fix errors in existing code!

Reverse Polish Notation (RPN)

RPN is a notation for arithmetic expressions in which the operator follows the argu- ments. For example, instead of writing 5 + 7, we would write 5 7 +. For more complex expressions, this has the advantage that no parentheses are needed: compare 5 × (7 + 3) to the RPN notation 5 7 3 + ×.

A calculator for RPN can be implemented using a stack, one of the fundamental data structures we use in programming. A stack is just a pile of data: you can only push a new data value to the top of the stack, or pop the top-most value.
To evaluate RPN, we just need to go through the RPN expression from left to right. When we find a number, we push it onto the stack. When we find an operator, we pop the top-most two numbers from the stack, compute the result of the operation, and push the result back onto the stack. Here is a step-by-step evaluation of 5 7 3 + ×:

Note that we read the stack from left to right here, so e.g. after reading the 7, the stack contains the values 5 and 7, with 7 at the top of the stack.

After all operations are finished, the final result is the only value left on the stack.

A stack in MARIE assembly

A stack can be implemented in memory by keeping track of the address of the current top of the stack. This address is called the StackPointer, and we use a label to access it easily:
StackPointer, HEX FFF

In this example, we set the initial stack pointer to address FFF, the highest address in MARIE.

A push operation writes the new value into the address pointed to by StackPointer, and then decrements the stack pointer. A pop operation increments the StackPointer and then returns the value at the address pointed to by the StackPointer. This means that when we push a value, the stack "grows downwards" from the highest address towards 0.

1. Write a sequence of instructions that pushes the values 5, 4, 3 onto the stack and then pops them again, printing each value using the Output instruction. Step through your code to make sure that the StackPointer is decremented and incre- mented correctly, and that the values end up in the right memory locations.

2. Write a program that implements Push and Pop subroutines. Test the subroutines by pushing and popping a few values, stepping through the code to make sure the stack works as expected.

A simple RPN calculator

We will now implement a simple RPN calculator that can only perform a single operation: addition.

We will use the Input instruction to let the user input a sequence of numbers and operators. To simplify the implementation, we will switch MARIE's input field to Dec mode, meaning that we can directly type in decimal numbers. But how can we input operators?

We will simply only allow positive numbers as input values, and use negative num- bers as operators. For this first version, we will use -1 to mean addition.

So to compute 10 + (20 + 30) we would have to enter 10 20 30 - 1 - 1. Of course we could also enter 10 20 - 1 30 - 1 (which would correspond to (10 + 20) + 30). The pseudo code for this simple calculator could look like this:

Loop forever:
AC = Input // read user input
if AC >= 0: // normal number? push AC
else if AC == -1: // code for addition?
X = Pop Y = Pop
Result = X+Y

Output Result // output intermediate result AND

Push Result // push onto stack for further calculations

Note that your calculator doesn't need to do any error checking, e.g. if you only enter a single number and then use the addition operator, or if you enter any negative number other than -1.

Implement this calculator in MARIE assembly. Use the Push and Pop subroutines from the previous task to implement the stack. It is a requirement that your calculator can handle any valid RPN expression, no matter how many operands and operators, and no matter in what order (up to the size of the available memory). I.e., the following expressions should all work and deliver the same result:

1020304050 - 1 - 1 - 1 - 1
1020 - 13040 - 150 - 1 - 1
102030 - 1 - 140 - 150 - 1
1020 - 130 - 140 - 150 - 1

Document a set of test cases and the outputs they produce.

More RPN operations

Of course the previous calculator is quite useless - if there is only one operation, we don't need to use RPN at all. Therefore, the next step is to extend your calculator with support for additional operations:
- Multiplication (code -2)
- Integer division (code -3)
- Subtraction (code -4)
The extended pseudo code would look like this:
Loop forever:
AC = Input // read user input
if AC >= 0: // normal number? push AC
else if AC == -1: // code for addition?
X = Pop Y = Pop
Result = X+Y Output Result Push Result
else if AC == -2: // code for multiplication?
X = Pop Y = Pop
Result = X*Y Output Result Push Result
else if ... // remaining cases follow the same structure

Note that by convention, XY - means X -Y in RPN, and similarly XY/ means X/Y .

As above, test your calculator using different test cases, which you should document in your written submission.

You can submit just one file for the entire extended version.

Solution Preview :

Prepared by a verified Expert
Assembly Language: Write the boolean function as boolean algebra terms first
Reference No:- TGS01547931

Now Priced at $150 (50% Discount)

Recommended (99%)

Rated (4.3/5)