CALD Spring 2024 Final
CALD Spring 2024 Final
R2
Thoroughly and accurately identifies
Does not demonstrate Identifies some Accurately identifies most
all components involved,
Able to Identify the an understanding of the components but lacks components but may miss
demonstrating a deep
Components components involved. accuracy or completeness. some minor elements.
understanding of the task.
R3
Unable to deduce the Produces a partially Deduces a correct logic Consistently deduces optimized logic
Able To Deduce The logic diagram or correct logic diagram but diagram for most inputs but diagrams for any input,
Optimized Logic Diagram produces an incorrect fails to optimize it may overlook optimization demonstrating a high level of
For Any Input diagram. effectively. opportunities. understanding and efficiency.
R4
Partially implements or Implements and Implements and demonstrates the
Unable to implement or
demonstrates the task demonstrates the task task flawlessly, showcasing thorough
Able To Implement And demonstrate the task
with significant errors or adequately, but with minor understanding and proficiency in
Demonstrate The Task effectively.
omissions. errors or inefficiencies. execution.
R3
Inappropriate Correct measurement
Measurement/ Partly correct measurement Competent measurement
measurement techniques are
techniques are demonstrated, techniques are demonstrated, with
Techniques/ Data techniques are demonstrated, with partly
with partly valid data valid and accurate data
Validation demonstrated valid data
R4
Shows little commitment Demonstrates
Demonstrates commitment to Actively helps to identify group goals
to group goals and fails commitment to group
Contribution/ group goals, but has difficulty and works effectively to meet them
to perform assigned goals and carries out
Group participation performing assigned roles in all roles assumed
roles assigned roles effectively
Grand Total
‘Anything that make sense is called logic’. Circuit that takes the logical
decision and the process are called logic gates. Each gate has one or more
input and only one output. Digital circuits have two discrete voltage levels to
represent the binary digits (bits) 1 and 0. All digital circuits are switching
circuits. Instead of mechanical switches, they use high-speed transistors to
represent either an ON condition or an OFF condition. Various types of logic,
representing different technologies, are available to the logic designer. The
choice of a particular family is determined by factors such as speed, cost,
availability, noise immunity, and so forth. The key requirement within each
family is compatibility; that is, there must be consistency within the logic
levels and power supplies of various integrated circuits made by different
manufacturers. The experiments in this lab book use primarily transistor-
transistor logic, or TTL. The detailed performance characteristics of TTL
depend on the particular subfamily. However, all TTL is designed to operate
from a 5 V power supply, and the logic levels are the same for all TTL
integrated circuits.
AND GATE
OR GATE
The NOT gate is called an inverter. The output is high when the input is low.
The output is low when the input is high.
IN LAB
PROCEDURE
AND Gate:
SYMBOL:
PIN DIAGRAM:
NOT Gate:
SYMBOL PIN
DIAGRAM
Review Question
If more than two input AND & OR gates are available, how will you connect its inputs so that they work
as 2 input gates? Perform it for 3 and 4 input AND & OR gates.
Practice given circuit and draw a truth table for each circuit. Construct boolean expressions for
all outputs.
F1=ABC
F2=A+B+C
Web Resources
https://www.techtarget.com/whatis/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-
XNOR#:~:text=There%20are%20seven%20basic%20logic,NAND%2C%20NOR%2C%20and%20XNOR.
http://www.uop.edu.pk/ocontents/Lec-10-universal%20gates.pdf
Videos Resources
https://www.youtube.com/watch?v=La9Nk6iwHvU
https://www.youtube.com/watch?v=-MqHBjJpAiE
INTRODUCTION
PRE-LAB
De Morgan Theorems:
Distributive
Associative
Commutative Law
Any binary operation which satisfies the following expression is referred to as a
commutative operation. Commutative law states that changing the sequence of
the variables does not have any effect on the output of a logic circuit.
● A. B = B. A
● A+B=B+A
Associative Law
It states that the order in which the logic operations are performed is irrelevant as
their effect is the same.
● ( A. B ). C = A . ( B . C )
● ( A + B ) + C = A + ( B + C)
Distributive Law
Distributive law states the following conditions:
● A. ( B + C) = (A. B) + (A. C)
● A + (B. C) = (A + B) . ( A + C)
AND Law
These laws use the AND operation. Therefore, they are called AND laws.
● A .0 = 0
● A.1=A
OR Law
These laws use the OR operation. Therefore, they are called OR laws.
● A +0=A
● A+1=1
● A+A=A
●
Inversion Law
This law uses the NOT operation. The inversion law states that double inversion of
a variable results in the original variable itself.
●
Universal Gates:
NAND and NOR gates are called universal Gates because they can be used in
combination to perform the function of other basic logic gates and
implement any Boolean function. NAND gates is also called NOT – AND and
NOR gate is called NOT – OR gate. Pin diagram of both gates is given below.
1. A+0 = A
2. A+1 = 1
3. A .0 = 0
4. A .1 = A
5. A+A = A
6. A+A’ = 1
7. A.A = A
8. A.A’ = 0
9. (A’)’ = A
10. A+AB = A
IN LAB
Procedure:
Procedure A:
a. Prove OR Law . (A+0=A)
The procedure is:
Connect terminal 2 with the ground and terminal 1 with the switch.
b. Connect the circuit of Fig.2. Which rule does this circuit illustrate? (A.A=A)
c. Design a circuit that illustrates rule 10.( A+AB = A) Use clock for A and one of the logic
switches for B. Also draw the logic diagram and its truth table.
OBSERVATION:
The output should be high if and only if A is high
d. Rule 6 illustrates that A+A’ could be replaced with a wire to Vcc. What does rule 8 illustrate?
A.A’ = 0
Prove that these two circuits perform equivalent logic. (Connect two circuits and show that their
outputs are the same).
EXERCISE
Review Questions:
Verify all these gates and theorems one by one and state their inputs / outputs and truth table.
Mathematically prove the implementations by using the above given theorem
XOR gate using NAND and NOR
XNOR using NAND and NOR
Implement the following using NAND and NOR IC’s
Construct and show that the following two circuits give the same outputs for all combinations
of A, B
Web Resources
Videos Resources
https://www.youtube.com/watch?v=La9Nk6iwHvU
https://www.youtube.com/watch?v=-MqHBjJpAiE
INTRODUCTION
1. AND GATE:
We know that AND gate is represented by:
F=A.B
Taking double complement of both sides
(F’)’=[(A.B)’]’
Applying Demorgan’s Law
F= (A’+B’)’
Implement the circuit and verify the truth table of AND gate
2. OR GATE :
We know that OR gate is represented by
F=A+B
Implement the circuit as shown in the diagram , also verify the truth table of the NOT gate
4. NAND:
Expression for NAND gate is:
F=(A.B)’
Taking double complement of both sides
(F’)’=[((A.B)’)’]’
Applying demorgan’s law
F=[(A’+B’)’]’
This is the expression of NAND gate in terms of NOR
EXCLUSIVE OR
Implement the circuit as shown in the diagram also verify its truth table
EXOR:
XNOR
An XNOR gate can be constructed from four NOR gates implementing the expression "(A NOR
N) NOR (B NOR N) where N = A NOR B".This construction has a propagation delay three
times that of a single NOR gate, and uses more gates.
XNOR Construction
REVIEW
NOR gate is a universal gate as it can be used to implement any other gate. So a combinational
circuit can be implemented with only NOR ICs.
Web Resources
https://www.techtarget.com/whatis/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-
XNOR#:~:text=There%20are%20seven%20basic%20logic,NAND%2C%20NOR%2C%20and%20XNOR.
http://www.uop.edu.pk/ocontents/Lec-10-universal%20gates.pdf
Videos Resources
https://www.youtube.com/watch?v=La9Nk6iwHvU
https://www.youtube.com/watch?v=-MqHBjJpAiE
Construct AND,OR,NOT,NOR,EXOR.EXNOR logical gates using NAND and draw truth tables.
Construct circuit diagram of the following expression using only NAND logical gates using NOR
IC and draw truth tables.
F=AC+BC+AD+BD
INTRODUCTION
Any logic Function can be minimized to a minimum number of literals and terms. It is efficient
to utilize the limited resources to have the functionality. One method of function minimization is
to use the Boolean theorems and identities as discussed in lab 1 and 2.
Karnaugh map or K-map is a map of a function used in a technique used for minimization or
simplification of a Boolean expression. It results in less number of logic gates and inputs to be
used during the fabrication.
Booleans expression can be simplified using Boolean algebraic theorems but there are no
specific rules to make the most simplified expression. However, K-map can easily minimize the
terms of a Boolean function.
K-map is basically a diagram made up of squares. Each of these squares represents a min-term of
the variables. If n = number of variables then the number of squares in its K-map will be 2n. K-
map is made using the truth table.
Rules:
1. No zeros allowed.
2. No diagonals.
3. Only power of 2 number of cells in each group.
4. Groups should be as large as possible.
5. Every one must be in at least one group.
6. Overlapping allowed.
7. Wrap around allowed.
8. Fewest number of groups possible.
2. Draw the logic diagrams for outputs F1 and F2 in terms of the inputs A, B, C, and D.
3. Implement and draw the two functions F1 and F2 together by using minimum number of
NAND gates.
4. Connect the circuit and verify it’s operation by preparing a truth table for F1 and F2.
Boolean Functions
4. Combine all the 0’s to obtain the simplified function for F’.
5. Implement both F and F’ using NAND gates and connect two circuits to the same input
switches but to separate output LED’s. Prove that both circuits are complement of each other and
verify the operation of the circuit.
Web Resources
https://www.techtarget.com/whatis/definition/logic-gate-AND-OR-XOR-NOT-NAND-NOR-and-
XNOR#:~:text=There%20are%20seven%20basic%20logic,NAND%2C%20NOR%2C%20and%20XNOR.
http://www.uop.edu.pk/ocontents/Lec-10-universal%20gates.pdf
Videos Resources
https://www.youtube.com/watch?v=La9Nk6iwHvU
https://www.youtube.com/watch?v=-MqHBjJpAiE
Exercise 4.1:
[15]
1. Construct a truth table for the following Boolean Functions.
F=A’C+A’D+ABC+B’D
4. Combine all the 0’s to obtain the simplified function for F’.
5. Construct both F and F’ using NAND gates and connect two circuits to the same input
switches but to separate output LED’s. Show that both circuits are complement of each other and
verify the operation of the circuit.
OBJECTIVES
To Design and construct half adder , full adder , half subtractor , full subtractor
Deduce their logic functions using K-MAPS
Verify their truth tables using logic gates
COMPONENTS REQUIRED
PRE LAB
INTRODUCTION
Half Adder
A combinational logic circuit that performs the addition of two single bits is
called Half Adder.
It is an arithmetic combinational logic circuit designed using XOR & AND
gates to perform addition of two single bits.
It contains two inputs and produces two outputs.
Added bits and Outputs are called Sum and Carry, respectively.
HALF SUBTRACTOR
The half subtractor is constructed using XOR and AND Gate. The half subtractor has two input
and two outputs. The outputs are difference and borrow. The difference can be applied using
XOR Gate, borrow output can be implemented using an AND Gate and an inverter.
FULL SUBTRACTOR
The full subtractor is a combination of XOR, AND, OR, NOT Gates. In a full subtractor the logic
circuit should have three inputs and two outputs. The two half subtractor put together gives a
full subtractor .The first half subtractor will be C and A B. The output will be difference output
of full subtractor. The expression AB assembles the borrow output of the half subtractor and
the second term is the inverted difference output of first XOR.
IN LAB
LOGIC DIAGRAM
HALF ADDER
TRUTH TABLE
FULL ADDER
HALF SUBTRACTOR
TRUTH TABLE
Applications:
1. For performing arithmetic calculations in electronic calculators and other
digital devices.
2. In Timers and Program Counters.
3. Useful in Digital Signal Processing.
POST LAB
Review Questions
Mathematically prove all the above equations (output equations of half ,full
adder and subtractor ) deduced from their truth table using K-MAP and Boolean
Simplification
OBJECTIVES
COMPONENTS REQUIRED
PRE LAB
INTRODUCTION
Binary code of N digits can be used to store 2 N distinct elements of coded information. This is
what encoders and decoders are used for. Encoders convert 2N lines of input into a code of N
bits and Decoders decode the N bits into 2N lines.
ENCODER:
An encoder is a combinational circuit that converts binary information in the form of a 2 N input
lines into N output lines, which represent N bit code for the input. For simple encoders, it is
assumed that only one input line is active at a time.
Another ambiguity arises when all inputs are 0. In this case, encoder outputs 000 which actually
is the output for D0 active. In order to avoid this, an extra bit can be added to the output, called
the valid bit which is 0 when all inputs are 0 and 1 otherwise.
Priority Encoder:
A priority encoder is an encoder circuit in which inputs are given priorities. When more than
one inputs are active at the same time, the input with higher priority takes precedence and the
output corresponding to that is generated.
V = D0 + D1 + D2 + D3
The circuit diagram of 4 to 2 priority encoder is shown in the following
figure.
The above circuit diagram contains two 2-input OR gates, one 4-input OR
gate, one 2input AND gate & an inverter. Here AND gate & inverter
combination are used for producing a valid code at the outputs, even when
multiple inputs are equal to ‘1’ at the same time. Hence, this circuit encodes
the four inputs with two bits based on the priority assigned to each input.
TRUTH TABLE
INPUT OUTPUT
Y1 Y2 Y3 Y4 Y5 Y6 Y7 A B C
1 0 0 0 0 0 0
0 1 0 0 0 0 0
0 0 1 0 0 0 0
0 0 0 1 0 0 0
0 0 0 0 1 0 0
0 0 0 0 0 0 1
DECODER:
A decoder does the opposite job of an encoder. It is a combinational circuit that converts n lines
of input into 2n lines of output. Each input code word produces a different output code word
i.e. there is one to one mapping can be expressed in truth table.
Let’s take an example of 3-to-8 line decoder
TRUTH TABLE
INPUT OUTPUT
E A B D0 D1 D2 D3
0 x x 0 0 0 0
1 0 0 1 0 0 0
1 0 1 0 1 0 0
1 1 0 0 0 1 0
1 1 1 0 0 0 1
PROCEDURE
REVIEW QUESTIONS
POST LAB
Introduction
Emu8086 is a program that compiles the source code (assembly language) and executes it. You
can watch registers, flags and memory while your program executes. Arithmetic & Logical Unit
(ALU) shows the internal work of the central processor unit (CPU). Emulator runs programs on a
Virtual PC; this completely blocks your program from accessing real hardware, such as hard-
drives and memory, 8086 machine code is fully compatible with all next generations of Intel's
microprocessors.
Where to start?
Start Emu8086 by selecting its icon from the start menu, or by running Emu8086.exe.
Select "Samples" from "File" menu.
Click [Compile and Emulate] button (or press F5 hot key).
Click [Single Step] button (or press F8 hot key), and watch how the code is being executed.
Try opening other samples, all samples are heavily commented, so it's a great learning tool.
Directives
ORG 100h is a compiler directive (it tells compiler how to handle the source code). This
directive is very important when you work with variables. It says to compiler that the executable
file will be loaded at the offset of 100h (256 bytes), so compiler should calculate the correct
address for all variables when it replaces the variable names with their offsets. Directives are
never converted to any real machine code.
Why executable file is loaded at offset of 100h? Operating system keeps some data about the
program in the first 256 bytes of the CS (code segment), such as command line parameters and
etc.
Offset is use to get the offset address of the variable in register specified.
MOV instruction
Copies the second operand (source) to the first operand (destination).
The source operand can be an immediate value, general-purpose register or memory location.
The destination register can be a general-purpose register, or memory location.
Both operands must be the same size, which can be a byte or a word.
Syntax:
mov destination, source
Example:
Register is a series of memory cells inside the CPU itself. Because registers are inside the CPU
there is very little overhead in working with them. There are four general purpose registers, AX,
BX, CX, and DX. These are the registers you will be using often. Each of these general registers
is 16- bit. They also have 8-bit counterparts. AX is 16 bits where as AH and AL is 8bit.
Note: - AH being the high bit, and AL being the low bit. Together AH and AL make AX.
Procedure is a part of code that can be called from your program in order to make some specific
task. Procedures make program more structural and easier to understand. Generally procedure
returns to the same point from where it was called.
db stands for "define byte" and it's used to define a sequence of bytes.
In this case, the sequence includes the characters "Hello", "World", followed by a carriage
return (0dh), a line feed (0ah), and a dollar sign ($).
The carriage return and line feed characters are used to control the cursor position when
printing the message.
The dollar sign likely marks the end of the message
CX (Count Register)
Contains the count for certain instructions e,g shift count, rotate the number of bytes and a
counter with loop instruction.
Can be accessed as 32 bit (ECX), 16 bit (CX) or 8 bit (CH or CL) register 32 bit
General Purpose use in ADD, MUL, DIV, MOV
Special Purpose use in LOOP etc.
EXERCISES
Exercise 7.1
Copy all example of assembly language one by one in Emu8086 and execute them. Practice all
these examples and show output.
Example:
Mov ah,1h ;keyboard input subprogram
INT 21h ;call the sub program to take character input from the user and store in al
Note:-
Carriage Return ASCII (0DH) is the control character to bring the cursor to the start of a line.
;display Return
mov dl, 0dh
mov ah, 2h
int 21h ; display Carriage Return
Line-feed ASCII (oAh) is the control character that brings the cursor down to the next line on
the screen.
;display Line-feed
mov dl, 0ah
mov ah, 2h
int 21h ; display Line Feed
The first version simply encloses the string in quotes. (preferred method)
The second version defines a string by specifying a list of the character constants that make
up the string.
The third version defines a string by specifying a list of the ASCII codes that make up the
string
In order to display string using MS-DOS subprogram (number 9h), the string must be
terminated with the ‘$’ character.
In order to display a string we must know where the string begins and ends.
The beginning of string is given by obtaining its address using the offset operator.
The end of a string may be found by either knowing in advance the length of the string or by
storing a special character at the end of the string.
To make programming easier there are some common functions that can be
included in your program. To make your program use functions defined in other
file you should use the INCLUDE directive followed by a file name. Compiler
automatically searches for the file in the same folder where the source file is
located.
To use any of the functions in emu8086.inc you should have the following line in
the beginning of your source file:
include 'emu8086.inc'
SCAN_NUM - procedure that gets the multi-digit SIGNED number from the
keyboard, and stores the result in CX register. To use it declare:
DEFINE_SCAN_NUM before END directive.
Hint: - The ASCII codes for lowercase letters (a-z) are 97-122. In order to convert a
lowercase letter to uppercase letter, just subtract 32 from its ASCII code.
Exercise 8.2
Write a program that input a character from user. The program will display it ten times on screen
in newline.
Exercise 8.3
Write a program that will display uppercase letters (A-Z), using loop on new line.
Exercise 8.4:
Write a program that takes two numbers from user and display their sum as follows:
Exercise 8.5:
Write a program that reads five unsigned integers from user and display sum of those
five integers on the screen.
Exercise 8.6:
Write a program that reads a number from the user. The program should then take the
sum of numbers from 1 to that number and print it on screen.
Exercise 8.7:
Write a program that reads a number from the user. The program should take sum of a
number and its negative and print on screen.
Exercise 8.8:
Write a program that takes two numbers from user. The program should display all the
numbers between them. The program should also display the sum of all those numbers.
The dividend is always double the size of divisor. The implicit dividends for these instructions
are as bellow
Web Resources
http://www.svu.edu.eg/specialunits/acadeet/dwnldFiles/trainMater/provis/emu86_short.pdf
Videos Resources
www.youtube.com/watch?v=pcyvLYb5XDc
www.youtube.com/watch?v=SqcVG6CA4J4
Exercise 9.2:
Try to write a program to use the SCAN_NUM to input prompt for values for three variables x, y
and z and the PRINT_NUM to display an appropriate label and value of the expression x – y + 2z –
1.
Exercise 9.3:
Try to write an assembly language program that prompts for and inputs the length, width, and height
of a box and calculates and displays its surface area.
surface area = 2 * (length * width + length * height + width * height)
Exercise 9.4:
Try to write an assembly language program that takes a number from user and finds its factorial.
Exercise 9.5:
Try to write an assembly language program that takes a number from user and prints its table.
Exercise 9.6:
Try to write an assembly language program that takes a number from a user and find its square and
cube.
Exercise 9.7:
Try to write a program that divide word size variables Var1=-500 and Var2=2 and stores the
result in memory.
Exercise 9.8:
Try to write an assembly language program that prompts for inputs %marks of four exams M1,
M2, M3, and M4. Suppose that M4 is a final exam that counts twice as much as the other three.
Calculate the sum (adding the last grade twice) and the average (sum/5). Display the sum and
average on two lines of a message box, each line with an appropriate label.
Exercise 9.9:
Try to write a program that takes input from user in Celsius and Convert the temperature to
Fahrenheit.
Exercise 9.10:
Objective
Identification of Flag register
Type of flag register
Learn which flag bits are affected by different instructions
Flag Register
Determines the current state of the processor.
They are modified automatically by CPU after mathematical operations, this allows to
determine the type of the result, and to determine conditions to transfer control to other parts
of the program.
Generally, you cannot access these registers directly.
Status Flags:
The Status flags reflect the outcomes of arithmetic and logical operations performed by the CPU.
You do not need to alter the value yourself.
Carry flag (CF) is set when the result of an unsigned arithmetic operation is too large to fit
into the destination (unsigned overflow). For example, when you add bytes 255+1 (result is
not in range 0...255). When there is no overflow, this flag is set to 0. This flag uses bit 0.
Example:
mov ah, 253
add ah, 12
These set of instructions will set the carry flag to 1 as the result of an unsigned arithmetic
operation is too large to fit into the destination (ah).
Parity flag (PF) is set if the least-significant byte in the result contains an even number of 1
bit. Even if result is a word only 8 low bits are analyzed. This flag uses bit 2.
Example:
Mov al, 05 (load 05H in register ax)
This instruction will set the parity flag to 1 as the BCD code of 05H is 00000101, which
contains even number of ones i.e., 2.
Auxiliary Carry flag (AC) is set when an arithmetic operation causes a carry from bit 3 to
bit 4. (Unsigned overflow for low nibble -4 bits) This flag uses bit 4.
Example:
MOV ax, 2B (load 2BH in register A)
MOV bx, 39 (load 39H in register B)
ADD ax, bx
These set of instructions will set the auxiliary carry flag to 1, as on adding 2B and 39,
addition of lower order nibbles B and 9 will generate a carry.
Carry Flag:
Control flags control the CPU’s operation.
Direction Flag (DF) this flag is used by some instructions to process data chains, when this flag
is set to 0- the processing is done forward, when this flag is set to 1 the processing is done
backward. This flag uses bit 10.
Interrupt enable Flag (IF) when this flag is set to 1 CPU reacts to interrupts from external
devices. This flag uses bit 9.
TF (Trap Flag) This flag is used to Control Permits operation of the processor in single-step
mode. This flag uses bit 8.
CMP Instruction
CMP (compare) instruction performs an implied subtraction of a source from destination operand
i.e. Subtract second operand from first for flags only. Neither operand is modified.
CMP instructions affect flags only and do not store a result (these instructions are used to make
decisions during program execution).
FLAGS: CF, ZF, SF, OF, PF, AF.
Examples:
Destination < Source:
mov ax, 5
cmp ax, 10 ;CF = 1
Destination = Source
mov ax, 1000
mov cx, 1000
cmp cx, ax ; ZF = 1
Destination > Source
mov si, 105
cmp si, 0 ; ZF = 0 and CF = 0
For each add instruction in this exercise, assume that AX contains the given contents before the
instruction is executed. Show the contents of AX as well as the values of the CF, OF, SF, PF, AF
and ZF after the instruction is executed. All numbers are in hex. (Hint: add ax, 45 adds 45 to the
contents of register ax and stores the result back in ax).
In the following instruction sequence, show the values of the Carry, Zero, and Sign flags where
indicated:
mov al, 01001011b
test al, 10100100b ; a. CF= ZF= SF=
mov al, 00000110b
cmp al, 00000101b ; b. CF= ZF= SF=
mov al, 00000101b
cmp al, 00000111b ; c. CF= ZF= SF=
Objective
Learn how to use of Boolean operators
Boolean Operators
AND Instruction
AND instruction performs boolean (bitwise) AND operation b/w each pair of matching bits in
two operands and place the result in dest. operand.
AND dest, source
AND instruction can be b/w
AND reg, reg
AND reg, mem
AND reg, imm
AND mem, reg
AND mem,imm
Note: -Operand can be 8, 16 or 32 bits and they must be of same size.
OR Instruction
OR instruction performs boolean (bitwise) OR operation b/w each pair of matching bits in two
operands and place the result in dest. operand.
OR dest, source
OR instruction can be b/w
OR reg, reg
OR reg, mem
OR reg, imm
OR mem, reg
OR mem,imm
XOR Instruction
XOR instruction performs boolean (bitwise) XOR operation b/w each pair of matching bits in
two operands and place the result in dest. operand.
XOR dest, source
Note:- XOR instruction uses the same operand combinations as AND and OR instructions.
NOT Instruction
NOT instruction toggles all bits in an operand.
Test Instruction
TEST instruction performs an implied AND operation b/w each pair of matching bits in two
operands and set the flag accordingly. TEST operand1, operand2
The difference b/w TEST and AND instruction is that TEST Does not modify the destination
operand.
TEST instruction permits the same operand combinations as the AND instruction.
Exercise 11.2:
In the following instruction sequence, show the changed value of registers where indicated, in
hexadecimal:
mov a1, 7Ah
not a1 ;a
mov a1, 3Dh
and al, 74h ;b
mov al, 9Bh
or al, 35h ;c
mov al, 72h
xor al, 0dch ;d
Exercise 11.3:
Write a single instruction that clears the high 8 bits of AX and does not change the
low 8 bits.
Exercise 11.4:
Write a single instruction that sets the high 8 bits of AX and does not change the
low 8 bits.
Objective
Learn how to write procedures in Assembly
Learn how to call procedures
Procedures
Procedure is a part of code that can be called from your program to make some specific task.
Procedures make program more structural and easier to understand. Generally, procedure returns
to the same point from where it was called.
name - is the procedure name, the same name should be in the top and the bottom, this is used to
check correct closing of procedures.
Probably, you already know that RET instruction is used to return to operating system. The same
instruction is used to return from procedure (actually operating system sees your program as a
special procedure).
PROC and ENDP are compiler directives, so they are not assembled into any real machine code.
Compiler just remembers the address of procedure.
Web Resources
http://www.svu.edu.eg/specialunits/acadeet/dwnldFiles/trainMater/provis/emu86_short.pdf
EXERCISE
Exercise 12.1:
Write a program in assembly that takes two number from user in a procedure and calculates area
in main procedure.
Exercise 12.2:
Write a program in assembly language that call a procedure to calculate 2 4. (hint: use multiple
calls).
In the context of OBE (Outcome-Based Education) system, an open-ended lab is a laboratory activity that
allows students to design and conduct their own experiments or investigations, without being restricted by
a predetermined procedure or outcome.
In an open-ended lab, students are given a problem or question to investigate, and are then required to
plan and carry out the experiment on their own. This type of lab allows students to apply critical thinking,
problem-solving, and decision-making skills, as they must make their own choices about what data to
collect, what variables to control, and what methods to use.
Open-ended labs can be challenging, as they require students to take greater responsibility for their
learning and may involve more uncertainty and risk. However, they can also be more engaging and
motivating for students, as they allow for greater creativity, exploration, and discovery.
A computer with a processor that supports different cache sizes (e.g., 2MB, 4MB, MB, 16MB,
32MB etc.)
Benchmarking software (e.g., linepack, antutu, geekbench, SPEC CPU, or any other that you
familiar with)
Performance measurement tools (e.g., perf)
Any other you think as important.
Procedure and methodology: (CLO3=10 Marks, CLO4=10 Marks)
1. Formulate a hypothesis about how the cache size will affect the performance of the computer
system. CLO3, Cog 4
2. Plan an experiment to test your hypothesis. Consider factors such as the types of benchmarks to
use, the range of cache sizes to test, and the number of trials to perform. CLO4, P-3
3. Conduct the experiment by running the benchmarks on the computer system with different cache
sizes (you can use lab pcs, your own laptops, Mac system, all with different specs). CLO4, P-3
4. Collect performance data using the measurement tools. CLO4, P-3
5. Analyze the data to determine the effect of cache size on performance, and to validate or refute
your hypothesis. CLO3, Cog 4
6. Write a report summarizing your findings and conclusions. CLO3, Cog 4
7. Draw a complete working diagram (flow chart, algorithm, architectural diagram) to describe the
flow of processes. CLO3, Cog 4
Benchmarking CLO4
(tools)/simulation parameters
(tabular form)/Results
In this open-ended lab, You are free to design Your own experiments, choose benchmarks, and collect
data. You must use critical thinking and problem-solving skills to determine the best approach for testing
hypothesis. The open-ended nature of the lab allows for creativity and exploration, while still providing a
clear problem statement and objectives.
Example:
consider the following pseudo-code:
if (total >= 100) or (count = 10) then
add value to total;
end if;
Web Resources
http://www.svu.edu.eg/specialunits/acadeet/dwnldFiles/trainMater/provis/emu86_short.pdf
Videos Resources
www.youtube.com/watch?v=pcyvLYb5XDc
www.youtube.com/watch?v=SqcVG6CA4J4
Objective:
Learn how to repeat execution of a program fragment.
Learn the working of loop instruction
Learn implementation of while, until, and for loops.
Loop Instruction
The LOOP instruction provides a simple way to repeat a block of statements a specific number
of times. CX is automatically used as a counter and is decremented each time the loop repeats.
Its syntax is:
LOOP destination
The execution of the LOOP instruction involves two steps: First, it subtracts 1 from CX. Next, it
compares CX to zero. If CX is not equal to zero; a jump is taken to the label identified by
destination. Otherwise, if CX equals zero, no jump takes place and control passes to the next
instruction. In the following example, we add 1 to AX each time the loop repeats. When the loop
ends, AX = 5 and CX = 0:
mov ax, 0
mov cx,5
L1:
inc ax
loop L1
A while loop is a pre-test loop – the continuation condition, a Boolean expression, is checked
before the loop body is executed. Whenever it is true the loop body is executed and then the
continuation condition is checked again. When it is false execution continues with the statement
following the loop. It may take several 80x86 instructions to evaluate and check a continuation
condition. In 80x86 implementation of a while loop follows a pattern much like this one:
while1: . ; code to check Boolean expression
.
.
body: . ; loop body
.
.
jmp while1 ; go check condition again
endWhile1:
Example:
consider the following code
while (sum < 100) loop
sum=sum+count;
count=count+1;
end while;
Example:
Consider the following code
BX can be used to store index counting from 1 to 50, while the CX register counts down from 50
to 1.
The corresponding assembly code is as follows:
Example:
consider the following code
repeat
add 2*count to sum;
add 1 to count;
until (sum > 1000);
Assuming that the sum references a word in memory, the following 80x86 code implements the
pseudocode, using the CX register for count.
Web Resources
http://www.svu.edu.eg/specialunits/acadeet/dwnldFiles/trainMater/provis/emu86_short.pdf
Videos Resources
www.youtube.com/watch?v=pcyvLYb5XDc
www.youtube.com/watch?v=SqcVG6CA4J4
Exercise 15.2:
Write a program in assembly to break and print a 5-digit number in reverse order.
Exercise 15.3:
Compute the following equation in assembly language. N will be entered by the user.
F(x)=1+x/2+x/3+x/4+x/5+x/6…… up to n terms
Exercise 15.4:
Write a code to convert a decimal number into binary using assembly language.
Exercise 15.5:
Write an assembly language program that will prompt for an integer n and the print the table of n upto 20
on screen.
Exercise 15.6:
Write an assembly language program that will prompt for an integer n, compute the factorial of n and
display it on screen.