Sei sulla pagina 1di 63

COMSATS Institute of Information Technology WAH Campus

Department of Electrical Engineering


Microprocessor Systems and Interfacing
EEE342
Student Laboratory Manual
By

Lab. Instructor: Engr. Sahar Rahim


Updated on: September 8, 2017
COMSATS Institute of Information Technology, Wah Campus
CIRCUIT ANALYSISEngineering
Electrical AND PHYSICSDepartment
LAB

EEE342 Microprocessor Systems and Interfacing

List of Experiments

Lab
Experiments
No.

1 Introduction to Digital Number & Data Conversion System

Introduction to Microprocessors & Microcontrollers & Examine working


2
environment of EMU 8086 (Microprocessor Emulator)
Introduction to Microprocessors (8086) Instruction Set & its implementation in
3
EMU 8086

4 Implementation of Flags & Data Addressing modes in EMU 8086

Implementation of Base plus index addressing & Arithmetic operations in EMU


5
8086

6 Introduction & implementation of combinational logic operators in EMU 8086

7 Lab Sessional 1

8 Introduction to Microcontroller (8051) assembler & Simulator using (Keil uVersion 4)

9 Simulating I/O Ports, Testing 8051 I/O Ports

10 Interfacing LCD (16x2) to 8051

11 Timer Programming

12 Lab Sessional 2

13 Interfacing stepper motor to 8051

14 Hands-on Introduction to Arduino

15 Interfacing of servo motor with Arduino

16 Final Terminal
LABORATORY SAFETY
Experiments in this laboratory will be conducted in strict accordance with following list of regulations,
procedures and comments in order to promote a professional and safe approach to the laboratory
experience. Additionally, laboratory safety rules apply during all experiments. If you are not sure of the
operation of equipment or laboratory procedure, particularly those which might compromise personal
safety and the safety of your laboratory partners, do not hesitate to ask your laboratory instructor for
assistance. The following rules must be strictly adhered to during the course of your laboratory
experiment:

1. Be calm and relaxed, while working in Lab.

2. No paper lying on table or nearby circuits.

3. No smoking, no food and no drinks permitted inside the laboratory.

4. Wear proper clothing and insulated footwear to the laboratory.

5. Do not use wet hands or stand on a wet floor while making electrical connections.

6. Do not place personal belongings (books, coat, etc.) on the laboratory equipment.

7. Keep your work area clean and organized.

8. Use only that equipment required for a particular experiment specified.

9. Do not use damaged or poorly insulated wires or equipment.

10. Properly ground all equipment.

11. Thoroughly check all connections before applying power.

12. Turn power off when making changes to your experiment.

13. Discharge capacitors by shorting with resistor.

14. Do not energize equipment until given permission.

15. Do not touch 120V electrical outlets or the terminals of any energized electrical connection.

16. Report any accident to your instructor immediately.

17. Work deliberately and carefully.

18. In the event of a power failure, turn off the power switched to all equipment immediately and wait
further instructions.

19. After you are done with your experiment, turn all main switches off.
COMSATS Institute of Information Technology
Department of Electrical Engineering

Evaluation Sheet (Lab. Rubrics)

Name of Student: ………………………………….

Roll no. : ……………………………………………….

Batch & Section: …………………………………..

Date of Experiment: ………………………………

Marks Obtained: …………………………………..

Instructor’s Signature: ……………………………


Experiment # 01

Digital Number System


Objective:
To understand and practice different data conversion systems (Binary, Octal, Decimal,
Hexadecimal).

Introduction:
In the modern world of electronics, the term Digital is generally associated with a computer
because the term Digital is derived from the way computers perform operation, by counting
digits. Now-a-days, digital electronics is used in many other applications. Following are some of
the examples in which Digital electronics is heavily used.
 Industrial process control
 Military system
 Television
 Communication system
 Medical equipment
 Radar
 Navigation
Comparison of Analog and Digital System:

Analog System Digital System

Analog signal has infinite values. Digital signal has a finite number of values.

Analog signal has a continuous nature. Digital signal has a discrete nature.
Analog signal is generated by transducers Digital signal is generated by A to D
and signal generators. converter.

Less accuracy More accuracy

More noise effect Less distortion

More effect of weather Less effect of weather

