FIT1047-Lab-Week-4 5 Solution PDF

Title FIT1047-Lab-Week-4 5 Solution
Course Introduction to Computers, Networks and Security
Institution Monash University
Pages 7
File Size 483.1 KB
File Type PDF
Total Downloads 106
Total Views 151

Summary

Download FIT1047-Lab-Week-4 5 Solution PDF


Description

• Programming MARIE assembly code

Instructions The tasks are supposed to be done in groups of two or three students. You will need the MARIE simulator for this assignment.

Task 1: Conditionals A conditional statement allows the flow of a program to depend on data. In a highlevel programming language, this is typically achieved using if-then-else statements such as the following (this is Python syntax): if X == Y: X = X + Y AMK remarks: If the value of X = Y then increment X by adding Y else: If the value of X (GreaterThan/LessThan) Y then Y is incremented by X Y = Y + x

Task 2: Subroutines An important concept in programming is that of a procedure, function, or subroutine, a piece of code that has a fixed purpose and that needs to be executed over and over again. As a simple example, you saw last week that MARIE doesn’t have an instruction for multiplication. Now imagine a large program: you will probably need the multiplication routine in hundreds of different places! Of course, you could just copy and paste the piece of code into the place where you need it. Discuss why that’s a bad idea! • Copying and pasting the code increases the number of lines of code (the complexity of the code), making it harder to write the code in the first place and reducing the readability of the code. • As a consequence of increased code complexity, if we make a mistake we have to fix it in hundreds of different places. This is error-prone and means that the program will likely contain more bugs. Similarly, if requirements change, there is no single piece of code that needs to be changed. Subroutines therefore also improve the maintainability of the code.

1

Most ISA (Instruction Set Architectures) have some level of support for writing subroutines. In MARIE, there’s the JnS X instruction (“jump and store”): It stores the value of the PC at memory address X and then jumps to address X+1. The value stored at X is called the return address, i.e., the address where execution should continue once the subroutine has finished its job. To return from a subroutine, the last instruction in the subroutine should be a jump back to the return address. This can be achieved using the JumpI X instruction: it jumps to the address stored at address X (compare that to Jump X which jumps to the address X). 1. Explain how you can use JnS X and JumpI X to implement subroutines. In particular, think about why JnS stores the value of the PC, not PC+1. JnS X can be used to jump to the subroutine while saving the PC at address X. JumpI X can be used to return from the subroutine. JnS X saves the PC not PC+1 because the program counter (PC) holds the address of the next instruction to be executed in the program. This will be the instruction to be executed after returning from the subroutine. 2. Implement a simple subroutine that computes 2 × X, i.e., it takes the value in a memory location X, doubles it, and returns to where the original program left off. See sample MARIE assembly code subroutine double.mas. Jump X === jumps to address X JnS X === or Jumps and Stores: Stores PC at address X and jumps to X+1 JumpI X === uses the value at X as the address to jump to

Label Begin,

Solution:

2

Instruction

Operand

Load

var_X

Subt

Ten

skipcond

000

Jump

Done

Load

var_X

Add

One

Store

var_X

Jump

Begin

Done,

Halt

var_X

Dec

1

One,

Dec

1

Ten,

Dec

10

X 0 0 0 0 1 1 1 1

Y 0 0 1 1 0 0 1 1

Z 0 1 0 1 0 1 0 1

F(X,Y,Z) 1 0 1 1 1 1 1 0

Section a is Z, section b is XY and section c is XY . Thus, F (X, Y, Z) = Z + XY + XY

Digital Logic Task-4: Exercise 1: Learn to reduce Sum of Products (SOP) using Karnaugh Map. Reduction rules for SOP using K-map

SOLUTION:

SOLUTION: Sum of Products: To obtain the standard Sum-of-Products expression. Working from the Truth Table, for each row with a true output (i.e., containing 1) list the state of the input variables as a product term (i.e., an AND expression). The AND expressions from each selected row can then be OR’ed together, yielding the Sum of Products form: Now we will write down the marked groups and find the reduced expression. Quad pair= W’Y’ 1st pair = XYZ 2nd pair = X’YZ’ Now the results of the reduced final expression is:F = W’Y’ + XYZ + X’YZ’ This is the required answer.

