INTEL 8086 Programming examples Part 2

Example 9.11

Write an 8086 assembly program that converts a temperature (signed) from Fahrenheit degrees stored at an offset contained in SI to Celsius degrees. The program stores the 8-bit integer part of the result at an offset contained in DI. Assume that the temperature can be represented by one byte and, DS is already initialized. The source byte is assumed to reside at offset 2000H in the data segment, and the destination byte at an offset of 3000H in the same data segment. Use the formula: C = (F-32)/9 x 5

Solution

image

Example 9.12

Write an 8086 assembly language program to multiply two 8 bit signed numbers stored in the same register; AH holds one number and AL holds the other number. Store the 16- bit result in DX.

Solution

image

image

Example 9.13

Write an 8086 assembly language program to move a block of 16-bit data oflength 10010 from the source block starting at offset 0200H to the destination block starting at offset 0300H from low to high addresses.

Solution

imageExample 9.14

Write an 8086 assembly language program that will perform: 5 x X+ 6 x Y + (Y/8) (BP)(BX) where X is an unsigned 8-bit number stored at offset 01 OOH and Y is a 16-bit signed number stored at offsets 0200H and 0201H. Neglect the remainder of Y/8. Store the result in registers BX and BP. BX holds the low 16-bit of the 32-bit result and BP holds the high 16-bit of the 32-bit result.

Solution

imageExample 9.15

Write an 8086 assembly language program to add four 16-bit numbers stored in consecutive locations starting at offset 5000H. Store the 16-bit result onto the stack. Use ADC instruction for addition.

Solution

image

image

Example 9.16

Write a subroutine in 8086 assembly language in the same code segment as the main program to implement the C language assignment statement: p = p + q; where addresses p and q hold two 16-digit (64-bit) packed BCD numbers (Nl and N2). The main program will initialize addresses p and q to DS:2000H and DS:3000H respectively. Address DS:2007H will hold the lowest byte ofNl with the highest byte at address DS:2000H while address DS:3007H will hold the lowest byte of N2 with the highest byte at address DS:3000H. Also, write the main program at offset 7000H which will perform all initializations including DS to 2000H, SS to 6000H, SP to 0020H, SI to 2000H, DI to 3000H, loop count to 8 and, then call the subroutine.

Solution

image

image

Example 9.17

Write an 8086 assembly language program to move the 8-bit contents of a memory location addressed by the contents of AL and BX into AL. Use XLAT instruction. This program will illustrate that XLAT is equivalent to MOV AL, [AL][BX].

Solution

image

imageExample 9.18

Write a subroutine in 8086 assembly language which can be called by a main program in a different code segment. The subroutine will compute IX/ IN. Assume the X/s are 16-bit signed integers, N = 100 and, IX/ is 32-bit wide. The numbers are stored in consecutive locations. Assume SI points to the X/s. The subroutine will start at an offset 7000H, and will initialize SI to 4000H, compute IX/ IN, and store 32-bit result in DX:AX (16-bit remainder in DX and 16-bit quotient in AX). Also, write the main program which will initialize DS to 2000H, SS to 6000H, SP to 0040H, call the subroutine, and stop.

Solution

image

image

Note: In the above, DIY is used for computing sum (Xi**2)/N since both SUM (Xi**2) and N are unsigned (positive). Also, in order to execute the above program, values for Xi must be stored in memory using 8086 assembler directive, DW.

Labels: