Sunday, November 24, 2013

Operations on integers



1. Addition and subtraction


Operand
Overflow

Addition
Subtraction
+ve , -ve
no
no
+ve , +ve
If result sign is 1
If result sign is 0
-ve , -ve
If result sign is 0
If result sign is 1

Example:  5 + 4

+5 :  0000 0000 … 0000 0101
+4 :  0000 0000 … 0000 0100
+9 :  0000 0000 … 0000 1001
           
Thus, when adding two positive operand with sign result sign is 1 = overflow.

Example:  5 + (-4)

+5 :  0000 0000 … 0000 0101
-4  :  1111 1111… 1111 1100
+1 :  0000 0000 … 0000 0001

Thus, when adding a positive and a negative  operand = not overflow.

Example:  5 (+4)

+5 :  0000 0000 … 0000 0101
+4 :  0000 0000 … 0000 0100
+1 :  0000 0000 … 0000 0001
           
Thus, when subtracting two positive operand with sign result sign is 0 = overflow.


2. Dealing with overflow

      I.        Some languages (e.g., C) ignore overflow
·         Use MIPS addu, addui, subu instructions
    II.        Other languages (e.g., Ada, Fortran) require raising an exception
·         Use MIPS add, addi, sub instructions
·         On overflow, invoke exception handler
-       Save PC in exception program counter (EPC) register
-       Jump to predefined handler address
-        mfc0 (move from system control) instruction can retrieve EPC value,
           to return after corrective action

3.Arithmetic for Multimedia

       I.        Graphics and media processing operates on vectors of 8-bit and 16-bit data
·         Use 64-bit adder, with partitioned carry chain
·         Operate on 8×8-bit, 4×16-bit, or 2×32-bit vectors
·         SIMD (single-instruction, multiple-data)
-           
     II.        Saturating operations
·         On overflow, result is largest representable value
-       c.f. 2s-complement modulo arithmetic
·         E.g., clipping in audio, saturation in vide

4. Multiplication and division

# Multiplication

Binary multiplication is just a bunch of right shifts and adds

# Division

Division is just a bunch of quotient digit guesses and left shifts and subtracts dividend = quotient x divisor + remainder


Published by : 
Hafizah binti Ismail  B031310266


No comments:

Post a Comment

 

Copyright © 2013 | by BITS STUDENT SIG2