Binary-coded decimal: Difference between revisions

Content deleted Content added
Rescuing 2 sources and tagging 0 as dead.) #IABot (v2.0.9.5
Other computers: elaborating on usage and hardware support
Line 714:
The Digital Equipment Corporation [[VAX]] series includes [[Instruction set|instructions]] that can perform arithmetic directly on packed BCD data and convert between packed BCD data and other integer representations.<ref name="DEC_1985_VAX11"/> The VAX's packed BCD format is compatible with that on IBM System/360 and IBM's later compatible processors. The MicroVAX and later VAX implementations dropped this ability from the CPU but retained code compatibility with earlier machines by implementing the missing instructions in an operating system-supplied software library. This is invoked automatically via [[exception handling]] when the defunct instructions are encountered, so that programs using them can execute without modification on the newer machines.
 
Many processors have hardware support for BCD-encoded integer arithmetic. For example the [[6502]]<ref>[http://www.masswerk.at/6502/6502_instruction_set.html 6502 Instruction Set] {{Webarchive|url=https://web.archive.org/web/20180508053805/http://www.masswerk.at/6502/6502_instruction_set.html |date=2018-05-08}}.</ref><ref>[http://www.6502.org/tutorials/6502opcodes.html NMOS 6502 Opcodes]. {{Webarchive|url=https://web.archive.org/web/20160114001557/http://www.6502.org/tutorials/6502opcodes.html |date=2016-01-14}}.</ref>, the [[Motorola 68000 series]],<ref name="Motorola_m68k"/> and the [[x86]] series.<ref>{{cite book|url= http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf|title= Intel 64 and IA-32 Architectures Software Developer's Manual Volume 1: Basic Architecture|at= Section 4.7|publisher= Intel|date= March 2013|access-date= April 23, 2013|archive-date= April 2, 2013|archive-url= https://web.archive.org/web/20130402233513/http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-1-manual.pdf|url-status= live}}</ref> The [[Intel]] x86 architecture supports a [[Intel BCD opcodes|unique 18-digit (ten-byte) BCD format]] that can be loaded into and stored from the floating point registers, from where computations can be performed.<ref name="Intel_2020_V1"/>
The [[Intel]] [[x86]] architecture supports a [[Intel BCD opcodes|unique 18-digit (ten-byte) BCD format]] that can be loaded into and stored from the floating point registers, from where computations can be performed.<ref name="Intel_2020_V1"/>
 
In more recent computers such capabilities are almost always implemented in software rather than the CPU's instruction set, but BCD numeric data are still extremely common in commercial and financial applications.
The [[Motorola 68000 series]] had BCD instructions.<ref name="Motorola_m68k"/>
 
In modern [[mobile telephony]], the telephone numbers dialed are sent in BCD format, as well as operator ID, [[International Mobile Equipment Identity|IMEI]], [[International mobile subscriber identity|IMSI]] (SUPI), et.c. They are sent as packed BCD-ecoded variable-length arrays terminated by 0xF.<ref>{{cite web|url=https://www.etsi.org/deliver/etsi_ts/124500_124599/124501/16.10.00_60/ts_124501v161000p.pdf|title=Non-Access-Stratum (NAS) protocol for 5G System (5GS); Stage 3. (3GPP TS 24.501 version 16.10.0 Release 16) TS 24.501 release 16.10.0|publisher=[[ETSI]] and [[3GPP]]|access-date=February 26, 2022|archive-date=February 17, 2022|archive-url=https://web.archive.org/web/20220217231615/https://www.etsi.org/deliver/etsi_ts/124500_124599/124501/16.10.00_60/ts_124501v161000p.pdf|url-status=live}} (TS 24.501)</ref><ref>{{cite web|url=https://www.etsi.org/deliver/etsi_ts/123000_123099/123003/16.08.00_60/ts_123003v160800p.pdf|title=Digital cellular telecommunications system (Phase 2+) (GSM); Universal Mobile Telecommunications System (UMTS); LTE; 5G; Numbering, addressing and identification (3GPP TS 23.003 version 16.8.0 Release 16)|publisher=[[ETSI]] and [[3GPP]]|access-date=February 26, 2022|archive-date=February 26, 2022|archive-url=https://web.archive.org/web/20220226144220/https://www.etsi.org/deliver/etsi_ts/123000_123099/123003/16.08.00_60/ts_123003v160800p.pdf|url-status=live}} (TS 23.003)</ref>
In more recent computers such capabilities are almost always implemented in software rather than the CPU's instruction set, but BCD numeric data are still extremely common in commercial and financial applications.
 
There are tricks for implementing packed BCD and zoned decimal add–or–subtract operations using short but difficult to understand sequences of word-parallel logic and binary arithmetic operations.<ref name="Jones_1999_AT" /> For example, the following code (written in [[C (programming language)|C]]) computes an unsigned 8-digit packed BCD addition using 32-bit binary operations: