Advanced Arithmetic - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Advanced Arithmetic

Description:

The 8086 integer operations are limited to 16-bits ... Remember they are stored in reverse byte format. mov ax,word ptr x. add ax,word ptr y ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 14
Provided by: timma87
Category:

less

Transcript and Presenter's Notes

Title: Advanced Arithmetic


1
Advanced Arithmetic
  • Assembly Language Programming
  • University of Akron
  • Dr. Tim Margush

2
Double-Precision Integers
  • The 8086 integer operations are limited to
    16-bits
  • If larger numbers are required (32, 64 bits), how
    do we handle the arithmetic?
  • Emulate the arithmetic operations
  • Provide additional hardware to perform arithmetic

3
32-Bit Emulation Add
  • To add two 32-bit numbers in memory
  • x dd 12345678h
  • y dd 98765432h
  • z dd ? result
  • Add low order words and store result
  • Remember they are stored in reverse byte format
  • mov ax,word ptr x
  • add ax,word ptr y
  • mov wordptr z,ax
  • The carry must be added to the sum of the
    high-order words
  • mov ax,word ptr x2
  • adc ax,word ptr y2
  • mov word ptr z2,ax

4
32-Bit Emulation Sub
  • To subtract two 32-bit numbers in memory
  • x dd 12345678h
  • y dd 98765432h
  • z dd ? result
  • Sub low order words and store result
  • Remember they are stored in reverse byte format
  • mov ax,word ptr x
  • sub ax,word ptr y
  • mov wordptr z,ax
  • The carry (borrow) must be added to the sum of
    the high-order words
  • mov ax,word ptr x2
  • sbb ax,word ptr y2
  • mov word ptr z2,ax

5
Flags
  • The flags will not reflect the result of the
    double-precision operation
  • SF, OF, and CF are correct after the second
    operation
  • If necessary, set the other flags manually
  • ZF is set if both words are zero
  • PF depends on parity of both words
  • AF is probably unnecessary to correct

6
Multiplication
  • 12345678h 98765432h
  • 5678h 5432h 1C704370h
  • 1234h 5432h 5FC9E28h
  • 5678h 9876h 337F1B50h
  • 1234h 9876h AD743F8h
  • 1C70 4370
  • 5FC 9E28
  • 337F 1B50
  • AD7 43F8
  • ----------------
  • 0AD7 7D73 D5E8 4370
  • If signed numbers are involved, suitable
    conversions should be performed

7
Converting Decimal Fractions
  • decimal fraction .ddddd to binary .bbbbb
  • Successive doubling of the fraction tells whether
    the next bit of the binary representation is 1 or
    0
  • if f 2gt1 then next bit is 1
  • if f 2 lt 1 then next bit is 0
  • We discard the whole part before the next doubling

8
Example Conversion
  • .24 2 0.48
  • .48 2 0.96
  • .96 2 1.92
  • .92 2 1.84
  • .84 2 1.68
  • .68 2 1.36
  • .36 2 0.72
  • .72 2 1.44
  • .44 2 0.88
  • .88 2 1.76
  • .76 2 1.52
  • .52 2 1.04
  • the process continues for as many bits as are
    desired
  • .001111010111...

9
Floating Point Representation
  • Mantissa
  • Significant digits of the number
  • Normalized if 1.bbbbbbbb...
  • Exponent
  • Specifies adjustment to the location of decimal
    (binary) point
  • Example 101.1101 with exponent 2 is the same as
    101110.1 with exponent -1

10
Encoding Floating Point Numbers
  • Sign and Magnitude
  • One bit in the code represents the sign of the
    number
  • The magnitude (expressed in normalized form) is
    encoded in the remaining bits
  • Exponent and Mantissa
  • The Exponent is translated using a biased code
    and stored in a field of the code
  • The Mantissa bits are stored in the remaining
    bits of the code

11
Short Real
s
exponent
mantissa
  • 32-bit floating point code
  • bit 31 is the sign bit (1 negative)
  • bits 30-23 hold the exponent
  • Exponents are biased by 127
  • Exponent range is -126 to 127
  • bits 22-0 the mantissa
  • The leading 1 is not stored.

12
Example Floating Point Conversion
  • 42.25 (decimal) converts to 101010.01b
  • Normalize 1.0101001 exponent 5
  • sign bit 0
  • exponent 10000100b (5127132)
  • mantissa 01010010000000000000000
  • leading 1 is dropped
  • 0100 0010 0010 1001 0000 0000 0000 0000
  • Hexadecimal 42290000h

13
Decoding Short Reals
  • 4372F10Ch
  • Assuming this is a Short Real, what decimal
    number does it represent?
  • Decode first 9 bits
  • 0 10000110
  • sign bit 0
  • Exponent code is 134
  • 134-1277 (exponent)
  • Mantissa is 1.11100101111000100001100
  • Move the binary point
  • 11110010.1111000100001100
  • 242.9415893555...
Write a Comment
User Comments (0)
About PowerShow.com