Sunteți pe pagina 1din 5

Program of conversion of packed BCD to

unpacked BCD
Rajveer Jain Information
Technology Department Shah
And Anchor Kutchhi Engineering
College, Mumbai, India
rajveerjain20@gmail.com
mplement on BCD codes. Scaling by a factor of 10 (or
power of 10) is simple; this is useful when a decimal
Abstract- ​In this paper, we discuss the caling factor is needed to represent a non-integer
conversion of packed BCD to unpacked BCD. uantity. It is very similar to decimal system. We need
o remember binary equivalents of decimal number 0
The meaning of packed BCD and unpacked BCD iso 9 only.
also been discussed. How does the conversion takes Disadvantages: The addition and subtraction of BCD
place is described in this paper. have different rules. The BCD arithmetic is more
complicated. BCD needs more number of bits than
Introduction on about BCD, its applications , binary to represent the same decimal number. So BCD
advantages and disadvantages. is less efficient than binary.

Keywords- ​BCD, packed BCD, unpacked BCD, Types of BCD:


registers, binary.
Basically there two types of BCD, packed
1. I​NTRODUCTION ​WHAT IS BCD and unpacked BCD.
BCD? BCD is the short form of Binary Coded Decimal. In
this code each decimal is represented by 4-bit binary [What is packed BCD?
number. The term packed BCD means the BCD number
Thus BCD is a way to express each of the corresponding to decimal numbers beyond 9 are called
decimal digits with a binary code. as packed BCD.

Also the positional weights are associated to the binary 1) In packed BCD (or simply packed decimal), each of
bits in BCD. This weights are 8-4-2-1, these generally the two nibbles of each byte represent a decimal digit.
are 2^3, 2^2, 2^1,2^0 which are same as in normal 2) The packed BCD is been used since at least the
binary system. E.g.: Decimal no 2 is represented as 1960s and is implemented in all IBM mainframe
0010, hardware since then. 3) Most implementations are big
ending, i.e. with the more significant digit in the upper
Decimal no 12 is represented as 0001 0010.
half of each byte, and with the leftmost byte (residing
at the lowest memory address) containing the most
Advantages: Encoding and Decoding into BCD is easy . significant digits of the packed decimal value. 4)
Lower nibble of the rightmost byte is usually used as
Hardware Algorithms (procedures) are easy to
the sign flag, although some unsigned representations 12 34.56 7+
lack a sign flag. 5) For example, 4-byte value consists
of 8 nibbles, wherein the upper 7 nibbles store the he decimal point is not actually
digits of a 7-digit decimal value and the lowest nibbletored in memory, as the packed BCD
indicates the sign of the decimal integer value. 6) torage format does not provide for
Some standard sign values are 1100 (hex C) t. Its location is simply known to
for positive (+) and 1101 (D) for he compiler and the generated code
negative (-). cts accordingly for the various
rithmetic operations.

XXX-X-XXXX-XXXX-X/XX/$XX.00 ©20XX IEEE ) Higher-density encodings:


7) Such conventions comes from the zone field EBCDIC If a decimal digit
characters and the signed overpunch requires four bits, then three decimal
representation. 8) Some other allowed signs are digits require 12 bits. However, since
1010 (A) and 1110 (E) for positive and 1011 (B) for 210 (1,024) is greater than 103
negative. 9) IBM system/ 360 processor will use the (1,000), if three decimal digits are
1010 encoded together, only 10 bits are
needed. Two such encodings are Chen–Ho
(A) And the 1011(B) signs if the A bit is set in the psw,for
encoding and densely packed decimal
the ASCII-8 standard that never passed. 10) In packed
(DPD). The latter has the advantage
BCD, the number 127 is represented by 0001 0010 0111
that subsets of the encoding encode
1100 (127C) and -127 is represented by 0001 0010 0111
two digits in the optimal seven bits
1101 (127D). ​Sign BCD Sign Notes digit ​A 1 0 1 0
and one digit in four bits, as in
+ B 1 0 1 1 - C 1 1 0 0 + Preferred D
regular BCD. E.g. for packed BCD is:
1 1 0 1 - Preferred E 1 1 1 0 + F 1 1
Decimal: 9 1 Binary : 1001 0001
1 1 + Unsigned

