Packed BCD To Unpacked BCD
Packed BCD To Unpacked BCD
Packed BCD To Unpacked BCD
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.
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.
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.
[7]
https://edge.edx.org/courses/course-v1:BITSX+F2
41+2019-16_Semester_II/5558377261dd42f19d76
64e8a4b9688b/.
[8] www.tatamcgrawhill.com [9] Jonathan