Вы находитесь на странице: 1из 42

Experiment- 1

Introduction to the 8086 single- board microcomputer Objectives


* *

Examine and modify information in memory Examine and modify the contents of the registers.

8Design and test simple data transfer programs.

Introduction
The 8086 trainer kit is built around the Intel 8086 microprocessor (CPU). It contains simple keypad for interning commands and data, a simple 7 segment

display unit for displaying data and result, a monitor program contained in (4k byte ) of EPROM and (2k byte ) RAM and input / output ports The monitor program contains all necessary subroutines for the operation of the keypad and display, as well as some other useful functions.

The 8086 registers


The 8086 use a group of registers for most data manipulation tasks. These registers play an important role in programming the 8086. Figure (1) shows the 8086 registers that can be accessed by the user. Here is a brief description of each register. 1- Instruction pointer (IP ): This (16 bit) register identify the location of the

next word of instruction code to be fetched from the current code segment of memory The value of the address for the next code access is often denoted as
.

CS : IP.

2- Data registers: These are (16 bit) four general purpose registers and they are

reflected to as the accumulator (A), the base register (B), the count register (C), and the data register (D). Each of these registers can be accessed either as a whole (16

bit) and denoted as (AX ,BX , CX, DX) or as an (8 bit) and denoted as (AL, AH, BL, BH, CL, CH, DL DR ) They are used for temporary storage of frequently used
.

immediate result.

3- Pointer and index registers (DI, SI ,BP, SP): These (16 bit) registers shown in fig

(1) are two pointer registers ( BP ( base pointer ) , SP ( stack pointer)). And two index registers (DI (destination index), SI (source index)). They are used to storage the offset address. SS: (SP) ES 0r DS : (SI or DI)

4- Status register (SR): Is a (16 bit) register also called the flag register. Just nine of

its bits are implemented. Six of these are (ZF) zero flag (CF) carry flag, (OF) overflow flag, (AF) auxiliary carry flag , (PF) parity flag, (SF) sign flag and three control flag: (DF) direction flag, (IF) interrupt enable flag and (TP) trap flag The
.

logic states of these are produced as the result of executing an instruction, such as ADD.

5- Segment register: These are (16 bit) four registers, code segment (CS), stack

segment (SS), data segment (DS) and extra segment (ES) each of these registers contains a base address that points to the lowest addressed byte of the segment in memory. And give a maximum of 256k byte of active memory.

8086 data transfer instruction


The instruction of the microprocessor defines the basic operations that a programmer can specify to the device to perform.

The 8086 move data from place to place in the system using a group of data transfer instruction. These instructions provided to move data either between its internal registers or between an internal register and a storage location in memory. A summary of several 8086 data transfer instruction is given below:

The procedure of writing and executing a program using (SDK 8086) is given below: 1) Use the (Examine Byte) (EB) key to examine memory contents. Enter the segment address then press the colon key G) to separate the segment address from the offset address and then inter the offset address. And then press the comma key (,) to show the contents on the display and to increment the address field to the next memory location.

2) The (Exam Reg.) (ER) key may be use to examine register contents.

3) The (GO) key followed by the code segment address and the (:) key then the offset address and then the (.) period key allow immediate execution of the program. 4) The (Examine Word) (EW) key may be used to examine a 2byte word of memory contents.

5) INTR key is used to point to a routine within the monitor, which causes all of the 8086 registers to be saved. Control is returned to the monitor for subsequent command entry.

Procedure:

For each of the following cases manually assemble and execute the given program, check the results by examining appropriate registers or memory locations. Document your results as shown in the following example:

Given program

CS: IP MOV AX, 0001H; place a constant (16 bit) into reg. (AX)

MOV BX ,0002H MOV AH ,20H MOV DL 72H ; place a constant (8 bit) into reg. (DL)
,

HLT

Assembled program

Address

Contents

Instruction

Comments

0000:0100 : 0103 :0106 :0108 :010A

B80100 BBO200 B420 B2 72 F4

MOV AX, 1H MOV BX 2H


,

MOV AH, 20H MOV DL, 72H HLT

a)
MOV CX,0200 XCHG AX,CX MOV SI,100H MOV DI,120H MOV AH,[SI] MOV [DI],AH XCHG [300],CX HLT

b)
MOV BX,0100 MOV DI,BX LEA LDS HLT SI,[DI+BX+05] DI,[2005]

Discussion:1-Describe the internal interface between the BIU and EU.

2- Identify the pointer and index registers of the 8086. In what way they are different from the general purpose registers?

3- Which of the following instructions can not be coded in 8086 assembly language? Give the reason why not, if any. To verify your answer, code each instruction.

a) MOV AX,72 b) MOV CX,3007 c) MOV DS,BX

d)MOV AX, 23 FB 9
e) MOV AL,97F f) MOV SI,9516 g) MOV BX,CS

h)MOV CS,BH
I) MOV DS, 9BF2 j) MOV AX ,DL

Experiment- 2

Binary Arithmetic
objectives
* Add or subtract (16-bit) or (multi- byte) quantities. * Inspect and interpret the contents of the flag register.

Table (1) contains the allowed operand for the addition and subtraction operation while table (2) contains the allowed operand for DEC and INC operation. Each for these instructions affects one or more flag in the status register. Fig (1) illustrates the position of each flag in the status register. The status register (SR) may be observed and examined using examine register function.

This status register contains six status flag and three control flag. The function of these status flag are outlined below: 1-Carry flag (CF): this flag is set whenever there is a carry out, either from d7 after an 8-bit operation or from d15 after a 16-bit data operation. 2- Parity flag (P0: after certain operations the parity of the results low- order byte is checked, if the byte has an even no. of iS ,the parity flag is set. 3- Auxiliary carry flag (AF):- if there is a carry from d3 to d4 of an operation, this bit is set, other wise, it is cleared. Used for BCD instruction. 4- Zero flag (ZF):- the Zero-flag is set to 1 if the result of an arithmetic or logic operation is Zero. 5- Sign flag (SF):- binary representation of signed number uses the M.S.B as the sign bit. After arithmetic operation the SF represent the sign of the result.

6- Over flow (OF):-this flag is set whenever the result of a signed number operation is too large, causing the high-order bit to over flow into the sign bit.

Multi- word (1 6-bit) Addition and sit btraction


Addition of multi- word quantities must be performed one word at a time using the (16-bit) addition instructions. As an example, the following program adds the two words stored in data segment offset of (200,201,202,203) to a twowords stored in a data segment offset of (204,205,206,206) store the result at (200,201,202,203).

MOV DI, (200) ; load DI with offset address MOV SI, (204) ; load SI with offset address of the second no. MOV AX, (SI) ; load the first word infix ADD AX, (DI) ; add the first word of the first no. with the first word of the second no. MOV (DI), AX INC DI INC DI INC SI INC SI MOV AX,(SI) ADC AX, (DI) MOV (DI), AX HLT

Notice that the two least significant words are added first using the ADD instruction. The addition of these two words may produce a carry, which the ADC instruction then adds with the two most significant words. When performing multi-word subtraction, subtract the two least significant words with SUB instruction. Subtract all more significant words using the SBB instruction.

Procedure:1- Write a program to add 5 bytes of data stored in a data segment offset of (600)H, use BX register as a pointer for the location where the byte are stored.

2- Write a program to perform multi-word subtraction by forming the (2S complement) of the subtrahend and then adding it to the minuend. verify your results by performing the following numbers 557460FF 132FF100

Discussion:1- Perform the following operation using the direct addressing mode, index addressing mode, base addressing mode and the base index addressing mode. ADD AX,DX

2- Find CF, ZF, and AF for each of the following. Also indicate the result of the addition and where the result is saved.

(a)

MOV BH,3F ADD BH,45

(B)

MOV DX,4599 MOV CX,3458 ADD CX,DX

(c)

MOV BX,0FF0 ADD BL,BH

(d)

MOV BL,9F ADD BL,61

3- Write a program to add 5 words the distance between each word is five locations, these 5 words stored in a data segment offset address starting at (2700)H. Store the result in location (2900)H.

Experiment- 3

Branching and Decision- Making

Objectives
* * *

Test the 8086 status flags with the conditional jump instruction. Compare binary quantities with the comparison instructions. Write programs that include simple looping structures.

Introduction
Decision-making programs rely on the proper use of the 8086 flags. Note that some 8086 instructions do not effect any flags while other instructions modify several of them. There is an instruction included in the instruction set of the 8086 which can be used to compare two 8-bit or 16-bit numbers. It is the compare (CMP) instruction of table (1) .table (2) shows that the operands can reside in a storage location in memory a register within the microprocessor. Or as part of the instruction.

The result of the comparison is reflected by changes in six of the status flags of the 8086 . The logic state of these flags can be referenced by instructions in order to make a decision wither or not to alter the sequence in which the program executes. The 8086 microprocessor allows two different types of jump. They are the unconditional jump and the conditional jump.

The Jump instructions specified with a short label Near- label , Memptr 16 or Regptr,

16 operand represent intra segment Jumps. On the other hand, the inter segment Jump instructions correspond to the farlable and memptr-32 operands.

Procedure

1- Write a program to add the following five date bytes stored in memory location starting from (200)H if the sum generates a carry , stop the adding , and store (01)H in memory location (300)H, otherwise, continue adding and store the sum in memory location (300)H. DATA (H): F I .66,90,34,DD

2- Write a program to read the data stored in memory location (200)H to (210)H and find the largest byte among them and store it in memory location (300)H Test
.

your program for the following data and record the status of the (CY) and (Z)
,

flags after executing the program.

DATA (H): (03,04,02,19,71 ,3B, 1 C,C3,99,00, 1F,FB,EE,39,F 1,52 and B2). (03,04,02,19,71,3B, 1C,C3,99,00,IF,FB,EE,39,F 1,52 and B2).

Discussion:1- what happens to the ZF and CF status flags as the following sequence of instructions is executed? Assume that they are both initially cleared. MOV BX,1111H MOV AX,BBBBH CMP AX.BX

2- write a program to count the number of data elements equal (FF)H in a set of data starting at address (0100)H and ended with the value of (00)H.

3- Write a program to compare the content of location (1070)H with the content of (1071)H

If content of location (1070)H is greater, let register (CL) contain (FF)H. If content of location (107 l)H is greater, let register (CL) contain (1 l)H. If they are equal , let register (CL) equal (00)H.

Experiment-4

Bit Manipulation

Objectives

Use the 8086 logical instructions to set, clear, complement a number.


*

Use the 8086 rotate instructions to manipulate groups of bits.

Introduction
The 8086 has instructions for performing the logic operation AND, OR, exclusive OR and NOT. The AND, OR and XOR instructions perform
-

their respective logic operation bit by bit on the specified source and destination operands, the result being represented by the final contents of the destination operand.

Table(1) Logical instructions, table(2) allowed operands for AND, OR and XOR, table(3) allowed operands for NOT. Table(1) shows the allowed operand combinations for the AND, OR and XOR instructions. For example, the instruction AND AX, BX Causes the contents of BX to be ANDed with the contents of AX. The result is reflected by the new contents of AX. The NOT Logic instruction differs from those for AND, OR and exclusive- OR in that it operates on a single operand. Example: Describe the result of executing the following sequence of instructions. MOV AL, 44H AND AL, 1FH OR AL,C0H

XOR AL, 0FH NOT AL

Solution:

The first instruction moves the immediate operand (010 10101)2 into the AL register. This loads the data that are to be manipulated with the logic instructions. The next instruction performs a bit by bit AND operation of the contents of AL with immediate operand (00011111)2. This gives: (01010101)2. (00011111) 2 (00010101)2

This result is produced in destination Register AL. Note that this operation has masked off the 3 most significant bits of AL. The next instruction performs a bit by bit Logical OR of the present contents of AL with immediate operand (CO)6 . This gives: (00010101)2 + (11000000)2 =(11010101)2 AL= (11010101)2 This operation is equivalent to setting the two most significant bits of AL. The fourth instruction is an exclusive - OR operation of the contents of AL with immediate operand (00001111)2. We get (11010101)2 (00001111)2 = (11011010)2 AL = (11011010)2 Note that this operation complement the logic state of those bits in AL that are ones in the immediate operand. The last instruction, NOT AL, inverts each bit of AL Therefore, the final contents of AL become (AL)=(11011010)2 =(00100101)2

The four shift instructions of the 8086 can perform two basic types of shift operations. They are the logical shift and the arithmetic shift.

Mnemonic Meaning

Format

Operation

Flags

SAL/SHL

shift arithmetic left! shift logical left

Shift the (D) left by the number of bit positions equal to SAL! D, Count count and fill the SHL vacated bits positions on the right with zeros.

OF, CF

SHR

shift logical SHR right

Shift the (D) right by the number of bit positions equal D, Count to count and fill the OF, CF vacated bits positions on the left with zeros. Shift the (D) right by the number of bit positions equal OF,SF,Z to count and fill the F,AF,PF, D, Count vacated bits CF positions on the left with original most significant bit.

SAR

shift arithmetic right

SAR

Destination count Register Register Memory Memory 1 CL 1 CL

Another group of instructions, Known as the rotate instructions, are similar to the shift instructions, we just introduced. This group includes the rotate left (ROL), rotate right (ROR), rotate left through carry (RCL), and rotate right through carry (RCR) instructions.

Destination count Register Register Memory Memory 1 CL 1 CL

Procedure:-

1-Write a program to sit (bit- 15) and clear (bit-O) of a Word wide numbers stored in memory locations form (01F0)H to (01FF)H 2- Write a program to implement the following expression using shift instructions to perform the arithmetic: 3(AX) + 7(BX)? (DX)

Discussion:1- Write an instruction sequence that generates a byte - size integer in the memory location identified by label RESULT. The value of the byte integer is to be calculated as follows:
RESULT = AL. NUM1 + (NUM2. AL + BL)

Assume that all parameters are byte size. 2 - Write a program to complement the (8 - bit) numbers stored in location (20200)H and then count the number of Zeros in this byte then store the result in memory location (20201)H. 3- Implement the following operation using shift and arithmetic Instructions: 7(AX) - 5(BX) -1/8 (BX)? (AX)

Experiment- 5
Subroutines and The stack

Objective
* *

Explain how information is stored and retrieved from the stack. Use the stack to link a Subroutine to its calling program.

Introduction

Subroutines are procedures written separate from the main program. Whenever the main program must perform a function that is defined by a Subroutine, it calls the Subroutine into operation. In order to do this, control must be passed from the main program to the starting point of the Subroutine. Execution continues with the Subroutine and upon completion control is returned back to the main program at the instruction that follows the one that called the Subroutine. There are tow basic instructions in the instruction set of the 8086 for Subroutine handling. They are the call (CALL) and return (RET) Subroutines. Together they provide the mechanism for calling a subroutine into operation and returning control back to the main program at its completion.

CALL allows implementation of two types of operations: the intrasegment call and the intersegment call. The CALL instruction is shown in table (1), and its allowed operand Variations are shown in table (2).

Upon entering a Subroutine. We find that it is usually necessary to save the contents of certain registers or some other main program parameters. These values are saved by pushing them onto the stack. Typically, these data correspond to registers and memory locations that are used by the subroutine. In this way, their original contents are kept intact in the stack segment of memory during the execution of the subroutine. Before a return

to the main program takes place. The saved values from the stack back into their original locations. This is done by popping the saved values from the stack back into their original locations. The instruction that is used to save parameters on the stack is the push (PUSH) instruction. And that used to retrieve them is the pop (POP) instruction.

At times, we also want to save the contents of the flag register, and if we save them, we will later have to restore them. These operations can be a complies with push flags (PUSH F) and pop flags (POP F) instructions.

Every subroutine must end by executing an instruction that returns control to the main program. This is the return (RET) instructions. It is described in table (6) and table (7).

Procedure:

1 - Write a program to copy the odd numbers of an array started at location (00140)H to another array starting at address (00150)H. The even numbers must be stored at memory locations starting at address (00160)H. Note: All the copy operations above must be carried out in a subroutine. DATA(H): (01,2F,3E,48,87,09,10,E4,5E,and 02).

2- Write a program find the average of four 16-bit data elements stored at memory locations (00140-00147)H. Store the result in register (DX). The

summation of dements must be carried out in a subroutine. Assuming that the result of summation does not exceed an (16-bit). DATA (H): (1010)H + (1E10)H + (0011)H + (3211) H

Discussion:1- Identify the type of call the type of operand, and operation performed by each of the instructions that follows. (a) CALL (b) CALL (c) CALL 1000 H WORD PTR [1000] H D WORD PTR [BX + DI]

2 - Described the operation performed by each of the instructions that follows. (a) PUSH (b) PUSH (c) PUSH (d) POP (e) POPF DS [SI] DI [BX + DI]

3 - Given an array A (I) of 100 16-bit signed integer numbers, write a program to generate a new array B (I) so that

B (I) = A (I), for I = 1 and 100 And B (I) = [A (I-1) 5A (I) + 9A (I+1)], for all others I s

For the calculation of B (I), the values of A (I-1), A (I) and A (I-1) are to be passed to a subroutine in registers AX, BX and CX and the subroutine returns the result B (I) in register AX.

4 When must PUSH F and POP F instructions be included in a subroutine.


-

Experiment- 6

BCD Arithmetic

Objectives
* Use

the Decimal adjust for addition (DAA) instruction & Decimal adjust for

subtraction
* (DAS). * Add

multi-digit BCD quantities.

Introduction
BCD (Binary Coded Decimal) is representation of decimal numbers in which

each decimal digit is separately coded into a binary number. The 8086 microprocessor con not add or subtract BCD quantities. It dose, however allows for BCD arithmetic with the help of the (DAA) (Decimal adjust for addition and (DAS) (decimal adjust for subtraction). The DAA is used too perform an adjust operation for the addition of packed BCD numbers and for a packed BCD subtraction we use the decimal adjust for subtract (DAS) instruction. Adjust instruction for BCD multiplication and division are also provided. These are adjust AX for multiply (AAM) and adjust AX for divide (AAD) The
.

multiplication performed just before execution of the AAM instruction is assumed to have been performed on two unpacked BCD numbers with the product produced in AL. The AAD instruction converts the result in AH and AL to unpacked BCD numbers.

Procedure:

1- Write an 8086 program to add the 4-digit BCD number stored in locations (001B0- 001B1)H , to the 6-digit number stored in locations (001C0- 001C2)H The least significant bytes are stored in locations (001B0)H and (001C0)H . Store the result in locations starting at (00lD0) H.

2- Two byte sized BCD integers are stored at the offset addresses (0013)H and (0014)H , write an instruction sequence to generate their difference summation division and multiplication and store the result at offset addresses starting at (0015)H.

Discussion: -

1- Write a program that converts a given 16-bit BCD number to its equivalent binary number .The BCD number is in register DX, Replace it with the equivalent binary number.

2- Write a program to subtract two (2-digit) unpacked BCD numbers .the first number stored at memory locations (001A0)H and (001A1)H and the Second number stored at memory locations (001A2)H and (001A3)H store the result as a unpacked BCD number at memory locations (001A4)H and (001A5)H.

Experiment-7Loop and the Loop Handling Instructions


Objective:*To be familiar with the LOOP, and the LOOP Handling instructions.

Introduction:The LOOP instruction is a combination of the conditional jump and the decrement CX instructions. It will decrement the contents of the register CX and, if CX is not 0, jump to the label associated with LOOP. If CX becomes 0, then the next sequential instruction in the program is executed.

Conditional LOOP: The LOOP instruction has some conditional forms. - LOOPE. - LOOPNE. LOOPE (LOOP while equal): will jump to the address pointed to by the label if CX is not 0 and an equal condition exists. It will exit the loop whenever CX becomes 0 or whenever unequal condition is indicated by a flag bits.

LOOPNE (LOOP while not equal): functions in the opposite manner. LOOPNE remains in the loop as long as CX is not 0 and while an unequal condition exists. LOOPNE exits the loop when CX becomes 0 or whenever an equal condition exists. Both are loop while instructions: LOOPE is a loop while equal, and LOOPNE is a loop while not equal.

Procedures:
1- Use LOOP instruction to transfer a block of data stored at memory locations (02050-0205F) to a new memory locations (02090-0209F).

2- Write a program to examine a block of data stored at memory locations (OAOO 1 -OAOOF), if it has a byte equal to (05) or not.

Discussion:1- Use LOOP instruction to find the largest word in a block of data stored at
memory locations (20500-205 OF).

2- Write a program to examine the block of data stored at memory locations (00900-009 11), if it has a word not equal to (9080).

Experiment- 8

String handling operation Objectives

Move data from one block to a block else where in memory.


*

Scan a string of data elements stored in memory looking for a specific

value.
*

compare the elements of two strings.

Introduction

The 8086 microprocessor is equipped with special instructions to handle string operations. By string we mean a series of data words or bytes that reside in consecutive memory locations. There are five basic string instructions in the instruction set of the 8086. These instructions are move byte or word string (MOVS, MOVSB/MOVSW) compare string (CMPS). And store string (STOS). They are called the basic string instructions because each defines an operation for one element of a string. Thus these operations must be repeated to handle a string of more than one element.

Move string MOVS, MOVSB /MOVSW


-

..-

The instructions MOVS MOVSB and MOVSW all perform the same
, ,

basic operation An element of the string specified by the source index (SI)
.

register with respect to the current data segment (DS) register is moved to the location specified by the destination index (DI) register with respect to the current extra segment (ES) register. The move can be performed on a byte or a word of data.

Compare string and scan string CMFS and SCAS: Th

CMPS instruction can be used to compare two elements in the same or different strings. It subtracts the destination operand from the source operand and adjusts flags CF, PF, AF, ZF, SF and OF accordingly. The result of subtraction is not saved, therefore, the operation does not affect the operands in any way. The scan string (SCAS) instruction is similar to CMPS; however, it compares the byte or word element of the destination string at the physical address derived from DI and ES to the contents of AL or AX, respectively. The flags are adjusted based on this result and DI incremented or decremented.

Load and store strings LODS and STOS:

The last two instructions, load string (LODS) and store string (STOS) are specifically provided to move string elements between the accumulator and memory.

LODS loads either a byte or a word from a sting in memory into AL or AX, respectively . The address in SI is used relative to DS to determine the address of the memory location of the string element. On the other hand, STOS stores a byte from AL or a word from AX into a string location in memory. This time the contents of ES and DI are used to form the address of the storage location in memory.

Repeat string REP:

In most applications, the basic string operation must be repeated in order to process arrays of data. This is done by inserting a repeat prefix before the instruction that is to repeated. The repeat prefixes of the 8086 are show in table (2) The first prefix, REP, causes the basic string operation to be repeated until the contents of register CX become equal to zero. The prefixes REPE / REPZ stand for the same function. They are meant for use with the CMPS and SCAS instructions. With REPE / REPZ , the basic compare or scan operation can be repeated as long as both the content is of CX are not equal to zero and the zero flag is 1 The last prefix , REPNE / REPNZ , works similarly to REPE / REPZ except that now the operation is repeated as long as CX is not equal to zero and ZF is zero.

Prefix REP

Used with MOVS STOP CMPS SCAS

Meaning Repeat while not end of string CXO Repeat while not end of string and strings are equal CX0 and ZF=l

REPE / REPZ

Auto-indexing for string instruction

.. -

The 8086 provides two instructions, clear direction flag (CLD) and set direction flag (STD), to permit selection between auto in decrement and auto decrement mode of operation these instruction are show in table (3). When CLD is executed, DF is set to 0. This selects auto increment mode and each time a string operation is performed SI and / or DI are increment.

Procedure:

1. Write a program to transfer a string of eight 16- bit element stored in memory location starting at (OOIBO)H to a new memory location starting at (OOIBO)H. Use the MOVSW instruction.

2. A string of 20 8-bit elements stored at (OOIBO)H write a program to count the number of elements in the string equal to (00)H and store the result in DL register.

3. Write a program to load a block of memory locations from (OOICO)H through (OICF )H with number (05)H

Discussion

..-

1. write equivalent instruction sequences using string instruction for each of the following :(a) MOV AL,(SI) MOV (DI), AL INC SI INC DI

(b) MOV AX,(SI) INC SI INC SI

(C) MOV AL,(DI) CMP AL,(SI) DEC SI DEC DI

2. Write a program using string instructions that corn pares the element of two arrays; each array contains 10 16-bit numbers. If the two arrays are found to be unequal, save (FF)H in memory location with offset address (1010)H in the current data segment; otherwise, write (00)H into this location.

3. Describe the difference between CLD & STD instruction.

Вам также может понравиться