0% found this document useful (0 votes)
14 views4 pages

Solution 5 Logic Functions v.6

Uploaded by

testphishingguy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Solution 5 Logic Functions v.6

Uploaded by

testphishingguy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Computer organisation and programming course, Shenkar College of Design & Engineering

Solution of Homework 5: Basic computer logic functions


Warm up exercise:
X Y OR NOR XOR XNOR AND
0 0 0 1 0 1 0
0 1 1 0 1 0 0
1 0 1 0 1 0 0
1 1 1 0 0 1 1
Different notations for logic/Boolean functions:
A AND B = A ˄ B = A∙B = AB
A OR B = A ˅ B = A+B
NOT A = !A = A'
1. Write the Boolean expression that implements each function in terms of the given
operations (AND & NOT). Use De-Morgan’s theorems.
a. Result = X OR Y = (X OR Y)’’ = (X’ Y’)’
b. Result = X NOR Y = (X OR Y)’ = (X’ Y’)’’ = X’ Y’
c. Result = X XOR Y = X’Y + XY’ = (XY + X’Y’)’ = (XY)’ · (X’Y’)’
d. Result = X NAND Y = (X Y)’

2. Implement the assembly language programs that carry out the functions.

It is necessary to put intermediate results in a temporary variable Tmp1.

// (a) X OR Y = (X OR Y)’’ = (X’Y’)’


Main, LDA X
CMA
STA notX
LDA Y
CMA
AND notX
CMA

STA Result // Result = X OR Y


HLT
// Data
notX, HEX 0
X, HEX F0F0
Y, HEX FF00
Result, HEX 0 //

// (c) X XOR Y = X’Y + XY’ = (X’Y + XY’)’' = ( (X’Y)' · (XY’)’ )'


Main, LDA X
CMA
AND Y
CMA
STA notX

LDA Y
CMA
AND X
CMA

AND notX
CMA

STA Result // Result = X XOR Y = ( (X’Y)' · (XY’)’ )'


HLT
// Data
notX, HEX 0
X, HEX F0F0
Y, HEX FF00
Result, HEX 0 //
(b) & (d) can be easily derived according to (a) & (c) and this is left as an exercise for the reader…

8. April 2022 1 Dr Yigal Hoffner


Computer organisation and programming course, Shenkar College of Design & Engineering

3. Write a program using Mano’s CPU to determine the following:


Odd or even integer: Checking the least significant bit of a 16-bit integer. If the integer is
even, put the result into a variable called Even, if the integer is odd, put the result into a
variable called Odd.
The (trivial) general high-level algorithm is:
IF (Number is even)
THEN Even = Number;
ELSE Odd = Number;
FI;

a.i) Solve the problem using the appropriate circulate operation (CIL or CIR
operation).

E = least-significant-bit(Number);
IF (E=0)
THEN Even = Number;
ELSE Odd = Number;
FI;
// using CIR
Main, LDA Number
CIR
SZE // IF (Number is even)
BUN ELSE //
THEN, LDA Number // THEN
STA Even // Even = Number;
BUN FI //
ELSE, LDA Number // ELSE
STA Odd // Odd = Number;
FI, HLT // FI
// Data
Number, DEC 11
Even, DEC 0
Odd, DEC 0

[Link]) Solve the problem using a Mask (as shown in lecture with the AND
operation).

Mask = 0000 0000 0000 0001; // 0001 Hex


IF (Number AND Odd_even_Mask = 0)
THEN Even = Number;
ELSE Odd = Number;
FI;
// using a Mask
Main, LDA Number // IF (Number is even)
AND Odd_Even_Mask //
SZA //
BUN ELSE //
THEN, LDA Number // THEN
STA Even // Even = Number;
BUN FI //
ELSE, LDA Number // ELSE
STA Odd // Odd = Number;
FI, HLT // FI
// Data
Number, DEC 11
Odd_Even_Mask, HEX 0001 // Binary: 0000000000000001
Even, DEC 0
Odd, DEC 0

b) Positive or negative integer: (given 2’s complement representation of integers, for


example) checking the most significant bit of an integer. If the integer is positive, put

8. April 2022 2 Dr Yigal Hoffner


Computer organisation and programming course, Shenkar College of Design & Engineering

the result into a variable called Positive, if the integer is negative, put the result into a
variable called Negative.

This is similar to part (a) except that we have to deal with the most significant
bit (bit 15 of the AC).
So:
b.i) we use CIL instead of CIR
[Link]) Pos_Neg_Mask = 1000 0000 0000 0000; // = 8000 Hex

4. One possible way to implement Boolean variables in 16 bit words is to use the convention
in the slides of:
Boolean TRUE = FFFF hex
Boolean FALSE = 0000
This representation of TRUE and FALSE ensures that when you use the CMA instruction
– it preserves the relationship of: NOT(TRUE) = FALSE and also NOT(FALSE) =
TRUE.
This is not the case with a representation such as TRUE = 1; FALSE = 0;

5. Implement the following in Mano Assembly language and try it with different values of
the Boolean variables a & b:
5a)
Boolean a = TRUE; // FFFF
Boolean b = FALSE; // 0000
int x = 4; int y = 5; int z;
IF !(a AND b)
THEN z = x + y;
ELSE z = x – y;
FI;

// The Boolean AND function


Main, LDA A
AND B Boolean a = TRUE; Boolean b = FALSE;
CMA int x = 4; int y = 5; int z;
SNA // IF !(a AND b) IF !(a AND b)
BUN Else //
Then, LDA X // THEN z = x + y; THEN z = x + y;
ADD Y // ELSE z = x – y;
BUN Fi // FI;
Else, LDA Y // ELSE z = x – y;
CMA //
INC //
ADD X //
Fi, STA Z // FI;
// Data
TRUE, HEX FFFF //
FALSE, HEX 0 //

A, HEX FFFF // TRUE is represented by FFFF;


B, HEX 0 // FALSE is represented by 0000;
X, DEC 4
Y, DEC 5
Z, DEC 0

Another approach is to look at the condition :


Boolean a = TRUE; Boolean b = FALSE;
int x = 4; int y = 5; int z; …
IF !(a AND b == TRUE) IF (a AND b == FALSE)
THEN z = x + y;  THEN z = x + y;
ELSE z = x – y; ELSE z = x – y;
FI; FI;

8. April 2022 3 Dr Yigal Hoffner


Computer organisation and programming course, Shenkar College of Design & Engineering

6) Boolean a = TRUE; // FFFF


Boolean b = FALSE; // 0000
int x = 4; int y = 5; int z;
IF (a OR !b)
THEN z = x + y;
ELSE z = x – y;
FI;
// Version 1 - The Boolean OR function: a OR !b = !!(a OR !b) = !(!a AND b)
Main, LDA A
CMA Boolean a = TRUE;
AND B Boolean b = FALSE;
CMA int x = 4; int y = 5; int z;
SNA // IF (a OR !b) IF (a OR !b)
BUN Else // THEN z = x + y;
Then, LDA X // THEN z = x + y; ELSE z = x – y;
ADD Y // FI;
BUN Fi //
Else, LDA Y // ELSE z = x – y;
CMA // Boolean a = TRUE;
INC // Boolean b = FALSE;
ADD X // int x = 4; int y = 5; int z;
Fi, STA Z // FI; IF (!(!a AND b) == TRUE)
// Data THEN z = x + y;
TRUE, HEX FFFF // ELSE z = x – y;
FALSE, HEX 0 // FI;
A, HEX FFFF // TRUE is represented by FFFF;
B, HEX 0 // FALSE is represented by 0000;
X, DEC 4
Y, DEC 5
Z, DEC 0

Alternatively – use the transformations to make the code simpler:


IF (!(!a AND b) == TRUE) = IF ( (!a AND b) == FALSE)
// Version 2 - The Boolean OR function:
Main, LDA A
CMA
AND B
SZA // IF (a OR !b)
BUN Else //
Then, LDA X // THEN z = x + y;
ADD Y //
BUN Fi //
Else, LDA Y // ELSE z = x – y;
CMA //
INC // Boolean a = TRUE;
ADD X // Boolean b = FALSE;
Fi, STA Z // FI; int x = 4; int y = 5; int z;
// Data IF (NOT(NOT(a) AND b) == TRUE)
TRUE, HEX FFFF // THEN z = x + y;
FALSE, HEX 0 // ELSE z = x – y;
FI;
A, HEX FFFF // A = TRUE;
B, HEX 0 // B = FALSE;
X, DEC 4
Y, DEC 5
Z, DEC 0 Boolean a = TRUE;
Boolean b = FALSE;
int x = 4; int y = 5; int z;
IF ( (NOT(a) AND b) == FALSE)
THEN z = x + y;
ELSE z = x – y;
FI;

8. April 2022 4 Dr Yigal Hoffner

You might also like