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  

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
    1. Make it faster to access small constant
    2. 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:
    1. the first position of the string is reserved to give the length of a string
    2. Accompanying variable has the length of the string
    3. the last position of a string is indicated by a character used to mark the end of string (C language) 

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)

Thursday, June 9, 2011

3.4 Representing Instructions in the Computer

  • In MIPS assembly language, registers $s0 to $s7 map onto registers 16 to 23, and registers $t0 to $t7 map onto registers 8 to15
  • ie. add $t0, $s1, $s2 : | 0 | 17 | 18 | 8 | 0 | 32 |
  • Each of the segments of an instruction is called a field
  • The first and last fields ( 0 & 32 ) tell the MIPS computer that this instruction performs addition
  • Fields in binary: | 000000 | 10001 | 10010 | 01000 | 00000 | 100000 |
  • MIPS fields: | op | rs | rt | rd | shamt | funct |
  • op: opcode, basic operation of instruction
  • rs: first register source operand
  • rt: second register source operand
  • rd: register destination operand, get the results of the operation
  • shamt: Shift amount
  • funct: Function. Selects specific variant of the operation in op field.
  • Instruction format : R-type (register) or I-type for data transfer instruction
  • I-type: | op | rs | rt | address |
  • address field is 16 bits

Wednesday, June 8, 2011

3.3 Operands of the Computer Hardware

  • Unlike high-level languages, the operands of arithmetic instruction cannot be any variables, they must be from a limited number of special locations called registers
  • Registers are the bricks of computer construction, for registers are primitives used in hardware design that are also visible to the programmer when the computer is completed
  • 32 bits are named word in MIPS architecture (32 bit)
  • One major difference between the variables of a programming language and registers is the limited number of registers, typically 32. (MIPS has 32 registers)
  • A very large number of registers would increase clock cycle time simply because it takes electronic signals longer when they must travel farther
  • MIPS convention is to use two character name following a dollar sign to represent a register. ie $s0, $s1
  • Processor can keep only a small amount of data in registers, but computer memory contains million of data elements
  • Hence complex data structures, such as arrays, are kept in memory
  • Arithmetic operations occur only on registers in MIPS instructions
  • Data transfer instructions are instructions that transfer data between memory and registers (traditionally called load)
  • To access a word in memory, the instruction must supply the memory address
  • Memory is a large, single-dimensional array with the address acting as the index to that array, starting at 0
  • The actual MIPS name for data transfer instruction is lw, standing for load word. ie lw  $t0, 8($s3)
  • The constant in a data transfer instruction is called the offset, and the register added to form the address is called the base register
  • Most architectures address individual bytes - address of sequential words differ by 4
  • Words must always start at addresses that are multiples of 4 in MIPS (alignment restriction)
  • The instruction complementary to load is traditionally called store (transfer data from a register to memory) 
  • The actual MIPS name is sw, standing for store word
  • The process of putting less commonly used variables into memory is called spilling registers

3.2 Operations of the Computer Hardware

  • MIPS assembly language notation: add a, b, c
  • The notation instructs a computer to add the two variables b and c and put their sum in a
  • Each line of the language can contain at most one instruction
  • Comments always terminate at the end of a line
  • Subtract: sub a, b, c

Chapter 3 Instructions: Language of the Machine

  • The words of a machine's language are called instructions
  • MIPS instruction set (machine language) will be introduced

Tuesday, June 7, 2011

2.3 Relating the Metrics

  • Execution Time = (Instructions/Program) x (Clock Cycles/Instruction) x (Seconds/Clock Cycle)

2.2 Measuring performance

  • Time is the measure of computer performance
  • CPU time is the time CPU spent to compute particular task (not including I/O wait time etc)  

Chapter 2 The Role of Performance

  • Response/Execution time - the time between the start and completion of a task
  • Throughput - the total amount of work done in a given time

Monday, June 6, 2011

1.3 Under the Covers

  • The five classic components of a computer are input, output, memory, processor (datapath and control)
  • The memory is where the programs are kept when they are running; also contains the data needed by running programs
  • Datapath performs arithmetic operation
  • Control manages memory, I/O according to program's instruction
  • Two basic types of memories: DRAM and cache
  • RAM means memory accesses take the same amount of time no matter what portion of the memory is used
  • Cache memory consists of a small, fast memory that acts as a buffer to DRAM
  • The use of layers or abstractions is a principle technique for designing very sophisticated computer systems
  • Instruction set architecture is the abstraction for interface between hardware and lowest level software
  • Volatile memory loses data when it loses power - hold programs while they are running (Main or Primary Memory ie. DRAM)
  • Nonvolatile memory - store programs between runs (Secondary Memory)

1.2 Below your program

  • Instructions, which are collections of bits that the computer understand, can be thought of as numbers
  • Assembler translates a symbolic version of an instruction (ie. assembly language) into the binary version
  • Compiler translates a higher level notation (high-level programming languages) down to assembly language
  • High-level programming languages offers following benefits:
    • Allow programmer to think in a more natural language 
    • Improve programmer productivity - Conciseness
    • Allow programs to be independent of computer
  • Operating systems are supervising programs that manage resources of a computer
  • Systems software are software that provides services (OS, assembler, compiler)
  • Application software are software that aims at computer users 

Chapter 1: Computer Abstractions and Technology

  • In the 1960s and 1970s, a primary constraint on computer performance was the size of the computer's memory. Thus programmers often followed a simple credo: Minimize memory space to make programs fast
  • In the 1980s, advances in computer design and memory technology have greatly reduced the importance of small memory size. For performance, programmers instead have to understand the hierarchical nature of memories and the parallel nature of processors