- 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
MIPS Assembly Language
Notes on Computer Organization and Design David Patterson
Wednesday, June 22, 2011
4.3 Addition and Substraction
Tuesday, June 21, 2011
4.2 Signed and Unsigned Numbers
- If the number that is the proper result of such operations cannot be represented by these rightmost hardware bits, overflow is said to have occurred.
- Sign and magnitude method and two's complement representation are used to distinguish positive and negative numbers
- Two's complement: leading 0s (MSB) mean positive and leading 1s (MSB) mean negative
- Shortcut to negate two's complement binary number: invert every 0 to 1 and every 1 to 0, then add one to result
Monday, June 20, 2011
Chapter 4: Arithmetic for Computers
- Representation of numbers (natural, negative, fractions, negative numbers)
- Arithmetic algorithms (its hardware)
Thursday, June 16, 2011
3.8 Other Styles of MIPS Addressing
- Two more ways of accessing operands
- Make it faster to access small constant
- Make branches more efficient
- Constant or Immediate Operands
- add instruction that has one constant operand is called add immediate or add i
- The MIPS field containing the constant is 16 bits long
- The op field for addi is 8
- Constant operands occur frequently, and by making constants part of arithmetic instructions, they are much faster than if they were loaded from memory
- Instruction load upper immediate (lui) specifically to set the upper 16 bits of a constant in a register, allowing a subsequent instruction to specify the lower 16 bits of the constant. ie lui $t0, 255
- Addressing in Branches and Jumps
- To allow program as large as 2^32, a branch instruction is calculate the following: Program counter = Register + Branch Address
- MIPS Addressing Mode:
- Register addressing: where the operand is a register
- Base addressing: where the operand is at the memory location whose address is the sum of a register and a constant in the instruction
- Immediate addressing: where the operand is a constant within the instruction itself
- PC-relative addressing: where the address is the sum of the PC and a constant in the instruction
- Pseudodirect addressing, where the jump address is the 26 bits of instruction concatenated with the upper bits of the PC
Wednesday, June 15, 2011
3.7 Beyond Numbers
- American Standard Code for Information Interchange (ASCII) uses 8-bit bytes(storage) to represent characters.
- ASCII code is 7 bits
- MIPS bytes-moving instructions: lb & sb
- Load bytes (lb) loads a byte from memory, placing it in the rightmost 8 bits of a register: lb $t0, 0($sp)
- Store bytes (sb) stores a byte from the rightmost 8 bits of a register to memory: sb $t0, 0($gp)
- Characters are normally combined into strings
- Three choices for representing a string:
- the first position of the string is reserved to give the length of a string
- Accompanying variable has the length of the string
- the last position of a string is indicated by a character used to mark the end of string (C language)
Tuesday, June 14, 2011
Monday, June 13, 2011
3.5 Instruction for Making Decision
- Conditional branch: beq, bne & slt
- Branch if equal: beq register1, register2, L1 - Goto statement L1 if register1 equal register2
- Branch if not equal: bne register1, register2, L1 - Goto statement L1 if register1 not equal register2
- Set on less: slt $t0, $s3, $s4 - $t0 is set to 1 if $s3 is less than $s4, otherwise $t0 is set to 0
- Unconditional jump: j & jr
- Jump: j 2500 - Jump to target address (10000)
- Jump register: jr $t1 - Goto $t1 (for switch statement)
Subscribe to:
Posts (Atom)