Thursday, 17 September 2015 Upcoming talk: Harnessing - - PowerPoint PPT Presentation
Thursday, 17 September 2015 Upcoming talk: Harnessing - - PowerPoint PPT Presentation
Thursday, 17 September 2015 Upcoming talk: Harnessing Bioinformatics to Improve the Rice Root System September 24 at 4:30 p.m. in Steffee B10 Allegheny will be offering Introduction to Bioinformatics this spring--CMPSC/BIO 200.
Today:
- Return lab 1 -- remarks
- Quiz! (Yay!)
- More on binary and twos complement
- Back to MIPS
Binary (unsigned)
Base 2 -- each position from right to left is a power of 2, starting with 20 = 1: 1001011 1x26 + 1x23 + 1x21 + 1x20 = 64 + 8 + 2 + 1 = 75
Useful to Know:
In k bits (unsigned), we can store all the values from 0 through 2k-1. Example: 4 bits: 0 = 0000, 1 = 0001, 2 = 0010, …, 15 = 1111 (15 = 24-1) Binary numbers ending in 0 represent even numbers; binary numbers ending in 00 represent multiples of 4; binary numbers ending in 000 represent multiples of 8; etc.
Converting Between Bases
Converting from binary to decimal: add up powers of 2. (C example: “bintodec.c” in code repository). Converting from decimal to binary: repeatedly divide by 2 and look at remainders. Example: convert 13 to base 2 13 / 2 = 6, remainder 1 6 / 2 = 3, remainder 0 3 / 2 = 1, remainder 1 1 / 2 = 0, remainder 1
1101
Converting from Decimal to Binary
Doing this in C is a bit tricky -- bits are computed from right to left, but we can’t print from right to left! Solution: use an array! See “dectobin.c” in repository.
Signed Integers
Use the “twos complement” representation. Most significant (leftmost) bit is used to represent a NEGATIVE power of 2: Example (7-bit twos complement):
1001011
- 1x26 + 1x23 + 1x21 + 1x20 =
- 64 + 8 + 2 + 1 = -53
Signed Integers
In twos complement, a string of all 1s represents -1: Example (5-bit twos complement): 11111 = -32 + 16 + 8 + 4 + 2 + 1 = -1 It is actually easy to compute the twos complement representation of a negative number. First, find the binary representation of the absolute value, then flip all the bits and add 1...
Signed Integers
What is -75 in 8-bit twos complement? +75 = 01001011 (Note: you have to fill in all 8 bits!) Flip: 10110100 Add 1: +1 10110101 = -75 The reverse process takes us back to +75: Flip: 01001010 Add 1: 1 01001011 = +75
Supplement to 17 September slides
Binary Addition (unsigned):
213 11010101 + 159 + 10011111 372 101110100 1 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0
“Carries”
Supplement to 17 September slides
Binary Addition (signed): (8-bit 2s complement)
- 79 10110001
+ 97 + 01100001 18 00010010 1 0 1 1 0 0 0 1 0 1 1 0 0 0 0 1 1 0 1 1 1 0 1 0
“Carries”
1 1
Chapter 2 — Instructions: Language of the Computer — 12
Representing Instructions
■ Instructions are encoded in binary ■ Called machine code ■ MIPS instructions ■ Encoded as 32-bit instruction words ■ Small number of formats encoding operation code (opcode), register numbers, … ■ Regularity! ■ Register numbers ■ $t0 – $t7 are reg’s 8 – 15 ■ $t8 – $t9 are reg’s 24 – 25 ■ $s0 – $s7 are reg’s 16 – 23 §2.5 Representing Instructions in the Computer
Chapter 2 — Instructions: Language of the Computer — 13
MIPS R-format Instructions
■ Instruction fields ■ op: operation code (opcode) ■ rs: first source register number ■ rt: second source register number ■ rd: destination register number ■ shamt: shift amount (00000 for now) ■ funct: function code (extends opcode)
- p
rs rt rd shamt funct
6 bits 6 bits 5 bits 5 bits 5 bits 5 bits