Examples; Examples;

Page 1
 Filter  Registers
 Amplifiers  Flip-flop
 Television receiver  Counters
 Motor speed controller  Microprocessors

Digital Number System:

A digital system can understand positional number system only where there are a few symbols
called digits and these symbols represent different values depending on the position they occupy
in the number. A value of each digit in a number can be determined using

 The digit.
 The position of the digit in the number.
 The base of the number system (where base is defined as the total number of digits
available in the number system).

Page 2
Lab Task 01:

Perform the following conversions and verify your results using scientific calculator

Base-10 Base-2 Base-16

63
256
10
512
255

Base-2 Base-16 Base-10

11010
10000

11110

101010

1111

Base-16 Base-2 Base-10

3BC
10A
20
FFF
FA
BAD

Page 3
Lab Task 02:

 Give the highest single digit for each of the number systems: decimal, binary, and hex.

 Which of the following cannot be a number in base-2? Give the reason.

(a) 11001 (b) 113 (c) 10001

 What is the highest 8-bit number?

• In binary:

• In hex:

 What is the highest 16-bit number?

• In binary:

• In hex:

 Convert binary 100000 to decimal and hex.

• Decimal:

• Hex:

 Convert hex number BAAD to binary and decimal.

• Binary:

• Decimal:
Page 4
COMSATS Institute of Information Technology
Department of Electrical Engineering

Evaluation Sheet (Lab. Rubrics)

Name of Student: ………………………………….

Roll no. : ……………………………………………….

Batch & Section: …………………………………..

Date of Experiment: ………………………………

Marks Obtained: …………………………………..

Instructor’s Signature: ……………………………


Experiment # 02
Introduction to Microprocessor & Microcontroller

Objective:
Introduction with Microprocessors and Microcontrollers and working environment of EMU
8086 (Microprocessor Emulator).

Introduction:
A microprocessor is also known as computer processor which incorporates the functions of
a computer's central processing unit (CPU) on a single integrated circuit (IC) or at most a few
integrated circuits. The microprocessor is a multipurpose, clock driven, register based,
digital-integrated circuit which accepts binary data as input, processes it according
to instructions stored in its memory, and provides results as output. Microprocessors contain
both combinational logic and sequential digital logic. Microprocessors operate on numbers
and symbols represented in the binary numeral system.

Microprocessors touch almost every aspect of modern life. They can be found in vehicles,
consumer electronics, communications devices, appliances, toys and of course computers.
With the exception of full computers (i.e. desktop or full laptops) which use full
microprocessors with separate memory and peripherals (device used to put information into
and get information out of the computer).

Figure 1: Block Diagram of Microprocessor

Difference between Microprocessor and Microcontroller:


The term microprocessor and microcontroller have always been confused with each other.
Both of them have been designed for real time application. They share many common

Page 5
features and at the same time they have significant differences. Both the IC’s cannot be
distinguished by looking at them. They are available in different version starting from 6
pin to as high as 80 to 100 pins or even higher depending on the features. Both
microcontrollers and microprocessors are complex sequential digital circuits meant to carry
out job according to the program / instructions.

Microprocessor is an IC which has only the CPU inside them i.e. only the processing
powers such as Intel’s Pentium 1,2,3,4, core 2 duo, i3, i5 etc. These microprocessors don’t
have RAM, ROM, and other peripheral on the chip. A system designer has to add them
externally to make them functional. Application of microprocessor includes Desktop PC’s,
Laptops, notepads etc.

But this is not the case with Microcontrollers. A Microcontroller is a programmable digital
processor with necessary peripherals. Microcontroller has a CPU, in addition with a fixed
amount of RAM, ROM and other peripherals all embedded on a single chip. At times it is
also termed as a mini computer or a computer on a single chip. Today different
manufacturers produce microcontrollers with a wide range of features available in different
versions. Some manufacturers are ATMEL, Microchip, TI, Freescale, Philips, Motorola
etc. Microcontrollers are designed to perform specific tasks.

Comparing microcontroller and microprocessor in terms of cost is not justified.


Undoubtedly a microcontroller is far cheaper than a microprocessor. However
microcontroller cannot be used in place of microprocessor and using a microprocessor is
not advised in place of a microcontroller as it makes the application quite costly.
Microprocessor cannot be used stand alone. They need other peripherals like RAM, ROM,
buffer, I/O ports etc and hence a system designed around a microprocessor is quite costly.

Difference between 8085, 8086 and 8088:


8085 8086 8088
8085 is an 8 bit 8086 is a 16 bit 8088 is a 16 bit
microprocessor microprocessor. microprocessor.
It has 8 bit data bus. It has 16 bit data bus. It has 8 bit data bus.
It has 8 bit ALU. It has 16 bit ALU. It has 16 bit ALU.
8085 does not require 8086 requires memory 8088 does not require
memory banking as it has an banking to transfer 16 bit memory banking as it has an
8 bit data bus. data at a time. 8 bit data bus.
8085 performs slower 8086 performs faster 8088 performs slower
memory operations as it can memory operations as it can memory operations as it can
transfer only 8 bits in one transfer 16 bits in one cycle. transfer only 8 bits in one
cycle. cycle.
8085 does not support 8086 supports pipeline 8088 supports pipeline
pipeline architecture. architecture. architecture.
8085 has no pre-fetch queue 8086 has a 6 byte pre-fetch 8088 has a 4 byte pre-fetch

Page 6
as it does not support queue for pipelining. queue for pipelining.
pipelining.
8085 has an IO/ pin to 8086 has an M/ pin to 8088 has an IO/ pin to
differentiate between differentiate between differentiate between
memory and I/O operations. memory and I/O operations. memory and I/O operations.
8085 has no pre-fetch queue. 8086 BIU will fetch new 8088 BIU will fetch a new
bytes into the pipelining byte into the pipelining
queue when 2 bytes of the queue when 1 byte of the
queue are empty. queue is empty.
8085 has 5 flags. 8086 has 9 flags. 8088 has 9 flags.

Programming Model of 8086:


The programming model for a microprocessor shows the various internal registers that are
accessible to the programmer. As a programmer of the 8086 we must be familiar with the
various registers in the execution unit (EU) and Bus Interface Unit (BIU). The Following
Figure is a model for the 8086. In general, each register has a special function.

Figure 2: Programming model


The four data registers labeled AX, BX, CX and DX may be further subdivided for 8-bit
operations into a high-byte or low-byte register, depending where the byte is to be stored in
the register. Thus, for byte operations, the registers may be individually addressed. So, each
of these is 16 bits wide but can be accessed as a byte or a word.

 AX: known as an accumulator is used in arithmetic and logical operations.

Page 7
 BX: refers to the 16-bit base register.
 CX: is used as a counter.

The 8086 has a 16 bit flag register of which only 9 bits are used as flags and the rest 7 bits are
not used. These flags are set or reset after the operation in an ALU. Six of the flags are status
indicators, reflecting properties of the result of the last arithmetic or logical instructions.
These are CF, AF, PF, ZF, SF and OF. The 8086/88 has several instructions that can be used
to transfer program control to a new memory location based on the state of the flags. Three of
the flags can be set or reset directly by the programmer and are used to control the operation
of the processor. These are TF, IF, and DF.

EMU 8086 - THE MICROPROCESSOR EMULATOR:


 emu8086 is the emulator of 8086 (Intel and AMD compatible) microprocessor and
integrated assemblers.
 The emulator runs programs like the real microprocessor in step-by-step mode.
 It shows registers, memory, stack, variables and flags.
 All memory values can be investigated and edited by a double click.
 The instructions can be executed back and forward.
 emu8086 can create a tiny operating system and write its binary code to a bootable
floppy disk.
 The software package includes several external virtual devices: robot, stepper motor,
led display, and traffic lights intersection. Additional devices can be created.

Working with EMU 8086:

 Once you open the emu8086 emulator you should see the following screen.

Figure 3: State up window

Page 8
 From here, you can create a new project with following options;

Figure 4: Formation of project

This screen allows you select what kind of file you want create- either a bin file with .com
extension, an executive file with .exe extension, a pure binary file or a boot file. Once you
select the type the emu8086 opens the editor with a readymade template of the kind of file you
wanted to create.

 Consider that you selected .exe template then the editor opens with default template as
shown below

Figure 5: Template

