B2H Algorithm
B2H Algorithm
1. 2. 3. 4. 5. 6. 7. 8. 9.
Start. Display menu message to user. Get choice from user. If choice = 1 then perform BCD to HEX conversion. Call b2h procedure. If choice = 2 then perform HEX to BCD conversion. Call h2b procedure. If choice = 3 then exit from the given MENU. Stop.
Macros: 1. Name: disp 2. Purpose: Use macro to display the different messages 3. I/P: 09 function and 21H interrupt Procedures: h2b: 1. Name: HEX to BCD 2. Purpose: convert HEX no. into BCD. 3. I/P: 4 bit HEX number 4. Algorithm for Procedures i) Start ii) Get the 4-digit Hex number from the user. iii) Initialize 5 digit counter with initial value zero. iv) Check whether HEX no. is zero if yes go to step (viii). v) Decrement HEX no. by 1. vi) Add decimal 1 to counter. vii) Go to step (iv) viii) Display counter as BCD no. ix) Stop.
Procedures: b2h: 1. Name: BCD to HEX 2. Purpose: convert BCD no. into HEX. 3. I/P: 5 bit BCD number 4. Algorithm for Procedures i) Start ii) Get the 5-digit BCD number from the user. iii) Initialize 4 digit counter with initial value zero. iv) Check whether BCD no. is zero if yes go to step (viii). v) Subtract decimal 1 from BCD no. vi) Increment counter by 1. vii) Go to step (iv). viii) Display counter as HEX no. ix) Stop.