Fixed Point Arithmetic and Packed Decimal Format: IBM S/370 Implementation - Prof. Edward , Study notes of Computer Architecture and Organization

The concept of fixed point arithmetic and its implementation using the packed decimal format on ibm s/370 mainframes. Topics include a review of ibm s/370 floating point formats, precision requirements for business and scientific applications, and an overview of the packed decimal format. The document also covers the encoding of decimal digits, zoned decimal data, and packed decimal data.

Typology: Study notes

Pre 2010

Uploaded on 08/04/2009

koofers-user-4yr
koofers-user-4yr 🇺🇸

3

(1)

10 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Fixed Point Arithmetic and the Packed Decimal Format
This set of lectures discusses the idea of fixed point arithmetic and
its implementation by Packed Decimal Format on the IBM Mainframes.
The topics include
1. A review of IBM S/370 floating point formats, focusing on
the precision with which real numbers can be stored.
2. The difference between the precision requirements of business
applications and those of scientific applications.
3. An overview of the Packed Decimal format, as implemented
on the IBM S/370 and predecessors.
We begin with a review of IBM notation for denoting bit numbers
in a byte or word. From our viewpoint, it is a bit non–standard.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Fixed Point Arithmetic and Packed Decimal Format: IBM S/370 Implementation - Prof. Edward and more Study notes Computer Architecture and Organization in PDF only on Docsity!

Fixed Point Arithmetic and the Packed Decimal Format

This set of lectures discusses the idea of fixed point arithmetic and

its implementation by Packed Decimal Format on the IBM Mainframes.

The topics include

1. A review of IBM S/370 floating point formats, focusing on

the precision with which real numbers can be stored.

2. The difference between the precision requirements of business

applications and those of scientific applications.

3. An overview of the Packed Decimal format, as implemented

on the IBM S/370 and predecessors.

We begin with a review of IBM notation for denoting bit numbers

in a byte or word. From our viewpoint, it is a bit non–standard.

IBM S/370: Terminology and Notation The IBM 370 is a byte–addressable machine; each byte has a unique address. The standard storage sizes on the IBM 370 are byte, halfword, and fullword. Byte 8 binary bits Halfword 16 binary bits 2 bytes Fullword 32 binary bits 4 bytes. In IBM terminology, the leftmost bit is bit zero, so we have the following. Byte 0 1 2 3 4 5 6 7 Halfword 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Fullword 0 – 7 8 – 15 16 – 23 24 – 31 Comment: The IBM 370 seems to be a “big endian” machine.

Precision Example: Slightly Exaggerated Consider a banking problem. Banks lend each other money overnight. At 3% annual interest, the overnight interest on $1,000,000 is $40.492. Suppose my bank lends your bank $10,000,000 (ten million). You owe me $404.92 in interest; $10,000,404.92 in total. With seven significant digits, the amount might be calculated as $10,000,400. My bank loses $4.92. I want my books to balance to the penny. I do not like floating point arithmetic. TRUE STORY When DEC (the Digital Equipment Corporation) was marketing their PDP– to a large New York bank, it supported integer and floating point arithmetic. At this time, the PDP–11 did not support decimal arithmetic. The bank told DEC something like this: “Add decimal arithmetic and we shall buy a few thousand. Without it – no sale.” What do you think that DEC did?

Precision Example: Weather Modeling Suppose a weather model that relies on three data to describe each point.

  1. The temperature in Kelvins. Possible values are 200 K to 350 K.
  2. The pressure in millibars. Typical values are around 1000.
  3. The percent humidity. Possible ranges are 0.00 through 1.00 (100%). Consider the errors associated with single precision floating point arithmetic. The values are precise to 1 part in 10 7 . The maximum temperature errors resulting at any step in the calculation would be: 3.5 10

Kelvins 1.0 10

millibars 1.0 10

percent in humidity.

As cumulative errors tend to cancel each other out, it is hard to imagine

the cumulated error in the computation of any of these values

as becoming significant to the result.

Example: A weather prediction accurate to 1 Kelvin is considered excellent.