Page 9
Now, you can write the code in the add your code here section, change the code, data segment
part and define constant or variables.

 If you select cancel in the above default template selection then it opens just the blank
editor as shown below

Figure 6: New file

Example:
Consider the simple program that loads the accumulator with some values; add new value to
the content of the accumulator and so on.

mov ax, 10
add ax, 21
inc ax
dec ax
sub ax, 12
add ax, 7
inc ax
dec ax
sub ax, 30

Once you have typed in your program you should save the program by going to File>Save or
File>save as or just by clicking the save button on the toolbar. Emu8086 will save it the newly
created file with .asm extension in it's default location (C:\emu8086\MySource) but you can
browse to a folder where you want to save the file.

Page 10
Figure 7: Save project

Once you have saved the file, you can emulate the program by clicking on the emulate button
on the toolbar to see the behavior of the program. That is what register has what content, the
flag resisters that gets effected by the program and so on. The screenshot below shows this
process.

Figure 8: Emulation Window

From this emulator window we can just run the program or go through the program step by
step by clicking on the single step button.
For the example program above when we step through the program we can see the content of
the accumulator and how it gets modified and what new values are stored. Not only can we
know the content of the accumulator but also the other registers, the stack and the flag
register.

Page 11
Lab Task 01
Write the following code in emulator and examine the contents of registers by single stepping
MOV AL, 57
MOV DH.69
MOV DL, 72
MOV BX, DX
MOV BH, AL
MOV BL, 9F
MOV AH, 20
ADD AX, DX
ADD CX, BX
ADD AX, 1F35

Page 12
Lab Task 02:

Write a program to subtract the content of register DX from the content of register AX,
then add the result to the content of CX. Set the registers to 4, 0A and 1F respectively.

Page 13
COMSATS Institute of Information Technology
Department of Electrical Engineering

Evaluation Sheet (Lab. Rubrics)

Name of Student: ………………………………….

Roll no. : ……………………………………………….

Batch & Section: …………………………………..

Date of Experiment: ………………………………

Marks Obtained: …………………………………..

Instructor’s Signature: ……………………………


Experiment # 03
Introduction to Microprocessor “8086”

Objective:
Introduction to 8086 Instruction Set and it implementation in EMU 8086 (Microprocessor
Emulator).

Introduction:
Pointers and Index Registers:-

The registers in this group are all 16 bits wide and, unlike the data registers, cannot be
accessed as a low or high byte. These registers are used as memory pointers. For example,
the instruction MOV AH, [SI] has the word interpretation "Move the byte whose address is
contained in register SI to register AH." SI is thus interpreted as "pointing" to the desired
memory location. The brackets around SI are used to indicate the contents of memory
pointed to by SI and not the value of SI itself.

SI - source index register:-

1. Can be used for pointer addressing of data

2. Used as source in some string processing instructions.

3. Offset address relative to DS

DI - destination index register:-

1. Can be used for pointer addressing of data

2. Used as destination in some string processing instructions

3. Offset address relative to ES

BP - base pointer:-

1. Primarily used to access parameters passed via the stack

2. Offset address relative to SS

SP - stack pointer:-

1. Always points to top item on the stack

Page 14
2. Offset address relative to SS

3. Always points to word (byte at even address)

Segment Registers:-

CS - points at the segment containing the current program.

DS - generally points at segment where variables are defined.

ES - extra segment register, it's up to a coder to define its usage.

SS - points at the segment containing the stack.

Although it is possible to store any data in the segment registers, this is never a good idea.
The segment registers have a very special purpose - pointing at accessible blocks of
memory. Segment registers work together with general purpose register to access any
memory value.

For example if we would like to access memory at the physical address


12345h(hexadecimal), we could set the DS = 1230h and SI = 0045h. This way we can access
much more memory than with a single register, which is limited to 16 bit values. The CPU
makes a calculation of the physical address by multiplying the segment register by 10h and
adding the general purpose register to it (1230h * 10h + 45h = 12345h). The address formed
with 2 registers is called an effective address.

Instruction Set:-

