Laboratory Manual Computer Engineering: Microprocessor Lab
Laboratory Manual Computer Engineering: Microprocessor Lab
Microprocessor lab
Laboratory Manual
Computer Engineering
A.Y.: 2021-22
Microprocessor lab
Laboratory Manual
Table of Contents
Sr . No. Topic Page. No.
1. Course Objective
2. Program Outcomes
3. Experiment Learning Outcome (ELO)
Sessions
Write an X86/64 ALP to accept five 64 bit Hexadecimal numbers
1. from user and store them in an array and display the accepted
numbers.
Write an X86/64 ALP to accept a string and to display its
2.
length.
Write an X86/64 ALP to find the largest of given
3.
Byte/Word/Dword/64-bit numbers.
Write a switch case driven X86/64 ALP to perform 64 -bit
4. hexadecimal arithmetic operations (+,-,*, /) using suitable macros.
Define procedure for each operation.
Write X86/64 ALP to count number of positive and negative
5. numbers from the array
Write 64 bit ALP to convert 4-digit Hex number into its equivalent
BCD number and 5-digit BCD number into its equivalent HEX
number. Make your program user friendly to accept the choice
6. from user for:
(a) HEX to BCD b) BCD to HEX (c) EXIT.
Display proper strings to prompt the user while accepting the input
and displaying the result. (use of 64-bitregisters is expected)
7. Write X86/64 ALP to switch from real mode to protected mode and
display the values of GDTR, LDTR, IDTR, TR and MSW
Registers
Write X86/64 ALP to perform non-overlapped block transfer
8. without string specific instructions. Block containing data can be
defined in the data segment.
Write X86/64 ALP to perform overlapped block transfer with string
9. specific instructions. Block containing data can be defined in the
data segment.
Write X86/64 ALP to perform multiplication of two 8-bit
10. hexadecimal numbers. Use successive addition and add and shift
method. (use of 64-bit registers is expected)
Course Outcomes:
CO1: Understand and compare Architecture of advanced processors and its resources.
CO2: Apply assembly language programming to develop real life applications.
CO3: Implement parallel processing and math Co-processor.
CO4: Compare different processor configurations.
2. To analyze the problem by finding its domain and applying domain specific skills.
3. To understand the design issues of the product/software and develop effective solutions
with appropriate consideration for public health and safety, and cultural, societal, and
environmental considerations.
11. To apply the knowledge of Computer Engineering for development of projects, finance
and management.
12. To keep in touch with current technologies and inculcate the practice of lifelong
learning.
Experiment Learning Outcome:
ELO1: Apply logical instruction sets to segregate positive and negative numbers.
ELO2: Apply the concept of overlapped and non-overlapped block transfer in the program with
or without using string instruction.
ELO3: Convert hexadecimal number to BCD and vice versa with the help of assembly language
programming.
ELO4: Choose different multiplication methods such as add & shift and successive addition for
multiplication of two numbers without using MUL instruction.
ELO5: Analyze the difference between near and far procedure to find number of lines, blank
spaces & occurance of character using nasm.
ELO6: Apply the concept of real mode and protected mode in 8086 ALP to implement a
program to display values from GDTR, LDTR, IDTR, TR and MSW registers.
ELO7: Apply the bubble sort technique in 8086 to sort the input from text file.
ELO8: Implement DOS commands like TYPE,COPY, DELET using file operations.
ELO10: Implement ALP to Calculate the roots of the quadratic equation with the help of
assembly language programming.
ELO11: Implement ALP to plot Sine Wave, Cosine Wave & Sinc function.
ELO12: Evaluate mean, variance and standard deviation using 8087 math coprocessor‟s
instruction set.
TITLE: Write an X86/64 ALP to accept five 64 bit Hexadecimal numbers from user and store
them in an array and display the accepted numbers.
OBJECTIVES:
1. To be familiar with the format of assembly language program structure and instructions.
2. To study the format of assembly language program along with different assembler
directives and different functions of the NASM.
PROBLEM DEFINITION:
Write an X86/64 ALP to accept five 64 bit Hexadecimal numbers from user and store them in an
array and display the accepted numbers.
WORKING ENVIRONMENT:
1) CPU: Intel I5 Processor
2) OS:- Windows XP (16 bit Execution ), Fedora 18 (32 & 64 bit Execution)
3) Editor: gedit, GNU Editor
4) Assembler: NASM (Netwide Assembler)
5) Linker:-LD, GNU Linker
There are six registers that stores the arguments of the system call used. These are the EBX,
ECX, EDX, ESI, EDI, and EBP. These registers take the consecutive arguments, starting with
the EBX register. If there are more than six arguments then the memory location of the first
argument is stored in the EBX register.
Instructions needed:
CALL- The CALL instruction causes the procedure named in the operand to be executed.
OBJECTIVES:
1. To learn the instructions related to String
2. To be familiar with data segments.
3. To learn the instructions related to String operation
PROBLEM DEFINITION:
Write an X86/64 ALP to accept a string and to display its length.
WORKING ENVIRONMENT:
1. CPU: Intel I5 Processor
2. OS:- Windows XP (16 bit Execution ), Fedora 18 (32 & 64 bit Execution)
3. Editor: gedit, GNU Editor
4. Assembler: NASM (Netwide Assembler)
5. Linker:-LD, GNU Linker
THEORY:
● For a few short forms of MOV that implicitly use the EAX register, the offset of the
operand is coded as a doubleword in the instruction. No base register, index register, or
scaling factors are used.
● String operations implicitly address memory via DS:ESI, (MOVS, CMPS, OUTS,
LODS, SCAS) or via ES:EDI (MOVS, CMPS, INS, STOS).
● Stack operations implicitly address operands via SS:ESP registers; e.g., PUSH, POP,
PUSHA, PUSHAD, POPA, POPAD, PUSHF, PUSHFD, POPF, POPFD, CALL, RET,
IRET, IRETD, exceptions, and interrupts.
The instructions in this category operate on strings rather than on logical or numeric values.
Refer also to the section on I/O for information about the string I/O instructions (also known as
block I/O).
The primitive string operations operate on one element of a string. A string element may be a
byte, a word, or a doubleword. The string elements are addressed by the registers ESI and EDI.
After every primitive operation ESI and/or EDI are automatically updated to point to the next
element of the string. If the direction flag is zero, the index registers are incremented; if one, they
are decremented. The amount of the increment or decrement is 1, 2, or 4 depending on the size of
the string element.
The REP prefixes apply only to one string instruction at a time. To repeat a block of instructions,
use the LOOP instruction or another looping construct.
1. If the address-size attribute is 16 bits, use CX for the count register; if the address-size
attribute is 32 bits, use ECX for the count register.
2. Check CX. If it is zero, exit the iteration, and move to the next instruction.
3. Acknowledge any pending interrupts.
4. Perform the string operation once.
5. Decrement CX or ECX by one; no flags are modified.
6. Check the zero flag if the string operation is SCAS or CMPS. If the repeat condition does not
hold, exit the iteration and move to the next instruction. Exit the iteration if the prefix is REPE
and ZF is 0 (the last comparison was not equal), or if the prefix is REPNE and ZF is one (the last
comparison was equal).
7. Return to step 1 for the next iteration.
Instructions needed:
MOVS: Move String
CMPS: Compare string
SCAS: Scan string
LODS: Load string
STOS: Store string
ESI: Source index register
EDI: Destination index register
REP: Repeat while ECX not xero
REPE/REPZ: Repeat while equal or zero
REPNE/REPNZ: Repeat while not equal or not zero
EXPERIMENT NO.3
TITLE: Find the largest of given Byte/Word/Dword/64-bit numbers.
OBJECTIVES:
1. To understanding of basic data structure
2. To compare the different data structure
3. To make usage of different data structure for hexadecimal number
PROBLEM DEFINITION:
Write an X86/64 ALP to find the largest of given Byte/Word/Dword/64-bit numbers.
WORKING ENVIRONMENT:
6. CPU: Intel I5 Processor
7. OS:- Windows XP (16 bit Execution ), Fedora 18 (32 & 64 bit Execution)
8. Editor: gedit, GNU Editor
9. Assembler: NASM (Netwide Assembler)
10. Linker:-LD, GNU Linker
THEORY:
Data Types
Integer:
A signed binary numeric value contained in a 32-bit doubleword,16-bit word, or
8-bit byte. All operations assume a 2's complement representation. The sign bit is located
in bit 7 in a byte, bit 15 in a word, and bit 31 in a doubleword. The sign bit has the value
zero for positive integers and one for negative. Since the high-order bit is used for a sign,
the range of an 8-bit integer is -128 through +127; 16-bit integers may range from -
32,768 through +32,767; 32-bit integers may range from -231 through +231-1. The value
zero has a positive sign.
Ordinal:
An unsigned binary numeric value contained in a 32-bit doubleword, 16-bit word,
or 8-bit byte. All bits are considered in determining magnitude of the number. The value
range of an 8-bit ordinal number is 0-255; 16 bits can represent values from 0 through
65,535; 32 bits can represent values from 0 through 232-1.
Near Pointer:
A 32-bit logical address. A near pointer is an offset within a segment. Near
pointers are used in either a flat or a segmented model of memory organization.
Far Pointer:
A 48-bit logical address of two components: a 16-bit segment selector component
and a 32-bit offset component. Far pointers are used by applications programmers only
when systems designers choose a segmented memory organization.
String:
A contiguous sequence of bytes, words, or doublewords. A string may contain
from zero bytes to 232-1 bytes (4 gigabytes).
Bit field:
A contiguous sequence of bits. A bit field may begin at any bit position of any
byte and may contain up to 32 bits.
Bit string:
A contiguous sequence of bits. A bit string may begin at any bit position of any
byte and may contain up to 232-1 bits.
BCD:
A byte (unpacked) representation of a decimal digit in the range0 through 9.
Unpacked decimal numbers are stored as unsigned byte quantities. One digit is stored in
each byte. The magnitude of the number is determined from the low-order half-byte;
hexadecimal values 0-9 are valid and are interpreted as decimal numbers.
Packed BCD:
A byte (packed) representation of two decimal digits, each in the range 0 through
9. One digit is stored in each half-byte. The digit in the high-order half-byte is the most
significant. Values 0-9 are valid in each half-byte. The range of a packed decimal byte is
0-99.
Instructions needed:
TITLE
Switch case driven X86/64 ALP to perform 64-bit hexadecimal arithmetic operations (+,-,*, /)
using suitable macros.
OBJECTIVES:
1. To understand the looping stamens
2. To understand switch case
3. To analyze the different arithmetic operations
PROBLEM DEFINITION:
Write a switch case driven X86/64 ALP to perform 64-bit hexadecimal arithmetic operations (+,-
,*, /) using suitable macros. Define procedure for each operation.
WORKING ENVIRONMENT:
11. CPU: Intel I5 Processor
12. OS:- Windows XP (16 bit Execution ), Fedora 18 (32 & 64 bit Execution)
13. Editor: gedit, GNU Editor
14. Assembler: NASM (Netwide Assembler)
15. Linker:-LD, GNU Linker
• Loop Instructions
The loop instructions are conditional jumps that use a value placed in ECX to
specify the number of repetitions of a software loop. All loop instructions automatically
decrement ECX and terminate the loop when ECX=0. Four of the five loop instructions
specify a condition involving ZF that terminates the loop before ECX reaches zero.
LOOP (Loop While ECX Not Zero) is a conditional transfer that automatically
decrements the ECX register before testing ECX for the branch condition. If ECX is non-
zero, the program branches to the target label specified in the instruction. The LOOP
instruction causes the repetition of a code section until the operation of the LOOP
instruction decrements ECX to a value of zero. If LOOP finds ECX=0, control transfers
to the instruction immediately following the LOOP instruction. If the value of ECX is
initially zero, then the LOOP executes 232 times.
EXPERIMENT NO.5
TITLE: Write an ALP to count numbers of positive and negative numbers from the array.
OBJECTIVES:
4. To be familiar with the format of assembly language program structure and instructions.
5. To study the format of assembly language program along with different assembler
directives and different functions of the NASM.
PROBLEM DEFINITION:
Write X86/64 Assembly language program (ALP) to count number of positive and negative
numbers from array.
WORKING ENVIRONMENT:
6) CPU: Intel I5 Processor
7) OS:- Windows XP (16 bit Execution ), Fedora 18 (32 & 64 bit Execution)
8) Editor: gedit, GNU Editor
9) Assembler: NASM (Netwide Assembler)
10) Linker:-LD, GNU Linker
INPUT:Hexadecimal numbers
OUTPUT:Number of Negative numbers, Number of Positive numbers
The following code snippet shows the use of the system call sys_exit:
MOV EAX, 1 ; system call number (sys_exit)
INT 0x80 ; call kernel
The following code snippet shows the use of the system call sys_write:
MOV EAX,4; system call number (sys_write)
MOV EBX,1; file descriptor (stdout)
MOV ECX, MSG ; message to write
MOV EDX, 4; message length
INT0x80; call kernel
Linux System Calls (64 bit)
Sys_write:
MOV RAX,1
MOV RDI,1
MOV RSI,message
MOV RDX,message_length
SYSCALL
Sys_read:
MOV RAX,0
MOV RDI,0
MOV RSI,array_name
MOV RDX,array_size
SYSCALL
Sys_exit:
MOV RAX,60
MOV RDI,0
SYSCALL
Assembly Variables
NASM provides various define directives for reserving storage space for variables. The define
Assembler directive is used for allocation of storage space. It can be used to reserve as well as
initialize one or more bytes.
Allocating Storage Space for Initialized Data
There are five basic forms of the define directive:
Instructions needed:
MATHEMATICAL MODEL:
S = System
s =Distinct Start of System
e = Distinct End Of System
X = Set of Inputs
Y= Set Of outputs
Fme = Central Function
Mem= Memory Required
Φs = Constraits
F2 Y = ∑ ( X2)
F3 Display Output
Output:
OUTCOME
ELO1: Apply logical instruction sets to segregate positive and negative numbers.
EXPERIMENT NO.6
TITLE: Hex to BCD & BCD to Hex Conversion.
OBJECTIVES:
To Learn the implementation of ALP for conversion of Hex to BCD & vice a versa.
PROBLEM STATEMENT:
To write 64 bit ALP to convert 4-digit Hex number into its equivalent BCD number and 5-digit
BCD number into its equivalent HEX number. Make your program user friendly to accept the
choice from user for: (a) HEX to BCD b) BCD to HEX (c) EXIT.
Display proper strings to prompt the user while accepting the input and displaying the result.
SOFTWARE REQUIRED:
9. CPU: Intel I5 Processor
10. OS:- Windows XP (16 bit Execution ), Fedora 18 (32 & 64 bit Execution)
11. Editor: gedit, GNU Editor
12. Assembler: NASM (Netwide Assembler)
13. Linker:-LD, GNU Linker
INPUT:
1. Hexadecimal number
2. BCD Number
OUTPUT:
1. Conversion of hex to BCD number
MATHEMATICAL MODEL:
Fme = { F1,F2,F3,F4}
Where F1= Accept X4
F2= If X4=1, Call Fme1
F3= If X4=2,Call Fme2
F4= If X4=3, Call Fme3
THEORY:
1. Hexadecimal to BCD conversion:
Conversion of a hexadecimal number can be carried out in different ways e.g. dividing
number by 000Ah and displaying quotient in reverse way.
Conversion of BCD number to Hexadecimal number can be carried out by multiplying the
BCD digit by its position value and the adding it in the final result.
DIV: Unsigned Divide. Result → Quotient in AL and Remainder in AH for 8-bit division
and for 16-bit division Quotient in AX and Remainder in DX
MUL: Unsigned Multiply. For 8-bit operand multiplication result will be stored in AX and
for 16-bit multiplication result is stored in DX:AX
Commands
• To assemble
• To link
ld –o hello hello.o
• To execute -
./hello
Output:
;[admin@localhost ~]$ vi conv.nasm
;[admin@localhost ~]$ nasm -f elf64 conv.nasm -o conv.o
;[admin@localhost ~]$ ld -o conv conv.o
;[admin@localhost ~]$ ./conv
;Enter Choice:1
;BCD Equivalent::65535
;Enter Choice:1
;BCD Equivalent::255
;Enter Choice:2
;Hex Equivalent::0FFFF
OUTCOME
Upon completion Students will be able to:
ELO3: Convert hexadecimal number to BCD and vice versa with the help of assembly language
programming.
EXPERIMENT NO.7
TITLE: Write X86/64 ALP to switch from real mode to protected mode and display the values
of GDTR, LDTR, IDTR, TR and MSW Registers.
OBJECTIVES:
1. To be familiar with the format of assembly language program structure and instructions.
PROBLEM DEFINITION:
Write X86/64 ALP to switch from real mode to protected mode and display the values of GDTR,
LDTR, IDTR, TR and MSW Registers.
WORKING ENVIRONMENT:
Four registers of the 80386 locate the data structures that control segmented memory
management called as memory management registers:
1. GDTR :Global Descriptor Table Register
These register point to the segment descriptor tables GDT. Before any segment register is
changed in protected mode, the GDT register must point to a valid GDT. Initialization of the
GDT and GDTR may be done in real-address mode. The GDT (as well as LDTs) should reside in
RAM, because the processor modifies the accessed bit of descriptors. The instructions LGDT
and SGDT give access to the GDTR.
2. LDTR :Local Descriptor Table Register
These register point to the segment descriptor tables LDT. The LLDT instruction loads a linear
base address and limit value from a six-byte data operand in memory into the LDTR. The SLDT
instruction always store into all 48 bits of the six-byte data operand.
3. IDTR Interrupt Descriptor Table Register
This register points to a table of entry points for interrupt handlers (the IDT). The LIDT
instruction loads a linear base address and limit value from a six-byte data operand in memory
into the IDTR. The SIDT instruction always store into all 48 bits of the six-byte data operand.
4. TR Task Register
This register points to the information needed by the processor to define the current task.
These registers store the base addresses of the descriptor tables (A descriptor table is
simply a memory array of 8-byte entries that contain
Descriptors and descriptor stores all the information about segment) in the linear address space
and store the segment limits.
SLDT: Store Local Descriptor Table Register
Operation: DEST ← 48-bit BASE/LIMIT register contents;
Description: SLDT stores the Local Descriptor Table Register (LDTR) in the two-byte register
or memory location indicated by the effective address operand. This register is a selector that
points into the Global Descriptor Table. SLDT is used only in operating system software. It is
not used in application programs.
Flags Affected: None
SGDT: Store Global Descriptor Table Register
Operation: DEST ← 48-bit BASE/LIMIT register contents;
Description: SGDT copies the contents of the descriptor table register the six bytes of memory
indicated by the operand. The LIMIT field of the register is assigned to the first word at the
effective address. If the operand-size attribute is 32 bits, the next three bytes are assigned the
BASE field of the register, and the fourth byte is written with zero. The last byte is undefined.
Otherwise, if the operand-size attribute is 16 bits, the next 4 bytes are assigned the 32-bit BASE
field of the register. SGDT and SIDT are used only in operating system software; they are not
used in application programs.
Flags Affected: None
SIDT: Store Interrupt Descriptor Table Register
Operation: DEST ← 48-bit BASE/LIMIT register contents;
Description: SIDT copies the contents of the descriptor table register the six bytes of memory
indicated by the operand. The LIMIT field of the register is assigned to the first word at the
effective address. If the operand-size attribute is 32 bits, the next three bytes are assigned the
BASE field of the register, and the fourth byte is written with zero. The last byte is undefined.
Otherwise, if the operand-size attribute is 16 bits, the next 4 bytes are assigned the 32-bit BASE
field of the register. SGDT and SIDT are used only in operating system software; they are not
used in application programs.
Flags Affected: None
OUTCOME:
ELO6: Apply the concept of real mode and protected mode in 8086 ALP to implement a
program to display values from GDTR, LDTR, IDTR, TR and MSW registers.
EXPERIMENT NO. 08 and 09
OBJECTIVES:
4. To be familiar with the format of assembly language program along with different
assembler directives and different functions of the DOS Interrupt.
5. To learn the instructions related to String and use of Direction Flag.
6. To be familiar with data segments.
7. Implement non-overlapped and overlapped block transfer.
PROBLEM DEFINITION:
Write X86/64 ALP to perform non-overlapped and overlapped block transfer (with and without
string specific instructions). Block containing data can be defined in the data segment.
WORKING ENVIRONMENT:
11) CPU: Intel I5 Processor
12) OS:- Windows XP (16 bit Execution ), Fedora 18 (32 & 64 bit Execution)
13) Editor: gedit, GNU Editor
14) Assembler: NASM (Netwide Assembler)
15) Linker:-LD, GNU Linker
THEORY:
1. Non-overlapped blocks:
In memory, two blocks are known as non-overlapped when none of the element is
common.
AD
9D
Memory Block 2
78
09
FF
28 Memory Block 1
F4
3F
FD
BB
AA
0D
2. Overlapped block:
In memory, two blocks are known as overlapped when at least one element is common
between two blocks.
While performing block transfer we have to see which element/s of source block is/are
overlapped. If ending elements are overlapped then start transferring elements from last
and if starting elements are overlapped then start transfer from first element.
AD
9D
Memory Block 2
78
09
Common Element
FF
28
F4
Memory Block 1
3F
FD
BB
AA
0D
Instructions needed:
1. MOVSB-Move string bytes.
3. AND-AND each bit in a byte or word with corresponding bit in another byte or word
X2 Source Array
Let X2 = {{b7-----b0}{ b7-------b0}--------{b7 b6 b5 b4 b3 b2 b1 b0}} where bi Є X1
There exists a function fX2 : X2 { {00h----FFh}{00h----FFh }{00h----FFh} ----- }
X2 Source Array
Let X2 = {{b7-----b0}{ b7-------b0}--------{b7b6 b5 b4 b3 b2 b1
b0}{00H}{00H}{00H}{00H}{00H}} where bi Є X1
There exists a function fX2 : X2 { {00h----FFh}{00h----FFh }{00h----FFh}------
{00h}{00h}{00h}{00h}{00h}}
Output:
OUTCOME
Upon completion Students will be able to:
ELO2: Apply the concept of overlapped and non-overlapped block transfer in the program with
or without using string instruction.
EXPERIMENT NO.10
TITLE: Multiplication of two 8 bit nos. using Successive addition and Shift and add
method
OBJECTIVES:
1. Understand the implementation.
2. To interpret the Microprocessor Interfacing paradigms.
3. To express and apply the method of odd, add and shift method.
4. Understand implememtation of arithmetic instruction of 8086.
PROBLEM STATEMENT:
Write 8086/64 ALP to perform multiplication of two 8 bit hexadecimal nos. Use successive
addition & shift & add method, Accept i/p from the user.
HARDWARE REQUIRED:
CPU: Intel i5 Processor
OS:Windows XP (16 bit execution), Fedora 18 32 & 64 bit execution
SOFTWARE REQUIRED:
OUTPUT:
Result : D120H
THEORY:
There are 5 basic form of define reverse directives.
Directives Purpose
DD Define byte
DW Define word
DD Define doubleword
DQ Define quad word
DT Define Ten byte
RESB Reserve byte
RESW Reserve word
RESQ Reserve quad word
REST Reserve ten word
Instructions Needed:
MOV : Move or copy word
ROR : Rotate to right
AND : Logical AND
INC : Increment
DEC : Decrement
JNZ : Jump if not zero
CMP : Compare
JNC : Jump if no carry
JBE : Jump if below
The method taught in school for multiplying decimal no. is based on calculated partial products,
shifting it to the left & then adding them together. Shift & add multilplication is similar to the
multiplication performed by paper & pencil. This method adds the multiplicand X to itself Y
times where Y denotes the multiplier. To multiply two nos. by paper & pencil placing the
intermediate product in the appropriate positions to the left of earlier product.
Step 1:
AX=11 + 11 = 22H
Step 2:
Decrement count =3
AX=22+22=44H
Rotate BL to left
No carry
Step 3:
Decrement count=2
AX=44+44=88H
Rotate BL to left
Step 4:
Decrement count=0
AX=88+88=110H
Rotate BL to left
Step 5:
Add Ax, BX
0110+0000=0110H
i.e.,
11H+10H=0110H
MATHEMATICAL MODEL:
Let S={s, e, x, y, time, mem ᶲs} be program perspective of multiplication of two 8 bit
hexadecimal Nos.
Let x2= b7 b6 b5 b4 b3 b2 b1 b0
Where xb1 € x1 Here exists a function fx2:x2 {00h, 01h, 02h, .............. ffh}
Y= b15 b14 b13 b12 bb11 b10 b09 b08 b07 b06 b05 b04 b03 b02 b01 b00 (where bi€ x1)
F3= display
Where
C=0 c=1
F3 = display y
C=0 c=1
F3= display
Output:
OUTCOME
ELO4: Choose different multiplication methods such as add & shift and successive addition for
multiplication of two numbers without using MUL instruction.