Task-4: Exercise 2 Learn to reduce Product of Sum (POS) using Karnaugh Map.

SOLUTION: Product of Sums: Working from the truth table, for each row with a zero output, list the state of the input variables as a product term and complement this sum of products to get product of sums: Now we will write down the marked groups and find the reduced expression. Quad pair= WY’ 1st pair = X’YZ

2nd Pair = XYZ’

Now the results of the reduced final expression is:F’ = WY’ + X’YZ + XYZ’ ��������������������������� � = WY F ’ + X’YZ + XYZ’ ����� ��������� (WY’) � �� X’YZ XYZ’ � F = �������� F = (W’+Y) (X+Y’+Z’) (X’+Y’+Z) This is the required answer.

Task-4: Exercise 3 Given the following truth table: A 0 0 0 0 1 1 1 1

B 0 0 1 1 0 0 1 1

C 0 1 0 1 0 1 0 1

Output (F) 0 1 0 0 1 0 1 0

a) Write a Boolean expression in the Sum-of-Products standard format that represents the logic function performed by this circuit. SOLUTION: Sum of Products: Take the truth table to obtain the standard Sum-of-Products expression. Working from the Truth Table, for each row with a true output (i.e., containing 1) list the state of the input variables as a product term (i.e., an AND expression). The AND expressions from each selected row can then be OR’ed together, yielding the Sum of Products form:   +฀฀) ฀ ฀ ฀฀( + ฀฀฀฀ ฀฀฀฀฀฀ ฀฀ℎ฀฀฀฀ ฀฀฀฀ ฀฀ℎ฀฀ ฀฀฀฀฀฀฀฀฀฀฀฀฀฀฀฀ (฀฀฀฀฀฀) ฀฀฀฀฀฀฀฀฀฀฀฀฀฀ ฀฀฀฀฀฀฀฀฀฀฀฀฀฀฀฀�= ฀฀� ,฀฀฀฀, =  ฀฀฀฀ b) From the truth table: convert the logic function into the Product-of-Sums standard format. SOLUTION: Product of Sums: Working from the truth table, for each row with a zero output, list the state of the input variables as a product term and complement this sum of products to get product of � = ฀฀฀�฀฀฀ + ฀฀฀฀฀฀ + ฀฀฀฀฀฀ + �฀฀฀฀ ฀ ฀ + ฀฀฀฀฀฀ sums: ฀฀ � ฀฀ + ฀฀฀฀฀฀ + ฀฀฀฀฀฀ + �฀฀฀฀ ฀ ฀ + ฀฀฀฀฀฀ ฀ ฀ =�������������������������������������������� ฀฀฀฀ ������ ������ �  ฀฀ ∙ ������ � ฀฀ ∙ ������ ฀฀฀฀∙ ฀฀฀฀ ฀฀฀฀฀฀ ฀ ฀ =������ ฀฀฀฀ ฀฀฀฀฀฀∙ ฀฀ ฀฀ℎ฀฀฀฀ ฀฀฀฀ ฀฀ℎ฀฀ ฀฀฀฀฀฀฀฀฀฀฀฀฀฀฀฀ (฀฀฀฀฀฀)฀฀฀฀฀฀฀฀฀฀฀฀฀฀ ฀฀฀฀฀฀฀฀฀฀฀฀฀฀฀฀ = ฀฀(฀฀, ฀฀, ฀฀) + ฀฀ ) = (฀ ฀ + ฀ ฀ + ฀฀) ∙ (฀ ฀ �++฀฀฀฀) ∙ (฀ ฀ +�฀฀+ ฀฀ ) ∙ (฀฀ + ฀ ฀ + ฀฀) ∙ (฀฀ +� ฀฀...


Similar Free PDFs