What is instruction set? When we talk to some person we need to talk in the language which
that person is able to understand. If we talk in a language that is not understandable by that
person he will not be able to follow our words and will not be able to reply us or fulfill the
task we are asking him to do. This is because we are not understandable to him which means
that we are not following his instruction set. Same is the case with microprocessor. If the
microprocessor is able to understand our words he will be able to perform our said tasks
otherwise will not be able to do it. That is only possible if we talk to microprocessor in its
language i.e. its INSTRUCTION SET. Each microprocessor has its own instruction set.

8086 Instruction Set:-

8086 Instructions can be divided into different classes which are data movement instructions,
conversions, Arithmetic Instructions, Logical Shift Rotate and Bit Instructions, I/O
Instructions String Instructions, Program Flow control instructions and other Miscellaneous
Instructions

Page 15
Data Transfer instructions:
MOV instruction:

 It is one of the simplest and flexible instructions.


 Source is far to the right.
 Destination is next to the opcode.
 An opcode, or operation code, tells the microprocessor which operation to perform.
 Source and destination are separated by a comma.
 Source never changes while destination almost always changes

Figure 1: Sample Example

Operands supported by MOV:

1. MOV REG, MEMORY (MOV AL,[1234h])


2. MOV MEMORY, REG
3. MOV REG, REG
4. MOV MEMORY, IMMEDIATE
5. MOV REG, IMMEDIATE (e.g: MOV AL,100)
6. MOV REG, SEGREG (e.g: MOV AL,DS)

Operands not supported by MOV:

1. MOV MEMORY, MEMORY


2. MOV IMMEDIATE, SEGREG
3. MOV SEGREG, SEGREG

ADD:

It adds the source operand to destination operand and places the result in destination. But
source and destination operands must watch and only one of them can be in memory. Carry is
stored in carry flag (CF).

Page 16
Format: - ADD destination, source

SUB:
It subtract byte from byte or word from word.
Format: operand1 = operand1 - operand2
Example:
MOV AL, 5
SUB AL, 1 ; AL = 4

Lab Task 01
Write and assemble a program to load register AX with value 99H. Then from register AX
move it to BX, CX, and DX. Use the simulator to single-step the program and examine the
registers.

Page 17
Lab Task 02:

Write and assemble a program to add all the single digits of your ID number and save the
result in Accumulator. Then use the simulator to single-step the program and examine the
registers.

Page 18
Lab Task 3

Subtraction of two 8 bit numbers and placed the result in accumulator register

Page 19
Lab Task 4

Addition of first ten natural numbers by using INC and ADD instruction.

Page 20
COMSATS Institute of Information Technology
Department of Electrical Engineering

Evaluation Sheet (Lab. Rubrics)

Name of Student: ………………………………….

Roll no. : ……………………………………………….

Batch & Section: …………………………………..

Date of Experiment: ………………………………

Marks Obtained: …………………………………..

Instructor’s Signature: ……………………………


Experiment # 04
Flags & Address mode in Microprocessor “8086”

Objective:
Introduction and implementation of flags and all the data address modes in EMU 8086.

Introduction:

Flag Register:

8086 has 16 flag registers among which 9 are active. The purpose of the FLAG register is to
indicate the status of the processor. It does this by setting the individual bits called flags.
There are two kinds of FLAGS;

Status FLAGS and Control FLAGS. Status FLAGS reflect the result of an operation executed
by the processor. The control FLAGS enable or disable certain operations of the processor.

1. Carry Flag (CF): Holds the carry out after addition or borrow after subtraction.

2. Parity Flag (PF): This flag is set to 1 when there is even number of one bits in result, and
to 0 when there is odd number of one bits.

3. Auxiliary Flag (AF): The auxiliary carry holds the carry (half-carry) after addition and
borrow after subtraction between bit positions 3 and 4 of the result.

4. Zero Flag (ZF): Set to 1 when result is zero. For non-zero result this flag is set to 0.

5. Sign Flag (SF): Set to 1 when result is negative. When result is positive it is set to 0. This
flag takes the value of the most significant bit.

6. Trap Flag (TF): Used for on-chip debugging.

7. Interrupt enable Flag (IF): When CPU reacts to interrupts from external devices, this
flag is set to 1.

8. 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.

9. Overflow Flag (OF) - An overflow indicates that the result has exceeded the capacity of
the machine.

Page 21
Register Addressing Modes:

An addressing mode specifies, how to calculate the effective memory address of an operand
by using information held in registers and/or constants contained within a machine instruction
or elsewhere

Immediate Addressing

Transfers the source-immediate byte or word of data into the destination register or memory
location.

• MOV AX,0F2H

• MOV AL,100

• MOV AL,0000B

• MOV CL, 03H

• MOV DX, 0502H

Direct Addressing

Move a byte or word between memory location and register. Transfer a byte of data stored at
memory location.

 MOV AL, [1234h]

The instruction set does not support a memory-to-memory transfer.

Register Indirect Addressing

Transfers a byte or word between a register and a memory location addressed by an index or
base register. The index and base registers are BP, BX, DI, and SI.

Example:

MOV AX, [BX] ; instruction copies the word-sized data from the data segment offset
address indexed by BX into register AX.

MOV AX, [SI]

Load Effective Address:

Computes the effective address of the second operand (the source operand) and stores it in the
first operand (destination operand). The source operand is a memory address (offset part)

Page 22
specified with one of the processors addressing modes; the destination operand is a general-
purpose register.

Difference between LEA and MOV instruction:

The LEA instruction computes a memory address using the same arithmetic that a MOV
instruction uses. But unlike the MOV instruction, the LEA instruction just stores the
computed address in its target register, instead of loading the contents of that address and
storing it.

Lab Task 01
What effect on Conditional Flags will happens after the addition of 10110001 and 10101011?
(write state of each of the flag as observed, note values of flags after execution of every single
instruction in the program)

