Convert ascii code to its bcd equivalent, Computer Engineering

Assignment Help:

Convert ASCII code to its BCD equivalent. This can be achieved by simply replacing bits in upper four bits of byte by four zeros. For illustration the ASCII '1' is 32h = 0010B. By making upper four bits as 0 we obtain 0000 0010 that is 2 in BCD. Number attained is known as unpacked BCD number. Upper 4 bits of this byte is zero. So upper four bits can be used to store another BCD digit. The byte so obtained is known as packed BCD number. For illustration an unpacked BCD number 59 is 00000101 00001001 which is 05 09. Packed BCD will be 0101 1001 which is 59.

The algorithm to convert two ASCII digits to packed BCD can be defined as:

Convert first ASCII digit to unpacked BCD.

Convert second ASCII digit to unpacked BCD.

1110_Convert ASCII code to its BCD equivalent.png

Move first BCD to upper four positions in byte.

702_Convert ASCII code to its BCD equivalent1.png

Pack two BCD bits in one byte.

506_Convert ASCII code to its BCD equivalent2.png

The assembly language program for the above can be written in the below manner.

 

; ABSTRACT                         Program produces a packed BCD byte from 2 ASCII 

                                                ; encoded digits. Assume the number as 59.

                                                ; The first ASCII digit (5) is loaded in BL.

                                                ; The second ASCII digit (9) is loaded in AL.

                                                ; The result (packed BCD) is left in AL.

; REGISTERS                        ; Uses CS, AL, BL, CL

; PORTS                                  ; None used

CODE    SEGMENT

            ASSUME                    CS:CODE

START:  MOV BL,                '5'; Load first ASCII digit in BL

   MOV AL,                            '9'; Load second ASCII digit in AL

   AND BL,                             0Fh; Mask upper 4 bits of first digit

   AND AL,                             0Fh; Mask upper 4 bits of second digit

   MOV CL,                            04h; Load CL for 4 rotates 

   ROL BL,                              CL; Rotate BL 4 bit positions

   OR AL,                                BL; Combine nibbles, result in AL contains 59 

                                                ; As packed BCD

CODE ENDS

END START

Discussion:

8086 doesn't have any instruction to swap lower and upper 4 bits in a byte so we need to use rotate instructions that too by 4 times. Out of two rotate instructions RCL and ROL we have chosen ROL as it rotates the byte left by one or more positions whereas RCL moves MSB into carry flag and brings original carry flag in the LSB position and that is not what we want.


Related Discussions:- Convert ascii code to its bcd equivalent

Flynns categorization, Flynn's Categorization Flynn's Categorization is...

Flynn's Categorization Flynn's Categorization is based on multiplicity of data streams and instruction streams observed by CPU at the time of program execution. Let I s and D

What is reducibility, What is reducibility?  The primary method of prov...

What is reducibility?  The primary method of proving some problems are computationally unsolvable.       It is known as reducibility. Reducibility always includes two problems

Computer graphics, explain area sub division method algorithm

explain area sub division method algorithm

Multiple valued logics, Multiple valued logics: Multiple valued logics...

Multiple valued logics: Multiple valued logics, where altered types of truth value such as "unknown" are may be allowed. These have some of the particular advantages of fuzzy

Define a variant of top-down parsing without backtracking, A parser which i...

A parser which is a variant of top-down parsing without backtracking is? Ans. Recursive Descend is a variant of top-down parsing without backtracking.

Write a program to read in a positive integer, Write a program to read in a...

Write a program to read in a positive integer and check whether it is prime or not? /* Program to check whether a given number is prime or not*/] # include # include

Find the magnetic declination, Question Use the National Geophysical Da...

Question Use the National Geophysical Data Center software tool to find the magnetic declination. The link to the web site is in Useful Links on the course Blackboard home page

Prints the hundreds digit in two integers , Write an application that prin...

Write an application that prints the hundreds digit  in two integers read from the keyboard. For example if the data values are 1456 and 255 respectably, output should include the

What are the counters, What are the Counters? 1. The Counter is a seque...

What are the Counters? 1. The Counter is a sequential circuit which consists of a set of flip flops connected in a appropriate manner to count the sequence of input pulses.

The number of control lines for a 8 – to – 1 multiplexer, What is the numbe...

What is the number of control lines for a 8 - to - 1 multiplexer ? Ans. There are 3 control lines, for an 8 to 1 Multiplexer. The control signals are utilized to steer any one

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd