Sei sulla pagina 1di 2

Experiment No: Date: HEX TO BCD CONVERSIONAIM: To write an Assembly Language Program to convert a hexadecimal number to BCDusin g 8085

APPARATUS REQUIRED: (i) 8085 Microprocessor kit with keyboard.(ii) Power cable. ALGORITHM Step 1: Initialize memory pointer with 4300H Step 2: Get the hexadecimal number in C-reg Step 3: Perform repeated addition for C number of times Step4: Adjust for BCD in each step Step5: Store the BCD number in the memory location Step6: Stop the process Stop FLOWCHART StartInitialize memory pointer with 4300HGet the hexadecimal number in C-regAdju st for BCD in each step & Perform repeated addition for C number of timesStore t he BCD number in the memory location PROGRAM: LABEL ADDRESS MNEMONIC OPCODE OPERAND COMMENTSSTART: 4100H LXI H,4300H4103H MOV A,M Initialize memory pointer4104H ADD A MSD *24105H MOV B,A Store MSB *24106H ADD A MSB *44107H ADD A MSB *84108H ADD B MSB *104109H INX H Point to LSB410AH ADD M Add to form hex410BH INX H410CH MOV M,A Store the result410DH HLT Stop the process RESULT: Thus the Assembly Language Program to convert hexadecimal number to BCD.had been written and executed & the results were stored in desired memory location. OBSERVATION: ADDRESS DATA COMMENTSINPUTOUTPUTVIVA VOCE QUESTIONS1. Define stack 2. What is program counter? How is it useful in program execution? 3. How the microprocessor is synchronized with peripherals? 4. What is a minimum system and how it is formed in 8085? 5. Define bit, byte and word.

Converting Hex to BCD sounds simple, but I've been trying to figure this out for hours without much to show for the effort (a search didn't reveal anything very helpful either). I'm trying to convert a Hex number to a BCD number in Assembly, programming a Mo torola M68HC12 microcontroller. (I need the BCD for outputting a 2-digit number to a pair of 7-segment LED displays connected to one of the ports). Hex to BCD i s easy if I do it, but trying to get the HC-12 to do it is another matter. Probl em is that the starting number, calculations, and result all have to be in hex. The output number has to look like BCD while actually being hex. For example: (starting number) (convert to) 00h 00h 05h 05h 0Ah 10h 0Fh 15h 14h 20h 19h 25h 1Eh 30h ... This only has to work on the numbers 0 through 59. Trying multiple ideas and sub routines, I managed to come up with one that works on numbers from (0-39), (42-4 7) but other numbers are messed up (obviously a faulty algorithm). I feel that I 'm missing something obvious here, but can't think what it might be. The algorithim that works on some numbers (so you can see what direction my thou ghts have been taking): seperate 2 hex digits (take upper and lower nibble of byte) if lower > 9 add 6 to it multiply higher by 16 add 2 togeather decimal adjust answer Decimal Adjust (op code daa) is meant to be used after adding 2 BCD numbers toge ather, so I'm not supposed to be using it in this case. Probably why it only "al most" works. Any help would be appreciated. If I can't figure this out I'll have to give up a nd write the program the easy way (store number in BCD to start with and use daa after each add/subtract operation).

Potrebbero piacerti anche