Experiment – 2

Familiarization with Assembly Instructions of 8086 Microprocessor by Adding Unsigned (+ve) Binary (Hex) Numbers

Read every Step of a Task and Work accordingly. When you finish a Step, Put Tick Mark (Ö ) on that Step using a Wood Pencil. Ask Lab Teacher for Help.

Task-2.1 Addition of Two Unsigned (+ve) 8-bit Binary (Hexadecimal) Numbers

Given the following Pseudo Code:

(03010) + (03011) ® 04010h, 04011h

(1) Write Meaning of the Pseudo Code

Two 8-bit numbers are being added by taking them from two memory locations. The result is 9-bit due to the generation of a carry bit (C). The lower 8-bit of result is saved into memory location 04010h. The upper part of the result is 1-bit; it is saved within the CF (Carry Flag) of the 8086 microprocessor. Seven zeros are placed to the left of the C to obtain an 8-bit format for the upper part of the result, and it is 0000 0000 (00 if there is no Carry) or 0000 0001(01 if there is a Carry). The result is saved into memory location 04011h.

(2) Draw Signal Flow Diagram (SFD) and Data Structure for the Pseudo Codes of Addition in your Lab Khata

Figure-2.1: Signal Flow Diagram (SFD) for adding two binary (hexadecimal) numbers

(3) Write Multiline Pseudo Codes in your (4) Draw Flow Chart in Lab Khata

Lab Khata for the addition

START: nop

L1: Initialization

Set MBA via ds-register

Set Offset pointer via bx-register

L2: ; read data from DSM

al ¬ (03010)

ah ¬ (03011)

L3: ; perform addition