Zoned Decimal Data

Remember that all textual data in computing are input and output

as character codes. IBM S/370 uses 8–bit EBCDIC to represent characters.

On input, these character codes are immediately converted to Zoned Decimal

format, which uses 8–bit (one byte) codes to represent each digit. With a

slight exception, it is identical to EBCDIC.

Here are the EBCDIC representations of each digit, shown as 2 hex digits.

Digit Code Digit Code

Hex Binary Hex Binary

0 F0 1111 0000 5 F5 1111 0101

1 F1 1111 0001 6 F6 1111 0110

2 F2 1111 0010 7 F7 1111 0111

3 F3 1111 0011 8 F8 1111 1000

4 F4 1111 0100 9 F9 1111 1001

Packed Decimal Data

Packed decimal representation makes use of the fact that only four

binary bits are required to represent any decimal digit.

Numbers can be packed , two digits to a byte.

How do we represent signed numbers in this representation?

The answer is that we must include a sign “half byte”.

The IBM format for packed decimal allows for an arbitrary number

of digits in each number stored. The range is from 1 to 31, inclusive.

After adding the sign “half byte”, the number of hexadecimal digits

used to represent any number ranges from 2 through 32.

Numbers with an odd digit count are converted to proper format by

the addition of a leading zero; 123 becomes 0123.

The system must allocate an integral number of bytes to store each datum,

so each number stored in Packed Decimal format must have

an odd number of digits.

Zoned Decimal Data The zoned decimal format is a modification of the EBCDIC format. The zoned decimal format seems to be a modification to facilitate processing decimal strings of variable length. The length of zoned data may be from 1 to 16 digits, stored in 1 to 16 bytes. We have the address of the first byte for the decimal data, but need some “tag” to denote the last (rightmost) byte. The assembler places a “sign zone” for the rightmost byte of the zoned data. The common standard is X’C’ for non–negative numbers, and X’D’ for negative numbers. The format is used for constants possibly containing a decimal point, but it does not store the decimal point. As an example, we consider the string “–123.45”. Note that the format requires one byte per digit stored.

Creating the Zoned Representation Here is how the assembler generates the zoned decimal format. Consider the string “–123.45”. The EBCDIC character representation is as follows. Character – 1 2 3. 4 5 Code 6D F1 F2 F3 4B F4 F The decimal point (code 4B) is not stored. A bit later we shall see the reason for this. The sign character is implicitly stored in the rightmost digit. The zoned data representation is as follows. 1 2 3 4 5 F1 F2 F3 F4 D The string “F1 F2 F3 F4 C5” would indicate a positive number, with digits “12345”.

Example: Addition of Two Packed Decimal Values

Consider two integer values , stored in packed decimal format.

Note that 32–bit two’s complement representation would limit the integer

to a bit more than nine digits: –2, 147, 483, 648 through 2, 147, 483, 647.

Integers stored as packed decimals can have 31 digits and vary between

–9, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999 and

30

Consider the addition of the numbers –97 and 12,541.

–97 would be expanded to –097 and stored as 097D.

12,541 would be stored as 12541C.

The CPU does what we would do. It first pads the smaller number with 0’s.

00097D

12541C

It then performs the operation, denoted as “12541 – 97”, and stores the

result as 12444, or 12444C in packed decimal format.

Fixed Point: Where is the Decimal Point?

Consider the following addition problem: 1.23 + 10.11405.

The answer is obviously 11.34405.

But the Packed Decimal format does not store the decimal point, so

1.23 is stored as 123C and 10.11405 is stored as 1011405C.

Using our previous logic, we line up the numbers 0000123C

1011405C

The result is denoted 10111528C , which might be 10.111528.

It cannot represent the correct answer.

This is a “feature” of fixed point arithmetic , in which all numbers are stored

with the decimal point in the same place. In this system, the code must

guarantee that 1.23 is stored as 0123000C.

The result is now 0123000C

1011405C, stored as 1134405C.

The code must interpret and output this as the value 11.34405.