Download as pdf or txt
Download as pdf or txt
You are on page 1of 89

COMPUTER ARCHITECTURE &

LOGIC DESIGN
LAB MANUAL

SUBMITTED TO: SIR SHOAIB


EMAN ZAI (2022-BSE-049)
AREEJ INTISHAD (2022-BSE-046)
SYEDA FARWA BATOOL (2022-BSE-071)
LAB NO. 01

EMAN ZAI
SYEDA FARWA BATOOL
AREEJ INTISHAD
EXPERIMENTAL RESULTS
1. AND GATE :

INPUT A = 1, INPUT B = 1 , OUTPUT Q = 1

 TRUTH TABLE :
INPUT A INPUT B OUTPUT Q
0 0 0
0 1 0
1 0 0
1 1 1

2. OR GATE :

INPUT A = 0 , INPUT B = 1 , OUTPUT Q = 1


 TRUTH TABLE :
INPUT A INPUT B INPUT Q
0 0 0
0 1 1
1 0 1
1 1 1

3. NAND GATE :

INPUT A = 1, INPUT B = 0 , OUTPUT Q = 1


 TRUTH TABLE :

INPUT A INPUT B OUTPUT Q


0 0 1
0 1 1
1 0 1
1 1 0

4. NOR GATE :

INPUT A = 0 , INPUT B = 1 , OUTPUT Q = 0


 TRUTH TABLE :
INPUT A INPUT B INPUT Q
0 0 1
0 1 0
1 0 0
1 1 0

5. X-OR GATE :

INPUT A = 0 , INPUT B = 1 , OUTPUT Q = 1


 TRUTH TABLE :
INPUT A INPUT B INPUT Q
0 0 0
0 1 1
1 0 1
1 1 0

6. NOT GATE :

INPUT A = 0 , OUTPUT Q = 1
 TRUTH TABLE :

INPUT A INPUT Q
0 1
0 0
COMPUTER ARCHITECTURE &
LOGIC DESIGN
LAB NO. 02

SUBMITTED TO: SIR SHOAIB

EMAN ZAI
AREEJ INTISHAD
SYEDA FARWA BATOOL
EXPERIMENTAL RESULTS
1. Working of AND gate using NAND gate

INPUT A = 1 , INPUT B =1 , OUTPUT C = 1

• TRUTH TABLE :

INPUT A INPUT B OUTPUT C


0 0 0
0 1 0
1 0 0
1 1 1

2. Working of OR gate using NAND gate

INPUT A = 1, INPUT B = 0 , OUTPUT C=1

INPUT A INPUT B OUTPUT C


0 0 0
0 1 1
1 0 1
1 1 1

3. Working of NOT gate using NAND


gate

INPUT A =0 , OUTPUT B = 1

TRUTH TABLE:
INPUT A OUTPUT B
0 1
0 0
COMPUTER ARCHITECTURE &s
LOGIC DESIGN

LAB NO. 03
SUBMITTED TO: SIR SHOAIB

EMAN ZAI
SYEDA FARWA BATOOL
AREEJ INTISHAD
EXPERIMENTAL RESULT
Fill in the following truth table in the presence of the
lab instructor.
4.1. Truth Table for XOR Gate: (Details above)
A B OUTPUT
0 0 0
1 0 1
0 1 1
1 1 0
Write Boolean function for XOR gate:
Draw NAND logic diagram for the XNOR gate:
Truth Table for XNOR Gate:
A B OUTPUT
0 0 1
0 1 0
1 0 0
1 1 1
Write Boolean function for XNOR gate:
COMPUTER ARCHITECTURE &
LOGIC DESIGN

LAB NO. 04
SUBMITTED TO: SIR SHOAIB

EMAN ZAI
SYEDA FARWA BATOOL
AREEJ INTISHAD

DATED: 27 0CTOBER, 2023


EXPERIMENT # 4
IMPLEMENTATION OF HALF ADDER & FULL ADDER

HALF ADDER:

A=1, B=1 => C=1 & Sum=0


HALF ADDER TRUTH TABLE AND LOGIC DESIGN

FULL ADDER:

A=1, B=1, Cin=1 => Cout=1 & Sum=1


FULL ADDER TRUTH TABLE AND LOGIC DESIGN
FULL ADDER LOGIC DESIGN
COMPUTER ARCHITECTURE AND LOGIC DESIGN

Lab-05

EMAN ZAI
AREEJ INTISHAD
SYEDA FARWA BATOOL
LAB 06

EMAN ZAI

AREEJ INTISHAD

SYEDA FARWA BATOOL


4-1 mux:
decoder:
4X2 ENCODER
EMAN ZAI
AREEJ INTISHAD
SYEDA FARWA BATOOL
LAB NO.7

1. Comment on Architecture of the following


CPUs
ANSWER:
PIC18 (Microchip):

The PIC18 is a family of microcontrollers designed by


Microchip Technology.
It uses a modified Harvard architecture with a reduced
instruction set.
Commonly used in embedded systems, industrial applications,
and more.
Atmel (ATmega series):

Atmel, now a part of Microchip Technology, produced


microcontrollers like the ATmega series.
Utilizes modified Harvard architecture.
Known for low power consumption and used in various
embedded applications.
IBM Power2:

The Power2 architecture is an older generation of IBM's


POWER architecture.
It is a RISC (Reduced Instruction Set Computing) architecture.
Historically significant for its use in IBM mainframes and
servers.
Itanium (Intel):

Itanium, formally known as Intel Itanium, is an architecture


developed by Intel.
It is an example of Explicitly Parallel Instruction Computing
(EPIC) architecture.
It was designed for high-performance computing but faced
limited adoption.
EPIC (Explicitly Parallel Instruction Computing):

EPIC is a computing architecture developed collaboratively by


Intel and Hewlett Packard (HP).
It emphasizes instruction-level parallelism.
Itanium processors are based on EPIC architecture.
Intel i860:

The Intel i860, also known as the Intel 860 RISC processor, is a
historical processor.
It features a unique design combining scalar and vector
processing units.
Originally intended for graphics and scientific applications.
Transmeta Crusoe:

The Crusoe processors were designed by Transmeta for mobile


computing.
They used a code-morphing software layer to emulate other
processor architectures.
Known for power efficiency, especially in early ultraportable
devices.
StarCore (Lucent/Motorola):

StarCore is a DSP (Digital Signal Processor) architecture


developed by Lucent and Motorola.
Primarily used for multimedia and communication applications.
Provides high performance in handling signal processing tasks.
TigerSHARC (Analog Devices):

TigerSHARC is a DSP architecture designed by Analog Devices.


It is optimized for high-performance signal processing
applications.
Used in audio processing, telecommunications, and other DSP-
intensive tasks.
Infineon:

Infineon produces a range of microcontrollers and processors.


Specific architectures may vary based on the product line.
Known for providing solutions for automotive, industrial, and
security applications.
These comments provide a brief overview, and each architecture
has its strengths and use cases based on the design goals and
intended applications.
2- Daily life examples of embedded systems /
special purpose processors around us.

ANSWER:
Smartphones: Embedded processors manage various
functions, such as communication, sensors, and
multimedia.

Washing Machines: Micro controllers control washing


cycles and user interface.

Microwaves: Embedded systems manage cooking times


and power levels.

Refrigerators: Embedded systems control temperature,


defrost cycles, and energy-saving features.

Digital Cameras: Special processors handle image


processing and compression.

Fitness Trackers: Embedded systems monitor and


analyze physical activity.

Smart TVs: Processors control video processing, apps,


and internet connectivity.

Air Conditioners: Embedded controllers regulate


temperature and airflow.

Digital Thermostats: Micro controllers manage heating


and cooling systems.