Lab Task 02
Add two numbers in hex, save the result in AX register and observe the value of flags.
1000 0000 0000 0000
1100 1000 0000 0000
(write state of each of the flag as observed, note values of flags after execution of every single
instruction in the program

Page 23
Lab Task 03

Check out the status of flags for the following examples? Use Single Step and observe
changes in flags after executing every single statement. Also, convert the numbers to binary
and prove the results (manually) as observed using emulator.

Example 1:-

MOV DX, 126FH

ADD DX, 3465H

MOV BX, 0FFFFH

ADD BX, 1

Example 2:-

MOV BL,+8

MOV DH,+4

ADD BL,DH

Page 24
Example 3:-

MOV AL, +66

MOV CL, +69

ADD CL,AL

Example 4:-

MOV AL, -12

MOV BL, +18

ADD BL,AL

Page 25
Example 5:-

MOV AH, -30

MOV DL, +14

ADD DL, AH

Lab Task 04
Write a program to swap the contents of AX and BX registers using register addressing.

Page 26
Lab Task 05

Declare two byte sized integer arrays num1 and num2 having 5 elements each, add them and
store the result in a third array num3.

Lab Task 06
Write a program to swap the contents of two word sized arrays num1 and num2.

Page 27
COMSATS Institute of Information Technology
Department of Electrical Engineering

Evaluation Sheet (Lab. Rubrics)

Name of Student: ………………………………….

Roll no. : ……………………………………………….

Batch & Section: …………………………………..

Date of Experiment: ………………………………

Marks Obtained: …………………………………..

Instructor’s Signature: ……………………………


Experiment # 05
Arithmetic Operations

Objective:
Introduction and implementation of Base plus index addressing and arithmetic operations in
EMU 8086.

Introduction:
Base-Plus-lndex Addressing:

Base-plus-index addressing is similar to indirect addressing because it indirectly addresses


memory data. In the 8086 through the 80286, this type of addressing uses one base register
(BP or BX), and one index register (DI or SI) to indirectly address memory.

Figure 1: Example
An example showing how the base-plus-index addressing mode functions for the MOV DX,
[BX+DI] instruction. Notice that memory address 02010H is accessed because DS = 0100H,
BX = 100H, and DI = 0010H.

Example

org 100h
LEA BP, [ARRAY1]
mov ax, [bp]
MOV DI, 10H
MOV [BX+DI], AL
ret

Page 28
ARRAY1 DB 1, 2, 3, 4, 5

CMP:

This instruction compares two operands, discarding the results and setting the flags

Syntax:

cmp op1, op2

op1: register or memory

op2: register, memory, or immediate

Flags Affected: OF, SF, ZF, AF, PF, CF.

Jump if greater

Short Jump if first operand is Greater than second operand (as set by CMP instruction).
Algorithm: if (ZF = 0) and (SF = OF) then jump
Example:
ORG 100h
MOV AL, 5
CMP AL, 5
JG label1
PRINT 'AL is not greater 5.' JMP exit label1:
PRINT 'AL is greater 5.' exit:
RET

Accessing Array Elements-Revised

 You can access the value of any element in array using square brackets, for
example:
 MOV AL, a[3]
 You can also use any of the memory index registers BX, SI, DI, BP, for example:
 MOV SI, 3
 MOV AL, a[SI]

Page 29
Sorting:

Arranging in an ordered sequence is called "sorting". Numbers are said to be in


ascending order when they are arranged from the smallest to the largest number. E.g.
5, 9, 13, 17 and 21 are arranged in ascending order.

Lab Task 01
Run the following code and observe the registers/ memory locations:

org 0x100

mov ax,10

mov bx,10

mov [200h],ax

mov [201h],bx

ret

Page 30
Lab Task 02
Write a code to add first ten natural numbers starting from the memory location 0200H?

Lab Task 03
Write a code to transfer a block of data from source memory block to destination memory
block. Use any starting address.

Page 31
Lab Task 04
Write a code to perform addition on 8 bit data stored in consecutive memory locations (10)
and store result in next memory locations. Use any starting address.

Page 32
Lab Task 05
Write a code to sort the given array in ascending order?

10,5,13,1,15,16,5,2

Lab Task 06
Write a code to add the numbers of two arrays respectively and multiply their results?

Page 33
.
Lab Task 07
Write a code to perform multiplication on 8 bit data (5 data values) and store the result in the
next memory location?

Page 34
COMSATS Institute of Information Technology
Department of Electrical Engineering

Evaluation Sheet (Lab. Rubrics)

Name of Student: ………………………………….

Roll no. : ……………………………………………….

Batch & Section: …………………………………..

Date of Experiment: ………………………………

Marks Obtained: …………………………………..

Instructor’s Signature: ……………………………


Experiment # 06
Logic Operations

Objective:
Introduction and implementation of combinational logic operators in EMU 8086.

Introduction:

MUL:
MUL BL

AX=AL*BL

When operand is a byte: AX = AL * operand.

MUL CX

(DX AX)=AX*CX

When operand is a word: (DX AX) = AX * operand.

Note that the product is stored in a register (or group of registers) twice the size of the
operands.
The operand can be a register or a memory operand
Example:

Mov al, 5h

Mov bl, 10h

Mul bl ; AX = 0050h, CF = 0

DIV:

AX= dividend, divided by contents of any 8 bit register or memory location

After division:

 AL= Quotient
 AH= Remainder
Page 35
Div CL

AX is divided by CL

 16 bit: DX-AX , divided by any 16 bit register or memory location

 AX= Quotient

 DX= Remainder

Example:

mov dx,0087h

mov ax,6000h

mov bx,100h

div bx

What will be the hexadecimal values of DX and AX after the following instructions execute?

Not

 NOT - Reverse each bit of operand.

NEG

 Make operand negative (two's complement).

AND

 AND operator gives 1 only if both operands are 1.

Procedure:
Procedure is a part of code that can be called from your program in order to make some
specific task (remember the functions in C). Procedures make program more structural and
easier to understand.

Procedure Syntax:

name PROC
; here goes the code
; of the procedure ...

Page 36
RET
name ENDP

Example:
ORG 100h

MOV AL, 1

MOV BL, 2

CALL m2

RET ; return to operating system.

m2 PROC

MUL BL ; AX = AL * BL.

RET ; return to caller.

m2 ENDP

END

Generally procedure returns to the same point from where it was called

CALL a Procedure:-

Transfer control to a procedure. RET is used to return control to the instruction after the call.

Lab Task 01
Take two binary numbers such as

11111111

11111111

Perform two’s complement of the first number and save it to one of the register. Then, reverse
the bits of second binary number and save it to the other register.

a) Take the value 0 in third register and perform the AND operation with both of the
results computed above.
b) Take the value 1 in third register and perform the AND operation with both of the
results computed above.

Page 37
Lab Task 02
Write a code to perform multiplication on 16 bit numbers in consecutive memory locations?