(al + (ah) ® al, CF

L4: ; take decision about Carry

If ((CF) = 1)

Goto L7

L5: ;Save Result with RUB=00

(al) ® 04010h

00h ® 04011h

L6: Halt

L7: ;Save Result with RUB=01

(al) ® 04010h

01h ® 04011h

Goto L6

Figure-2.2: Flow Chart for adding two numbers

(5) Now Perform the Following Steps

(a) Write ASM codes for the Pseudo Codes of Step-3 in your Lab Khata, and show it to Lab Teacher. Set the ORG at 1000h. Save the ASM program as P21.asm.

(b) Use MASM and process P21.asm program to get the files: P21.obj and P21.lst.

(c) Use LOD186, and process P21.obj file to create the file P21.abs.

(d) Use MTKVCOM3 Interface, and download P2.abs into MicroTalk-8086 Trainer.

(e) Enter F7h into locations 03010h, and 23h into location 03011h.

(f) Execute the program at 01000h using DOP command.

(g) Add the numbers of Step-5e in your Lab Khata to see what result you expect.

(h) Open memory locations 040100h and 04011h. Check that these locations contain the expected result (01FE).

(i) Check that the program also gives correct result for the numbers FFh and FFh.

Task-2.2 Modify program P21.asm so that the result now appears at DP5-DP8 positions of the Trainer. Save the modified program as P22.asm. (Take help from Q14 of Task-1.17.)

Task-2.3 Addition of Three 8-bit Hexadecimal Numbers

Given the following Pseudo Code:

(03010) + (03011) + (03012) ® 04010, 04011

(1) Write Meaning:

Three 8-bit numbers are being added by taking them from three memory locations. The upper part of the result is the summation of the carries that are generated during the additions of the given numbers. Now, we need a ‘Carry Counter = CCntr’ to count the carries. Initially, the CCntr will hold 00h. We may use a register or a memory location as a CCntr. The lower 8-bit of the result will be stored into location 04010h, and the upper part of the result will be stored into location 04011h.

(2) Write Multiline Pseudo Codes:

START: nop

L1: ; initialization

Seg (0000) ® ds-register

Offset (3000) ® bx-register

00h ® CCntr (= ch-register)

L2: ; read data

ax ¬ (03010, 03011) ; data1, data2

cl ¬ (03012) ; data3

L3: ; add data1 and data2

(al) + (ah) ® al, CF

L4: ; add carry with CCntr

If ((CF) = 1)

Goto LX

(3) Draw Data Structure, and show it to the Lab Teacher. A data structure is a memory map that clearly shows the input and output variables.

(4) Draw Flow Chart for the Pseudo Codes of Step-2, and show it to Lab Teacher.

(5) Write ASM codes for the Pseudo Code (Step-2)/Flow Chart (Step-4) in your Lab Khata and PC, and show them to the Lab Teacher.

(6) Now perform the following steps:

(a) Set ORG at 2000h and save the program as P23.asm.

(b) Make P23.obj and P23.lst files using MASM.

(c) Make P23.abs from P23.obj file using LOD186.

(d). Download the P23.abs file into the CSM area of the MDA 8086 Trainer.

(e) Enter the inputs: Data1 = FFh, Data2 = CDh and Data3 = 12h.

(f) Execute the program at 0000:2000 using the GO command.

(g) Open the output memory locations and check that they contain correct result.

Task-2.4 Addition of Multibyte Binary (Hexadecimal Format) Numbers

Given the following Pseudo Code for adding multibyte numbers:

12345678h + ABCDEF12h ® 04010 – 04013 (assume no carry generation from MS-byte)

(1) Write assembly instructions in your Lab Khata and PC using 8-bit addition instructions. Save the program as P23a.asm. Assemble it and download the P24a.abs program. Execute the program at ORG 2500h. Check the output memory locations for correct answer.

(2) Write assembly instructions in your Lab Khata and PC using 16-bit addition instructions. Save the program as P23b.asm. Assemble it and download the P24b.abs program. Execute the program at ORG 3000h. Check the output memory locations for correct answer.

Task-2.5 Questions and Answers

1 What is an unsigned number?

An unsigned number is always a positive number. Every bit of an unsigned number bears positive positional values. For example, 87h (1000 0111) is an unsigned number. It means that all the bits of this number bear positive positional values. As a result, the additions of these positional values yield a positive value.

87h = 1000 0111b = 1x27 + 0 + 0 + 0 + 0 + 1x22 + 1x21 + 1x20 = 128 + 4 + 2 + 1 = 135d (d=decimal).

2 Discuss the features of an 8-bit signed number system.

A signed number system is capable to represent both positive and negative numbers. In an 8-bit signed number system, the MS-bit is reserved for the sign (0 indicates positive signed magnitude as 0x27; 1 indicates negative signed magnitude as -1x27) of the number. The lower 7-bit always carry positive positional values. Examples:

(a)  0000 0000 = 0

(b)  0110 1001b = 0x27 + 1x26 + 1x25 + 0x24 + 1x23 + 0x22 + 0x21 + 1x20

= 0 + 64 + 32 + 0 + 8 + 0 + 0 + 1 = 105

(c)  0111 1111 = 0x27 + 1x26 + 1x25 + 1x24 + 1x23 + 1x22 + 1x21 + 1x20

= 0 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = +127

(d)  1000 0000 = -1x27+ 0x26 + 0x25 + 0x24 + 0x23 + 0x22 + 0x21 + 0x20 = -128

(e) 1110 1001 = -1x27 + 1x26 + 1x25 + 0 + 1x23 + 0 + 0 + 1x20 = -128 + 105 = -23.

(f) 1111 1111 = -1x27 + 1x26 + 1x25 + 1x24 + 1x23 + 1x22 + 1x21 + 1x20 = -128 + 127 = -1.

In the computers of Intel architecture, the negative numbers are represented in 2’s complement code (2sC). The procedures to represent the negative number -23 in 2sC:

a.  Ignore negative ( - ) sign. Now, we have 23

b.  Convert 23 into its binary equivalent. It is 0001 0111

c.  Add 1. Now, we have 1110 1000 + 1 ® 1110 1001b = E9h. This is 2’s complement code of -23

d.  Validity check:

E9h = 1110 1001b = -1x27 + 1x26 + 1x25 + 0 + 1x23 + 0 + 0 + 1x20 = -128 + 105 = -23

3 Write the meaning and ASM Code for the following Pseudo Code:

23h + (CF) ® al

Meaning: The number 23h is added with the carry bit of the previous operation. The result goes into al-register.

ASM Code: mov al, 00h

adc al, 00h

4 Write the meaning and ASM Code for the following Pseudo Code:

23h + C+ (al) ® al

5 Write the meaning and ASM Code for the following Pseudo Code:

(03010) + 12h ® 03010h

6 Write ASM code for the following subtraction operation:

789Ah – 1234h ® dx

7 Given that: (03012) = 45h, (al) = 32h and (CF) = 1

What will be the content of al-register after the execution of the following instruction?

adc al, BYTE PTR ds:[bx+12h]

8 Write ASM codes for the following operation:

12h + FFh + CDh ® 04010, 04011

9 Write Pseudo Code for the following Text Code: Read data from location 03012h, add the data with al-register and then save the result into location 03012h.

10 Write ASM code to get the 2’s complement code for -45. Save the result into location 04010h.

36