6 Hextobcd MPL
6 Hextobcd MPL
Experiments No:6
Name of Student……………………………………………….. Roll No.:…… Batch:…….
4 4 4 4 4 20
Problem Statement: Write X86/64 ALP to convert 4-digit Hex number into its equivalent BCD
number and 5-digit BCD number into its equivalent HEX number. Make your program user
friendly to accept the choice from user for: (a) HEX to BCD b) BCD to HEX (c) EXIT.Display
proper strings to prompt the user while accepting the input and displaying the result. (Wherever
necessary, use 64-bit registers).
Hardware Requirement: NA
Theory Contents :
These directives instruct the assembler as to how large the various segment (code,
data, stack, etc) can be and what sort of segmentation register will be required.
.MODEL
<model >
Where <model>is one of the following options:
Tiny- code and data fit into single 64k and accessed via near pointers.
Small- code and segment both less than 64k and accessed via near pointers. Compact –
Code segment is <64K (near ptr) and data segment is <1MB (far ptr ) Medium- Code
segment is <1Mb (far ptr) and data segment is <64K (near ptr) Large- code and data
segment both less than 1MB and accessed via far pointers. Huge- Like “large” model, but
also permits arrays larger then 64K
Segment directives
These directives indicate to assembler the order in which to load segment. When it
encounter one of these directives, it interprets all subsequent instructor as belonging to the
indicated segment (until the ne xt directives is encounter).
. data
.stack <size>; specified .code
As has been previously discu ssed, data can be of several different lengths and assembler must be
able to decide what length a specific constant (or variable) is. This can be down using data type
declaration in conjunction with a constant declaration or variable assignment .this is akin to strong
typing of variable in high level language .the data types are:
Byte (8 bit quantity)—synonyms are byte and db
Word (16) -- synonyms are word dw
Dword (32bit) -- synonyms are dword and dd
Qword (64bit) -- synonyms with dq
Tword (128bit) -- synonyms with dt An
example of their use is:
MOV AX, word VAR; moves a 16-bit Variable VAR into AX
2. Instruction Used:
1. PUSH:-Push word onto stack.
2. POP:-Pop word off stack.
3. DIV:-Divide byte/word
4. XOR: - Exclusive or byte/word
5. JA/JNBE:-Jump if above/not below or equal
6. JB/JNAE:-Jump if below /not above or equal
7. JG/JNLE:-Jump if /not less nor equal
8. JL/JNGE:-Jump if less /not greater nor equal
9. INT:-It allows ISR to be activated by programmer & external H\W device
5.Algorithm:
HEX to BCD
1. Define variable on data segment.
2. Display message on screen ENTER 4-DIGIT HEX NO.
3. Accept BCD NO from user.
4. Transfer 0AH as a divisor in one of the register.
5. Divide the no by 0AH
6. PUSH reminder in one of the register
BCD to HEX
1. Define variables in data segment
2. Display message on screen ENTER 5-DIGIT BCD NO.
3. Accept single digit from user
4. Transfer 10000 to multiplier
5. Multiply accepted BCD digit by multiplier & add it to RESULT variable.
6. Accept single digit from user
7. Transfer 1000 to multiplier
8. Multiply accepted BCD digit by Multiplier & Add it to RESULT variable.
9. Accept single digit from user
10. Transfer 100 to multiplier
11. Multiply accepted BCD digit by Multiplier & Add it to RESULT variable.
12. Accept single digit from user
13. Transfer 10 to multiplier
14. Multiply accepted BCD digit by multiplier & add it to RESULT variable.
15. Accept single digit from user
16. Transfer 1 to multiplier
17. Multiply accepted BCD digit by multiplier & add it to RESULT variable.
18. Display result by calling display procedure
19. Stop.
a. Compare its ASCII with 30H if No is less than 0 (i.e case of -ve no given) then go to
step f else go to step c.
b. Compare its ASCII with 39H if No is greater than 9 (i.e case of character A – F given)
SNJB’s LS KBJ COE Chandwad
Department of Computer Engineering Microprocessor Laboratory (2019 course)
d. Check whether four digits (16-bit number) or two digits (8-bit number) are read; if yes
then go to display procedure else go to step 1 for next bit
e. Till counter is zero go to accept procedure.
f. Display massage “I/P is invalid BCD number” & go to step 17.
3. End of accept procedure.
HEX to BCD
and we are pushing Reminder on stack and then printing it in reverse order
BCD to HEX
Hence final result is in EAX = 65535 which is 1111 1111 1111 1111 and when we print this it is
represented as FFFF
Assignment Questions:
1. Explain various addressing modes of 8086 microprocessor used in this program.
2. Explain Different assembler directives used in this program.
3. Explain various Number Systems used in Digital Electronics.
4. What is HEX Number? Explain the s teps to convert HEX No to BCD No
5. What is BCD Number? Explain the steps to convert BCD No to HEX No.
Conclusion:In this way we studied about hex to bcd and hex to BCD number conversion.
Sign of Student