Car Engine Control Units (Ecus): Special-purpose


processors optimize engine performance.

Anti-lock Braking Systems (ABS): Embedded systems


enhance vehicle safety during braking.

Traffic Light Controllers: Micro controllers manage


traffic flow at intersections.

Elevators: Embedded systems control movement, door


operations, and safety features.

Automatic Teller Machines (ATM's): Embedded systems


handle transactions and security.

Printers: Special-purpose processors manage printing


tasks.

Medical Devices: Implantable devices and medical


equipment often use embedded systems for monitoring
and treatment.

Digital Thermometers: Embedded processors measure


and display temperature.

Key less Entry Systems: Special-purpose processors


control access to vehicles and buildings.
CCTV Cameras: Embedded systems process video feeds
for surveillance.

Automatic Pet Feeders: Embedded systems control


feeding schedules for pets.

3- Name and Comment on Architecture of the


processor of your PC and Mobile

MOBILE:
NAME : SAMSUNG A14
The Samsung Galaxy A14 5G has a 64-bit CPU architecture. 64-
bit CPUs are more efficient than 32-bit CPUs, which are more
efficient than 16-bit CPUs.
Here are some specifications for the Samsung Galaxy A14 5G:
 Processor: Samsung Exynos 1330
 CPU cores: Octa-core
 CPU technology: 5 nm
 CPU max speed: 2.4 GHz
 GPU: Mali-G68 MC4
 OS: Android v13
 RAM: 4 GB
 ROM: 64 GB
The Samsung Galaxy A14 5G has the following AnTuTu
Benchmark scores:
 Overall: 409,771
 CPU: 131,896
 GPU: 84,030
 Memory: 78,109

LAPTOP : HP Elite Book Folio 9470m


Processor: Intel ULV with v Pro support
The HP Elite Book Folio 9470m has a third-generation Intel
Core i5 processor. The processor has two cores, a clock speed
of 1.8 GHz, and can reach speeds of up to 2.8 GHz. The HP
Elite Book Folio 9470m also has:
4 GB of RAM
180 GB Intel SSD
Integrated Intel HD 4000 graphics
Here are some other specifications for the HP Elite Book Folio
9470m:
14-inch screen
1366 x 768 (HD) resolution
128 GB SSD SATA 6Gb/s
52 Wh
Name:EMAN ZAI
AREEJ INTISHAD
FARWA BATOOL

INSTRUCTOR:SIR SHOAIB
Hello World
Program 1:

org 100h
.data ; Declare variables
hello_message db 'Hello','World',0dh,0ah,'$'
.code ; Write code
main proc
mov ax,@data ; Copy the address of data
mov ds,ax ; Segment into DS register
mov dx,offset hello_message
mov ah,9 ; MS-Dos Function to display string
INT 21H
mov ax,4C00h ; Halt the program and return control to
OS
INT 21H
main endp

CONSOLE:
Program 2:
org 100h

mov ah, 02h ; Function to display character


mov dx, 'H' ; Display 'H'
int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'e' ; Display 'e'


int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'l' ; Display 'l'


int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'l' ; Display 'l'


int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'o' ; Display 'o'


int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'W' ; Display 'W'


int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'o' ; Display 'o'


int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'r' ; Display 'r'


int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'l' ; Display 'l'


int 21h

mov dx, 0Dh ; Move to a new line


int 21h
mov dx, 0Ah ; Move to a new line
int 21h

mov dx, 'd' ; Display 'd'


int 21h

mov dx, '$' ; End the program


int 21h
mov ah, 4Ch ; Halt the program and return control to OS
int 21h

CONSOLE:

Program 3:

org 100h

mov ah, 02h ; Function to display character

mov dx, 'H' ; Display 'H'


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h
mov dx, 'e' ; Display 'e'
int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, 'l' ; Display 'l'


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, 'l' ; Display 'l'


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, 'o' ; Display 'o'


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, 'W' ; Display 'W'


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, 'o' ; Display 'o'


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h
mov dx, 'r' ; Display 'r'
int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, 'l' ; Display 'l'


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, 'd' ; Display 'd'


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov dx, ' ' ; Display space


int 21h

mov ah, 4Ch ; Halt the program and return control to OS


int 21h
CONSOLE:

Program 4:
org 100h

mov ah, 09h ; Function to display string

mov dx, offset hello_message ; Display 'Hello' on the first line


int 21h

mov dx, offset newline ; Move to a new line


int 21h

mov dx, offset world_message ; Display 'World' on the second


line
int 21h

mov ah, 4Ch ; Function to exit the program


int 21h

hello_message db 'Hello$' ; 'Hello' text


world_message db 'World$' ; 'World' text
newline db 0Dh, 0Ah, '$' ; Newline characters with a
terminating dollar sign

CONSOLE:
LAB # 8

NAME:EMAN ZAI
AREEJ INTISHAD
SYEDA FARWA BATOOL
TASKS
Assemble and trace following programs using DEBUG. For each
program, write down the contents of only those registers and
flag bits which have been modified by the given program.
Program 1: [AX=0020, BX=00AA]
mov ah, bl

Program 2: [AX=06AF]
mov ah,3

Program 3: [Assume registers and flag bits are set to default


values]
mov ah,7F
mov ax,1234
mov bh, al
mov bl, ah

Program 4: [Assume registers and flag bits are set to default


values]
mov al,81
add al,FE

Program 5: [Assume registers and flag bits are set to default


values]
mov ax, 5510
sub al,2

Program 6: [Assume registers and flag bits are set to default


values]
mov al, 3e
add al, 3e

Program 7: [Assume registers and flag bits are set to default


values]
mov ah,2
mov dl,41

Program 8: [Assume registers and flag bits are set to default


values]
mov ax, 5
mov bx,10
add ax,bx

Program 9: [Assume registers and flag bits are set to default


values]
mov al,FFFE
sub al,2
mov bl,8c
mov bh,2D
add bx,ax
Program 10: [Assume registers and flag bits are set to default
values]
mov ax, 1234
mov bx,ax
mov cx,ax
add ch, al
add bl, ah
add ax, FFFF
dec bx
COMPUTER ARCHITECTURE & LOGIC DESIGNS

LAB NO. 09

EMAN ZAI
SYEDA FARWA BATOOL
AREEJ INTISHAD
Exercise 9.1
Write a program that input a character from user is in lowercase,
the program will
convert it to uppercase and will display it on console after
conversion .(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.)
CODE:

CONSOLE:
Exercise 9.2
Write a program that input a character from user. The program
will display it ten times on screen in newline.
CONSOLE:
CODE:
12/28/2023 COMPUTER
ARCHITECTURE
&LOGIC DESIGNS
LAB NO.10

Eman zai Areej intishad Syeda farwa batool


2022-BSE-049 2022-BSE-046 2022-BSE-071
LAB TASK
Activity 3.1:
Show the working of following instruction by taking the two‟s complement
• 9 – 6 = 00000011

9= 00001001
6 = 00000110
Now toggle bits of 6 : 11111001
Now add +1 : 11111010
Now add above numbers according to formula : A+(-B):
9+(-6) = 00000011
Here 0 indicates + sign so, 9 + (-6)= 0000011

• 146 – 9 =10001001

146 = 10010010
9=00001001
Now toggle all bits of 9 = 11110110
Add 1 to above : 11110111
146 -9 = 10010010 + (11110111) = 110001001
Now we will discard 1 as compiler execute only 7 bits
Here 1 indicates - sign so, 146 -9 = 10001001

Activity 3.2:
95C3 +1 -->01100000b

DE10 +1 --> 00000001b

Activity 3.3:
Addition of two single digits numbers

CODE:
.data
Num1 db 0
Num2 db 0
msgNum1 db "Enter the 1st No: $"
msgNum2 db 10,13,"Enter the 2nd No: $"
msgAns db 10,13,"The answer is: $"
.code
;========================================
main proc
mov ax, @data
mov ds, ax
mov dx,offset msgNum1
mov ah, 09h
int 21h
mov ah, 1 ; accept 1 char from keyboard
int 21h
sub al,30h ; convert to number
mov Num1,al
;=======================================
mov ax, @data
mov ds, ax
mov dx,offset msgNum2
mov ah, 09h
int 21h
mov ah, 1 ;accept 1 char from keyboard
int 21h
sub al,30h ;convert to number
mov Num2,al
;++++++++++++++++++++++++++++++++++++++++++
;ADD Num1,Num2 is illegal
mov bh, Num1
add bh, Num2
add bh, 30h ;convert back to ASCII equiv
mov ax, @data
mov ds, ax
mov dx,offset msgAns ;some message
mov ah, 09h
int 21h
mov dl,bh
mov ah,2 ;print answer
int 21h
mov ah,00h ;pause..... resume when press any key
int 16h
main endp
end
CONSOLE:

Activity 3.4:
Addition of two multi-digits numbers

CODE:
include 'emu8086.inc';include library
.data
num1 dw 0
num2 dw 0
; get the multi-digit signed number from the keyboard, and store the
; result in cx register:
call scan_num ; Get first number
mov num1, cx ; store first number:
call scan_num ; Get second number
mov num2, cx ; store second number:
mov ax, num1 ; Can not add two memory variables
add ax, num2 ; add num2 in ax and store result in ax
call print_num ; print ax value.
DEFINE_PRINT_NUM ; used by print_num proc
DEFINE_PRINT_NUM_UNS ; used by print_num proc
DEFINE_SCAN_NUM ; used by scan_num proc

CONSOLE:

Exercise 3.1
Modify above program to format the output.
Enter first number: 25
Enter second number: 50
The sum of two number is : 75
Note: - GOTOXY col, row- macro to sets cursor position.
CODE:

include emu8086.inc ;include library


.data
num1 dw 0
num2 dw 0
; get the multi-digit signed number from the keyboard, and store the
; result in cx register:
print "Enter first number ";
call scan_num ; Get first number
mov num1, cx ; store first number:
gotoxy 10,1 ;
print "Enter 2nd number ";
call scan_num ; Get second number
mov num2, cx ; store second number:
mov ax, num1 ; Can not add two memory variables
add ax, num2 ; add num2 in ax and store result in ax
gotoxy 10,3 ;
print "Answer : ";
call print_num ; print ax value.
DEFINE_PRINT_NUM ; used by print_num proc
DEFINE_PRINT_NUM_UNS ; used by print_num proc
DEFINE_SCAN_NUM ; used by scan_num proc
END
CONSOLE :
Exercise 3.2:
Write a program that reads five unsigned integers from user and display sum of those
five integers on the screen.
CODE:
include emu8086.inc ;include library
.data
num1 dw 0 ; Define variables for each number
num2 dw 0
num3 dw 0
num4 dw 0
num5 dw 0
sum dw 0 ; Variable to store the sum
msgFirst db "Enter first number: $"
msgSecond db 10, 13, "Enter second number: $"
msgThird db 10, 13, "Enter third number: $"
msgFourth db 10, 13, "Enter fourth number: $"
msgFifth db 10, 13, "Enter fifth number: $"
msgResult db 10, 13, "The sum of five numbers is: $"

.code
main:
mov ax, @data
mov ds, ax

; Input for the first number


mov dx, offset msgFirst

mov ah, 09h


int 21h

call scan_num ; Get first number


mov num1, cx ; Store first number

; Input for the second number


mov dx, offset msgSecond
mov ah, 09h
int 21h

call scan_num ; Get second number


mov num2, cx ; Store second number

; Input for the third number


mov dx, offset msgThird
mov ah, 09h
int 21h

call scan_num ; Get third number


mov num3, cx ; Store third number

; Input for the fourth number


mov dx, offset msgFourth
mov ah, 09h
int 21h

call scan_num ; Get fourth number


mov num4, cx ; Store fourth number
; Input for the fifth number
mov dx, offset msgFifth
mov ah, 09h
int 21h

call scan_num ; Get fifth number


mov num5, cx ; Store fifth number

; Calculate the sum


mov ax, num1 ; Move the first number to ax
add ax, num2 ; Add the second number
add ax, num3 ; Add the third number
add ax, num4 ; Add the fourth number
add ax, num5 ; Add the fifth number
mov sum, ax ; Store the final sum

; Display the sum


mov dx, offset msgResult
mov ah, 09h
int 21h

mov ax, sum ; Move the sum to ax for printing


call print_num ; Print the sum

mov ax, 4C00h ; Exit to DOS


int 21h
DEFINE_PRINT_NUM ; used by print_num proc
DEFINE_PRINT_NUM_UNS ; used by print_num proc
DEFINE_SCAN_NUM ; used by scan_num proc
END main
CONSOLE:

Exercise 3.3:
Write a program using instruction shown in table and fill in the table with the offsets
of the instructions in the code segment.

CODE:
.data
number dw 100
sum dw 0

.code
main PROC
mov ax, number
add ax, 158
mov sum, ax
mov ax, 0

mov ah, 4Ch ; exit to DOS


int 21h
main ENDP
END main ; end of program

Instruction Segment and Offset


mov ax, number 0000
add ax, 158 0003
mov sum, ax 0006
mov ax, 0 0009
1/4/2024
COMPUTER
ARCHITECTURE &
LOGIC DESIGNS
LAB 11

Eman zai
Areej intishad
Syeda farwa batool
EXERCISE 4.1
INSTRUCTION 1:

INSTRUCTION 3:
EXERCISE 4.2:
Calculate the range of signed and unsigned numbers that db, dw, dd, dq and dt
directives can specify. Mention the adopted method i.e how you will calculate the
range.
EXERCISE 4.3:
byte1 db 10110111b : 183
byte2 db 35q :29
byte3 db 0E8h :232
byte4 db 150 : 150
byte5 db -91 : 165
byte6 db „K‟ : 75
byte7 db „k‟ :107
byte8 db “Ali‟s book” : 065
byte9 db 5 DUP("< >") : 060
byte10 dw 1000000 : overflow error
Byte11 dw "Maria Sultan": 4D077- 90144

byte12 dw “1010b”: 31049-62098


byte13 dw “BSE 5A&B”:42066-42066
byte14 dw “Computer Architecture”:43067-45101
byte15 dw 6 DUP (“<:p>”):06006

Exercise 4.4
Define 5 different 8-bit Numbers. Write a programme to do the
following : Use the DB directive to define the following list of numbers and
name it myarray.
• 36h, 37h, 39h, 40h
• Display the array in reverse order.
OPEN ENDED LAB
OPEN ENDED LAB
Exercise 5.1
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.
CODE:
include emu8086.inc ;include library

.data
x dw 0 ; Define variable for x
y dw 0 ; Define variable for y
z dw 0 ; Define variable for z
result dw 0 ; Variable to store the result
msgX db "Enter value for x: $"
msgY db 10, 13, "Enter value for y: $"
msgZ db 10, 13, "Enter value for z: $"
msgResult db 10, 13, "Result (x-y + 2z- 1): $"

.code
main:
mov ax, @data
mov ds, ax

; Input for x
mov dx, offset msgX
mov ah, 09h
int 21h

call scan_num ; Get value for x


mov x, cx ; Store value for x

; Input for y
mov dx, offset msgY
mov ah, 09h
int 21h

call scan_num ; Get value for y


mov y, cx ; Store value for y

; Input for z
mov dx, offset msgZ
mov ah, 09h
int 21h

call scan_num ; Get value for z


mov z, cx ; Store value for z

; Calculate the result


mov ax, x ; Move the value of x to ax
sub ax, y ; Subtract the value of y
shl z, 1 ; Multiply the value of z by 2
add ax, z ; Add the doubled value of z
sub ax, 1 ; Subtract 1
mov result, ax ; Store the final result

; Display the result


mov dx, offset msgResult
mov ah, 09h
int 21h

mov ax, result ; Move the result to ax for printing


call print_num ; Print the result

mov ax, 4C00h ; Exit to DOS


int 21h

DEFINE_PRINT_NUM ; used by print_num proc


DEFINE_PRINT_NUM_UNS ; used by print_num proc
DEFINE_SCAN_NUM ; used by scan_num proc
END main
CONSOLE:
Exercise 5.2
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)
CODE:
include emu8086.inc ;include library
.data
length dw 0 ; Define variable for length
width dw 0 ; Define variable for width
height dw 0 ; Define variable for height
surface_area dw 0 ; Variable to store the surface area
msgLength db "Enter Length: $"
msgWidth db 10, 13, "Enter Width: $"
msgHeight db 10, 13, "Enter Height: $"
msgResult db 10, 13, "Surface Area: $"

