Wednesday, June 22, 2011

4.3 Addition and Substraction

  • Overflow occurs when adding two positive numbers and the sum is negative, or vice versa
  • Adding or subtracting two 32-bit numbers can yield a result that needs 33 bits to be fully expressed
  • The lack of 33 bits means that overflow occurs when the carry out occurred into the sign bit 
  • Unsigned integers are commonly used for memory addresses where overflows are ignored
  • Two kinds of arithmetic instruction to ignore overflow or not:
    • add. addi, sub cause exceptions on overflow
    • addu, addiu, subu do not cause exceptions on overflow
  • Because C ignores overflows, the MIPS C compilers will always generate unsigned version of arithmetic instructions (addu, addiu etc)
  • MIPS detects overflow with an exception/interrupt
  • An exception/interrupt is essentially an unscheduled procedure call
  • MIPS includes a register called the exception program counter (EPC) to contain the address of the instruction that caused the exception
  • The instruction move from system control (mfc0) is used to copy EPC into a general-purpose register so that MIPS software has the option of returning to the offending instruction via a jump register instruction  

No comments:

Post a Comment