0% found this document useful (0 votes)
5 views

Experiment 3

The document describes an experiment to convert binary coded decimal (BCD) numbers to hexadecimal. It involves adding two BCD vectors stored in memory locations, storing the result in another memory location as BCD, and then converting it to hexadecimal. The assembly language program code and instructions to perform the experiment on an 8086 CPU emulator are provided.

Uploaded by

ahmed alhammad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Experiment 3

The document describes an experiment to convert binary coded decimal (BCD) numbers to hexadecimal. It involves adding two BCD vectors stored in memory locations, storing the result in another memory location as BCD, and then converting it to hexadecimal. The assembly language program code and instructions to perform the experiment on an 8086 CPU emulator are provided.

Uploaded by

ahmed alhammad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment 3

BCD TO HEXA DECIMAL CONVERSION Theory:


Theory:
Binary coded decimal [BCD] is a representation of decimal number in binary form
(hexadecimal form). Which comes into two types: unpacked BCD where each decimal digit is
represented by four bit in the lower section of a byte leaving the high section filled with zeros thus
each byte can hold one decimal digits and packed BCD where each decimal digit is represented by
four bit thus each byte can hold two decimal digits.

80x86 systems usually deals with packed BCD, however in case needed developers can
easily write a program to convert packed BCD to unpacked BCD.

Experiment:
Assume that we have two BCD vectors v1 stored in memory starting from 1200h and v2
stored in memory 1220h.
Step1 Calculate v3
v3=v1+v2
Then store v3 in memory starting from 1300h. Make sure that v3 is a BCD numbers.

Step2
Convert v3 to hexadecimal vector v4 and store it in memory location 1320h.
To convert BCD to hexadecimal use this method
Hexadecimal = BCD_high * 10 + BCD_low.

v1 = {13, 15, 28, 17, 39, 52, 99, 99}


v2 = {72, 35, 15, 12, 20, 71, 60, 61}
Instruction used in this experiment
1- LEA regx load effective address into DS:regx
This is usually used in emulator programs since normally programmer does not know what
the exact memory location are will be for his data;
EX:
LEA SI, vect1;
LODSB
Hlt.
vect1 db 50;

2- DAA ; Decimal adjust for addition


Since ADD instruction treats the numbers as binary/hexadecimal the result of adding two
BCD numbers will be in calculated in HEX, DAA is used to fix the result back to BCD.
EX
15h+ 35h = 4A h using DAA 4Ah will be converted to 50 h which is same as
15+35=50 in decimal mathematics. If the resulted number for ADD instruction is does not
have values [A,B … F] in its lower bits there will be no change on the number
13h+ 72 h = 85 h.
If ADD instruction result is larger than 0x63 and less than 0xFA, DAA will rise CA
flag
52h+ 71h=C3 h ; using DAA will results in Cary 1 and 23h same as 52+71=123
Note: the experiment program did not treat this case. See discussion section.
If result larger than 0xF9 DAA will fail to give proper results.
3- ROR : rotate right ;
The rotate instructions shift the bits around, just like the shift instructions, except the bits
shifted out of the operand by the rotate instructions recirculate through the operand. They
include rcl (rotate through carry left), rcr (rotate through carry right), rol (rotate left), and ror
(rotate right). These instructions all take the forms

rcl dest, count


rol dest, count
rcr dest, count
ror dest, count
The specific forms are
rcl reg, 1
rcl mem, 1
rcl reg, imm (2)
rcl mem, imm (2)
rcl reg, cl
rcl mem, cl
rol,rcr,ror uses the same formats as rcl.
4- AND src,dest: logical AND
The 80x86 logical instructions operate on a bit-by-bit basis. Both eight, sixteen, and thirty-
two bit versions of each instruction exist. The and, not, or, and xor instructions do the
following:
and dest, source ;dest := dest and source
or dest, source ;dest := dest or source
xor dest, source ;dest := dest xor source
not dest ;dest := not dest
The specific variations are
and reg, reg
and mem, reg
and reg, mem
and reg, immediate data
and mem, immediate data
and eax/ax/al, immediate data
or uses the same formats as AND
xor uses the same formats as AND
not register
not mem
Except not, these instructions affect the flags as follows:
• They clear the carry flag.
• They clear the overflow flag.
• They set the zero flag if the result is zero, they clear it otherwise.
• They copy the H.O. bit of the result into the sign flag.
• They set the parity flag according to the parity (number of one bits) in the result.
• They scramble the auxiliary carry flag.
The not instruction does not affect any flags.

Assembly Program
MOV CX, 0009H;
MOV BX, 0000h
L1:
MOV SI, 1200h; equivalent to LEA SI, vect1
MOV AL, [BX+SI];
MOV SI, 1220h; equivalent to LEA SI, vect2
ADD AL, [BX+SI];
DAA;
MOV DI, 1300H; equivalent to LEA DI, vect3
MOV [BX+DI] AL;

MOV DL, AL; store the value


AND AL, 0F0H; Mask high secion
ROR AL, 01H; shift down high section
ROR AL, 01H; shift down high section
ROR AL, 01H; shift down high section
ROR AL, 01H; shift down high section
MOV DH, 0AH;
MUL DH; Multiply high section by 10
AND DL, 0FH; Mask Low section
ADD AL, DL;

MOV DI, 1320H; equivalent to LEA DI, vect4


MOV [BX+DI] AL;
INC BX;
LOOP L1; equivalent to CX--, if CL>0 goto L1
INT 3;
Procedure

1- Connect the Kit to 101 PS/2 Keyboard


2- Press SB 1200 to enter sub byte mode starting from memory 1200 in the data segment
3- Insert the bytes of vector v1
4- Repeat steps 2,3 for vector v2 in location 1220;
5- Press A followed by Enter
6- Start Address is: 1000
7- Write the program line by line followed by enter [Write down the memory locations for
correspondent to L1 and use it in Loop instruction]
8- Press (.) to return to the Main screen
9- Write GO 1000 followed by Enter. The Program should end with BRK PT (Break point)
10- In result sheet draw a table of data in vectors 1200, 1220, 1300, 1320;

Discussion:

1- The program in this experiment did not treat the case of adding 52 and 71 correctly. Do the
required to fix this issue and rewrite the program and test it using emu8086 software;
2- Discuss result of adding 99 to 61.

You might also like