A) Fixed-point packed decimal:


What is Unpacked BCD? >>Unpacked
Fixed-point
BCD: ​The term unpacked BCD means each
decimal numbers are supported by some
number is encoded in to one byte with
programming languages (such as COBOL,
four bits representing the number and
PL/I and Ada).
the other four are of no use for a
These languages allow the single BCD digit. The number 75 in
programmer to specify an implicit unpacked BCD would be 00000111 and
decimal point in front of one of the 00000101. UN-Packed puts one BCD
digits. For example, a packed decimal nibble into one 8 bit word leaving 4
value encoded with the bytes 12 34 56 bits unused. ... Packed BCD ( Binary
7C represents the fixed-point value coded decimal) is type in which each
+1,234.567 when the implied decimal decimal digit is represented by 4
point is located between the 4th and bits. E.g. Decimal: 9 1
5th digits:
Binary:0000 1001 0000
0001]R1
12 34 56 7C
ov AX,data
mov DS,AX xor
Algorithm for conversion of AX,AX mov
AL,packbcd mov
Packed BCD to Unpacked BCD​:
DL,AL and
[Step I : Initialize the data memory.
AL,0F0H mov CL,4
Step II : Load number into register
ror AL,CL mov BH,AL and
AL. Step III : Mask the lower nibble.
DL,0FH mov BL,DL mov
Step IV : Rotate 4 times left to make
unpackbcd,BX mov AH,4ch
; MSB digit = int 03H code ends end
LSB. Step V : Display the digit. start]R3
Step VI : Load number in AL. Step VII
: Mask upper nibble. Step VIII : OUTPUT: ​Unpacked BCD is 05h 0Ah
Display the result Step IX : Stop.]R4

Working of program:
Flow-Chart for Algorithm:
Steps- (Note: this
[ START | ​v Load
​ packed bcd program is for 8-bits)
number in AL
1) In data segment of
| ​v Mask
​ lower bcd digit | ​V Rotate
​ 4 code,variables are initialised with
times to left to make MSB= LSB the variables. 2) In code segment

| ​v Display ​ ​Load
result | v the data in the variables is moved

to ax register. 3) From ax register
original number back in AL
it is moved to data segment. 4) The
| ​v Mask
​ upper bcd digit | ​v Display
​ value in packbcd is load in to AL
register. 5) This value is now
Program
result | ​v Stop ]R4 ​
copied from AL to DL. 6) After the
for Conversion of above step, we perform ‘and’
operation with AL and 0F0H value to
Packed BCD to Unpacked obtain one unpacked bcd value. 7)
BCD: In the next step,value 4 is loaded
in counter register(CL). 8) In this
a rotary operation is performed 4
[Assume cs:code segment,ds:data
times between AL and CL register in
segment data segment
which the bits in AL register is
packbcd db 5Ah unpackbcd
masked meaning MSB is made equal to
dw 0 data ends
LSB. 9) This masked value in store
code segment start: in BH register. 10) In this
step,’and’ operation is between DL
register and 0Fh value to get
When storing a string of alphanumeric
another unpacked bcd value. 11) And
in the last step,the int 03h means haracters – all operations will be in bytes
the terminating step. nly.
A. ​Abbreviations and Acronyms
he code segment starts with .startup and
cs: code segment register nds with .exit. If .startup is missing –
ds: data segment register egment registers will not be initialized.
MSB: most significant bit
Macro is defined before .code and .startup.
LSB: least significant bit

Ror: rotate bits as per specification (in this When using string instructions the source
program we have rotated the bits 4 times) ddress is always a combo of ds:si and
Mov: to copy data or byte from source to estination is always es:di.
destination
tack is usually initialized as word not bytes - as
tack transfer is usually in words.]R2
​ b:
B. ​Equations & Symbols d
D. ​Applications and implementation
data byte(8-bit) dw: data
word(16-bit) AX: accumulator It's use lies in places where alphanumeric characters
register AL: accumulator ranging from (0-9 and A-F) are to be displayed ,
register CL: counter register especially in systems consisting solely of digital logic
BH: base register DL: data and not containing a microprocessor. BCD is a
register convention for representing decimal data digitally and
was traditionally used in finance (e.g. payroll and tax
C. S
​ ome Common Mistakes processing), particularly on IBM mainframes.