Write a code to add 16 bit numbers and find the average of numbers?

Page 38
Lab Task 03
Write a program to find the minimum number of a byte sized array and store it in a variable
min

Lab Task 04
Search a number in an array.

Page 38
Lab Task 05
Write a program to calculate the factorial of number 10?

Lab Task 06
Write a program to find the factorial of given number by using procedure of FACT ?

Page 39
Lab Task 07
Write a program to swap any two numbers by using procedure of SWAP?

Page 40
COMSATS Institute of Information Technology
Department of Electrical Engineering

Evaluation Sheet (Lab. Rubrics)

Name of Student: ………………………………….

Roll no. : ……………………………………………….

Batch & Section: …………………………………..

Date of Experiment: ………………………………

Marks Obtained: …………………………………..

Instructor’s Signature: ……………………………


Experiment # 07
Introduction to Microcontroller (8051) assembler &
Simulator using (Keil uVersion 4)

Objective:
To introduce 8051 microcontroller and its assembler Keil uVersion4.

Introduction:
Microcontroller

A micro controller is an integrated circuit or a chip with a processor and other support
devices like program memory, data memory, I/O ports, and serial communication interface
etc., integrated together. Unlike a microprocessor, a microcontroller does not require any
external interfacing of support devices. Intel 8051 is the most popular microcontroller ever
produced in the world market

Criteria for Selection of a Microcontroller

Criteria for selection of microcontroller in any embedded system are as following:

(a) Meeting the computing needs of task at hand efficiently and cost effectively

• Speed of operation
• Packing
• Power consumption
• Amount of RAM and ROM on chip
• No. of I/O pins and timers on chip
• Cost

(b) Availability of software development tools such as compiler, assembler and debugger.

Important Attribute of 8051

• A CISC (Complex Instruction Set Computer) processor


• Very simple and easy to understand
• 8 bit microprocessor
• Accumulator based architecture

Page 41
• 4 Port (Port 0, port 1, port 2, port 3)
• Multiple functions
• Instruction set-8051
o Data transfer instructions
o Logical instructions
o Branching Instruction
o Arithmetic Instruction
o Bit Oriented Instruction
• 8 General purpose registers available for user (R0 ~ R7).
• ‘H’ denotes hexadecimal number and ‘b’ denotes binary numbers.
• Case insensitive.
Keil uVersion 4
o The µVision IDE combines project management, run-time environment, build facilities,
source code editing, and program debugging in a single powerful environment.
o µVision is easy-to-use and accelerates your embedded software development.
o µVision supports multiple screens and allows you to create individual window layouts
anywhere on the visual surface.

Introduction to Keil tool for 8051 Microcontroller

Step 1:
Download from Keils website (free for student). Many versions are available there but use
Keil uVersion 4 for 8051.
Step 2:
Menu file:

Figure 1

Page 42
Step 3:
o How to create a project

Figure 2
o Create folder

Figure 3

Figure 4

Page 43
o Type of microcontroller

Figure 5
o Select Atmel

Figure 6
o AT89C51 with Description

Figure 7

Page 44
o Ask for file add
• Important for C program

Figure 8

Step 4

Create new file

Figure 9

Figure 10

Figure 11

Page 45
Step 5

o Save source file

Figure 12

o Create assembly file and save it

Figure 13

Figure 14

Page 46
Step 6

Add file to project

Method 1

Figure 15

Figure 16

Figure 17

Page 47
Method 2

Figure 18

Figure 19

Figure 20

Page 48
Step 8

o Write a program:

Example,

org 0000h

mov r1#2h

mov r2#20h

end

o Translate it (if first time)

Figure 21
o Build file

Figure 22

Figure 23

Page 49
Step 9

o Run the program

Figure 24

Or

Figure 25

o Warning about size limitation:

Figure 26

Page 50
o Execution
o Step by step

Figure 27

Lab Task 01

Write an assembly code to load value 55H into register A and then transfer its
content into register R0, R1, R2, R3 and R7 in Keil uVersion4 and run by using
single step command.

Page 51
Lab Task 02

Write an assembly code to add ten natural numbers by using INC and ADD
instruction. Then use the simulator to single-step the program and examine the
registers.

Page 52

Potrebbero piacerti anche