INTEL 8086 Programming examples Part 1

Example 9.1

(a) Determine the effect of each of the following 8086 instructions:

i). DIV CH            i). CBW            iii). MOVSW Assume the following data prior to execution of each of these instructions independently (assume that all numbers are in hexadecimal): (DS) = 2000H, (ES) = 4000H, (CX) = 0300H, (AX)= 0091H, (20300H) = 05H, (20301H) = 02H, (40200H) = 06H, (40201H) = 07H, (SI) = 0300H, (DI) = 0200H, DF=0.

(b) Write an 8086 assembly language program for each of the following C language program structures:

imageSolution

(a)

i). Before unsigned division, CH contains 0310 and AX contains 14510• Therefore, after DIV CH, (AH) =remainder= OIH and (AL) =quotient= 48 10 = 30H.

ii). CBW sign-extends the AL register into the AH register. Because the content of AL is 91H, the sign bit is 1. Therefore, after CBW, (AX)= FF91H

image

(b)

i). Assume addresses x and y are initialized with the contents of the 8086 memory locations addressed by offsets BX and SI in segment register, DS:

image

Example 9.2

(a) Write an 8086 assembly program to find (X2)/255 where X is an 8-bit signed number stored in CH. Store the 16-bit result onto the stack. Initialize SS and SP to 1000H and 2000H respectively.

(b) What are the remainder, quotient, and registers containing them after execution of the following 8086 instruction sequence?

image

imageExample 9.3

Write an 8086 assembly language program to add two 16-bit numbers in CX and DX and store the result in location 0500H addressed by DI.

Solution

imageExample 9.4

Write an 8086 assembly language program to add two 64-bit numbers. Assume SI and DI contain the starting offsets of the numbers. Store the result in memory pointed to by DI. Solution

image

imageExample 9.5

Write an 8086 assembly language program to multiply two 16-bit unsigned numbers to provide a 32-bit result. Assume that the two numbers are stored in CX and DX.

Solution

image

imageExamule 9.6

Write an 8086 assembly language program to clear 5010 consecutive bytes starting at offset 1000H. Assume DS is already initialized.

Solution

imageExamule 9.7

Write an 8086 assembly program to implement the following C language program loop: sum= 0;

for (i = 0; i <=99; i = i + 1)

sum= sum+ x[i] * y[i];

The assembly language program will compute LxJ’; where X; andY; are signed 8-bit numbers stored at offsets 4000H and 5000H respectively. Initialize DS to 2000H. Store 16-bit result in DX. Assume no overflow.

Solution

image

imageExample 9.8

Write an 8086 assembly language program to add two words; each contains two ASCII digits. The first word is stored in two consecutive locations with the low byte pointed to by SI at offset 0300H, while the second word is stored in two consecutive locations with the low byte pointed to by DI at offset 0700H. Store the unpacked BCD result in memory location pointed to by DI. Assume that each unpacked BCD result of addition is less than or equal to 09H.

Solution

image

image

Example 9.9

Write an 8086 assembly language program to compare a source string of 5010 words pointed to by an offset 1 OOOH in the data segment at 2000H with a destination string pointed to by an offset 3000H in the extra segment at 4000H. The program should be halted as soon as a match is found or the end of the string is reached.

Solution

image

image

Example 9.10

Write a subroutine in 8086 assembly language which can be called by a main program in the same code segment. The subroutine will multiply a signed 16-bit number in CX by a signed 8-bit number in AL. The main program will perform initializations (DS to 5000H, SS to 6000H, SP to 0020H and BX to 2000H), call this subroutine, store the result in two consecutive memory words, and stop. Assume SI and DI contain pointers to the signed 8-bit and 16-bit data respectively. Store 32-bit result in a memory location pointed to by BX.

Solution

image

Leave a comment

Your email address will not be published. Required fields are marked *