[Keep the name of the file short and less than 8


characters if not then the assembler will throw E. ​Identify the Headings
an exception of file not found. This paper takes into consideration the Micro
processor language topics such as packed BCD and
Save the file using all file type option or better unpacked BCD and their conversion.
use notepad++ which allows to save the file as
The respective algorithm, flowchart and program
an asm file.
are given for better, easy and simpler understanding of the
entire conversion.
Depending on the size of data(8-bits/16-bits) the
data should be saved and transferred from 2. A​CKNOWLEDGMENT ​1. Jonathon Bartlett, thank you
memory to an 8/16 bits register accordingly and for your book Programming from the ground up which
also pointer increment and decrement needs to made to understand the assembly language program . 2.
be done​. Schneider,Hans-Jochen, thank you for your information
on lexicon of computer science and data processing . 3. Bartlett,(2009-09-24) “Programming
Tata ​Mc Graw HILL​, thank you for your theory book on from the Gound Up”, ISBN-10: 1616100648
microprocessor. 4. Tafel, Hans Jorg, thank you for ISBN-13: 978-1616100643.
providing with information on on Digital information [10]R2=https://edge.edx.org/courses/course-v1:BITSX
processing through which ALP was understandable. +F241+2015-16_Semester_II/5558377261dd42f19
d7664e8a4b9688b/.
3. R​EFERENCES
[11]R3=https://www.coursehero.com/file/p3f044l/7-W
rite-an-Assembly-Language-Program-ALP-to-con
[1] ​R1=
vert-a-packed-BCD-number-to/.
https://en.wikipedia.org/wiki/Binary-coded_decim al. ​[2]
Schneider, Hans-Jochen (1986). Lexikon der Informatik
und Datenverarbeitung (in German) (2 ed.). R. Oldenbourg [12]R4=https://projectsgeek.com/2011/05/unpack-the-
Verlag München Wien. ISBN 3-486-22662-2. [​ 3] ​Tafel, packed-bcd-number-code.html
Hans Jörg (1971). Written at RWTH, Aachen, Germany.
Einführung in die digitale Datenverarbeitung [Introduction
to digital information processing] (in German). Munich,
Germany: Carl Hanser Verlag. ISBN 3-446-10569-7. ​[4]
Steinbuch, Karl W.; Weber, Wolfgang; Heinemann,
Traute, eds. (1974) [1967]. Taschenbuch der Informatik -
Band II - Struktur und Programmierung von
EDV-Systemen. Taschenbuch der
Nachrichtenverarbeitung (in
German). 2 (3 ed.). Berlin, Germany: Springer-Verlag.
ISBN 3-540-06241-6. LCCN 73-80607. [​ 5] ​Tietze, Ulrich;
Schenk, Christoph (2012-12-26). Advanced Electronic
Circuits. Springer Science & Business Media. ISBN
3642812414. 9783642812415. Retrieved 2019-03-29.. [6]
https://books.google.co.in/books?id=Q-1bEe-RTb
wC&pg=SA4-PA6&lpg=SA4-PA6&dq=mistakes+
while+typing+program+for+conversion+of+packe
d+bcd+to+unpacked+bcd&source=bl&ots=iglmkn
Fvkr&sig=ACfU3U2v0MNAy3WCqdUJDl-0wE0
O4HufBw&hl=en&sa=X&ved=2ahUKEwjprafnqq
bhAhUL8XMBHXMgCdoQ6AEwAHoECAgQA
Q#v=onepage&q&f=false.

[7]
https://edge.edx.org/courses/course-v1:BITSX+F2
41+2019-16_Semester_II/5558377261dd42f19d76
64e8a4b9688b/.
[8] www.tatamcgrawhill.com [9] Jonathan

S-ar putea să vă placă și