.code
main:
mov ax, @data
mov ds, ax

; Input for length


mov dx, offset msgLength
mov ah, 09h
int 21h

call scan_num ; Get length


mov length, cx ; Store length

; Input for width


mov dx, offset msgWidth
mov ah, 09h
int 21h

call scan_num ; Get width


mov width, cx ; Store width

; Input for height


mov dx, offset msgHeight
mov ah, 09h
int 21h

call scan_num ; Get height


mov height, cx ; Store height

; Calculate surface area


mov ax, length
imul width ; Multiply length by width and store the result in ax
mov bx, length
imul height ; Multiply length by height and store the result in bx
mov cx, width
imul height ; Multiply width by height and store the result in cx

shl ax, 2 ; 2 * (length * width)


add ax, bx ; 2 * (length * width + length * height)
add ax, cx ; 2 * (length * width + length * height + width * height)

mov surface_area, ax ; Store the surface area

; Display the result


mov dx, offset msgResult
mov ah, 09h
int 21h

mov ax, surface_area ; Move the surface area to ax for printing


call print_num ; Print the surface area

mov ax, 4C00h ; Exit to DOS


int 21h
DEFINE_PRINT_NUM ; used by print_num proc
DEFINE_PRINT_NUM_UNS ; used by print_num proc
DEFINE_SCAN_NUM ; used by scan_num proc
END main
CONSOLE:
1/18/2024 LAB 13
SUBMITTED TO: SIR MUHAMMAD SHOAIB

EMAN ZAI
AREEJ INTISHAD
SYEDA FARWA BATOOL
Exercise 7.1
In the following instruction sequence. Show the changed value of AL where indicated,
in binary:

1. mov a1, 00001111b


and al, 00111011b ;a

2. mov al, 6Dh


and al, 4Ah ;b

3. mov al, 00001111b


or al, 61h ;
4. mov al, 94
xor al, 37h ;d

Exercise 7.2
In the following instruction sequence, show the changed value of AL 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, odch ;d

Exercise 7.3
In the following instruction sequence, show the values of the Carry, Zero, and Sign flags
where indicated:

 mov al,00001111b
test al,00000010b ;

CF=0, ZF=0, SF=0

 mov al,00000110b
cmp al,00000101b ;

CF=0, ZF=0, SF=0

 mov al,00000101b
cmp al,00000111b ;

CF=1, ZF=0, SF=1

Exercise 7.4
Write a single instruction that clears the high 8 bits of AX and does not change the low 8 bits.
Exercise 7.5
Write a single instruction that sets the high 8 bits of AX and does not change the low 8
bits.

You might also like