CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4...
Transcript of CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4...
![Page 1: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/1.jpg)
CSC 252: Computer Organization Spring 2020: Lecture 2
Instructor: Yuhao Zhu
Department of Computer ScienceUniversity of Rochester
Action Items: • Programming Assignment 1 is out
![Page 2: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/2.jpg)
Carnegie Mellon
!2
Announcement• Programming Assignment 1 is out
• Details: https://www.cs.rochester.edu/courses/252/spring2020/labs/assignment1.html
• Due on Jan. 31, 11:59 PM • You have 3 slip days
Today
Due
![Page 3: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/3.jpg)
Carnegie Mellon
!3
Announcement• TA office hours are all posted. Start from this week.• Programming assignment 1 is in C language. Seek help
from TAs.• TAs are best positioned to answer your questions about
programming assignments!!!• Programming assignments do NOT repeat the lecture
materials. They ask you to synthesize what you have learned from the lectures and work out something new.
![Page 4: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/4.jpg)
Carnegie Mellon
!4
Previously in 252…
Problem
Algorithm
Program
Instruction SetArchitecture (ISA)
Microarchitecture
Circuit
![Page 5: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/5.jpg)
Carnegie Mellon
!4
Previously in 252…
Problem
Algorithm
Program
Instruction SetArchitecture (ISA)
Microarchitecture
Circuit
ISA is the contract between software and hardware.
![Page 6: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/6.jpg)
Carnegie Mellon
!4
Previously in 252…
Problem
Algorithm
Program
Instruction SetArchitecture (ISA)
Microarchitecture
Circuit
ISA is the contract between software and hardware.
Renting Computing
Service provider Landlord HardwareService receiver YOU SoftwareContract Lease Assembly ProgramContract’s language Natural language (e.g.,
English)ISA
![Page 7: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/7.jpg)
Carnegie Mellon
!4
Previously in 252…
Problem
Algorithm
Program
Instruction SetArchitecture (ISA)
Microarchitecture
Circuit
ISA is the contract between software and hardware.
Renting Computing
Service provider Landlord HardwareService receiver YOU SoftwareContract Lease Assembly ProgramContract’s language Natural language (e.g.,
English)ISA
![Page 8: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/8.jpg)
Carnegie Mellon
!4
Previously in 252…
Problem
Algorithm
Program
Instruction SetArchitecture (ISA)
Microarchitecture
Circuit
• How is a human-readable program translated to a representation that computers can understand? ISA is the contract
between software and hardware.
![Page 9: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/9.jpg)
Carnegie Mellon
!4
Previously in 252…
Problem
Algorithm
Program
Instruction SetArchitecture (ISA)
Microarchitecture
Circuit
• How is a human-readable program translated to a representation that computers can understand?
• How does a modern computer execute that program?
ISA is the contract between software and hardware.
![Page 10: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/10.jpg)
Carnegie Mellon
!5
Previously in 252…Assembly program
movl $1, -4(%rbp) movl $2, -8(%rbp) movl -4(%rbp), %eax addl -8(%rbp), %eax
C Program
void add() { int a = 1; int b = 2; int c = a + b; }
![Page 11: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/11.jpg)
Carnegie Mellon
!5
Previously in 252…Assembly program
movl $1, -4(%rbp) movl $2, -8(%rbp) movl -4(%rbp), %eax addl -8(%rbp), %eax
Executable Binary
00011001 … 01101010 … 11010101 … 01110001 …
![Page 12: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/12.jpg)
Carnegie Mellon
!6
Previously in 252…Assembly program
movl $1, -4(%rbp) movl $2, -8(%rbp) movl -4(%rbp), %eax addl -8(%rbp), %eax
Executable Binary
00011001 … 01101010 … 11010101 … 01110001 …
• What’s the difference between an assembly program and an executable binary?
• They refer to the same thing — a list of instructions that the software asks the hardware to perform
• They are just different representations
• Instruction = Operator + Operand(s)
![Page 13: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/13.jpg)
Carnegie Mellon
!6
Previously in 252…Assembly program
movl $1, -4(%rbp) movl $2, -8(%rbp) movl -4(%rbp), %eax addl -8(%rbp), %eax
Executable Binary
00011001 … 01101010 … 11010101 … 01110001 …
• What’s the difference between an assembly program and an executable binary?
• They refer to the same thing — a list of instructions that the software asks the hardware to perform
• They are just different representations
• Instruction = Operator + Operand(s)
![Page 14: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/14.jpg)
Carnegie Mellon
!6
Previously in 252…Assembly program
movl $1, -4(%rbp) movl $2, -8(%rbp) movl -4(%rbp), %eax addl -8(%rbp), %eax
Executable Binary
00011001 … 01101010 … 11010101 … 01110001 …
• What’s the difference between an assembly program and an executable binary?
• They refer to the same thing — a list of instructions that the software asks the hardware to perform
• They are just different representations
• Instruction = Operator + Operand(s)
![Page 15: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/15.jpg)
Carnegie Mellon
!7
Today: Representing Information in Binary
• Why Binary (bits)?• Bit-level manipulations• Integers
• Representation: unsigned and signed• Conversion, casting• Expanding, truncating• Addition, negation, multiplication, shifting• Summary
• Representations in memory, pointers, strings
![Page 16: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/16.jpg)
Carnegie Mellon
!8
Everything is bits
![Page 17: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/17.jpg)
Carnegie Mellon
!8
Everything is bits• Each bit is 0 or 1. Bits are how programs talk to the hardware
![Page 18: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/18.jpg)
Carnegie Mellon
!8
Everything is bits• Each bit is 0 or 1. Bits are how programs talk to the hardware• Programs encode instructions in bits
![Page 19: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/19.jpg)
Carnegie Mellon
!8
Everything is bits• Each bit is 0 or 1. Bits are how programs talk to the hardware• Programs encode instructions in bits• Hardware then interprets the bits
![Page 20: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/20.jpg)
Carnegie Mellon
!8
Everything is bits• Each bit is 0 or 1. Bits are how programs talk to the hardware• Programs encode instructions in bits• Hardware then interprets the bits• Why bits? Electronic Implementation
![Page 21: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/21.jpg)
Carnegie Mellon
!8
Everything is bits• Each bit is 0 or 1. Bits are how programs talk to the hardware• Programs encode instructions in bits• Hardware then interprets the bits• Why bits? Electronic Implementation
Power (Voltage)
![Page 22: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/22.jpg)
Carnegie Mellon
0.0V0.2V
0.9V1.1V
0 1 0
!9
Why Bits?• Each bit is 0 or 1. Bits are how programs talk to the hardware• Programs encode instructions in bits• Hardware then interprets the bits• Why bits? Electronic Implementation
• Use high voltage to represent 1 • Use low voltage to represent 0
![Page 23: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/23.jpg)
Carnegie Mellon
0.0V0.2V
0.9V1.1V
0 1 0
!9
Why Bits?• Each bit is 0 or 1. Bits are how programs talk to the hardware• Programs encode instructions in bits• Hardware then interprets the bits• Why bits? Electronic Implementation
• Use high voltage to represent 1 • Use low voltage to represent 0
Low voltage
![Page 24: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/24.jpg)
Carnegie Mellon
0.0V0.2V
0.9V1.1V
0 1 0
!9
Why Bits?• Each bit is 0 or 1. Bits are how programs talk to the hardware• Programs encode instructions in bits• Hardware then interprets the bits• Why bits? Electronic Implementation
• Use high voltage to represent 1 • Use low voltage to represent 0
Low voltage High voltage
![Page 25: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/25.jpg)
Carnegie Mellon
!10
Why Bits?
![Page 26: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/26.jpg)
Carnegie Mellon
!10
Why Bits?Processors are made of transistors, which are Metal Oxide Semiconductor (MOS)
![Page 27: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/27.jpg)
Carnegie Mellon
!10
Why Bits?Processors are made of transistors, which are Metal Oxide Semiconductor (MOS)
• two types: n-type and p-type
![Page 28: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/28.jpg)
Carnegie Mellon
!10
Why Bits?Processors are made of transistors, which are Metal Oxide Semiconductor (MOS)
• two types: n-type and p-typen-type (NMOS)
Terminal #2 must be connected to GND (0V).
![Page 29: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/29.jpg)
Carnegie Mellon
!10
Why Bits?Processors are made of transistors, which are Metal Oxide Semiconductor (MOS)
• two types: n-type and p-typen-type (NMOS)
• when Gate has high voltage, short circuit between #1 and #2 (switch closed)
Terminal #2 must be connected to GND (0V).
![Page 30: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/30.jpg)
Carnegie Mellon
!10
Why Bits?Processors are made of transistors, which are Metal Oxide Semiconductor (MOS)
• two types: n-type and p-typen-type (NMOS)
• when Gate has high voltage, short circuit between #1 and #2 (switch closed)
Gate = 1
Terminal #2 must be connected to GND (0V).
![Page 31: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/31.jpg)
Carnegie Mellon
!10
Why Bits?Processors are made of transistors, which are Metal Oxide Semiconductor (MOS)
• two types: n-type and p-typen-type (NMOS)
• when Gate has high voltage, short circuit between #1 and #2 (switch closed)
• when Gate has low voltage, open circuit between #1 and #2(switch open)
Gate = 1
Terminal #2 must be connected to GND (0V).
![Page 32: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/32.jpg)
Carnegie Mellon
!10
Why Bits?Processors are made of transistors, which are Metal Oxide Semiconductor (MOS)
• two types: n-type and p-typen-type (NMOS)
• when Gate has high voltage, short circuit between #1 and #2 (switch closed)
• when Gate has low voltage, open circuit between #1 and #2(switch open)
Gate = 0
Gate = 1
Terminal #2 must be connected to GND (0V).
![Page 33: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/33.jpg)
Carnegie Mellon
!11
Why Bits?p-type is complementary to n-type (PMOS)
• when Gate has high voltage, open circuit between #1 and #2(switch open)
• when Gate has low voltage,short circuit between #1 and #2(switch closed)
Gate = 1
Gate = 0Terminal #1 must be connected to +1.2V
+1.2V
![Page 34: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/34.jpg)
Carnegie Mellon
!12
Inverter+1.2V
+0.0V
![Page 35: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/35.jpg)
Carnegie Mellon
!12
Inverter+1.2V
+0.0V
PMOS
![Page 36: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/36.jpg)
Carnegie Mellon
!12
Inverter+1.2V
+0.0V
PMOS
NMOS
![Page 37: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/37.jpg)
Carnegie Mellon
!12
Inverter+1.2V
+0.0V
+1.2V
![Page 38: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/38.jpg)
Carnegie Mellon
!12
Inverter+1.2V
+0.0V
+1.2V
+0.0V
![Page 39: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/39.jpg)
Carnegie Mellon
!12
Inverter
In Out
0 11 0
+1.2V
+0.0V
+1.2V
+0.0V
![Page 40: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/40.jpg)
Carnegie Mellon
!12
Inverter
In Out
0 11 0
+1.2V
+0.0V
+1.2V
+0.0V
![Page 41: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/41.jpg)
Carnegie Mellon
Store/Access Data
!13
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
![Page 42: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/42.jpg)
Carnegie Mellon
Store/Access Data
!13
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1
![Page 43: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/43.jpg)
Carnegie Mellon
Store/Access Data
!13
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
![Page 44: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/44.jpg)
Carnegie Mellon
Store/Access Data
!13
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
1
![Page 45: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/45.jpg)
Carnegie Mellon
Store/Access Data
!13
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
1
• Two cross coupled inverters store a single bit
• Feedback path persists the value in the “cell”
![Page 46: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/46.jpg)
Carnegie Mellon
Store/Access Data
!13
row select
bitli
ne
_bitl
ine
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
1
• Two cross coupled inverters store a single bit
• Feedback path persists the value in the “cell”
![Page 47: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/47.jpg)
Carnegie Mellon
Store/Access Data
!13
row select
bitli
ne
_bitl
ine
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
1
• Two cross coupled inverters store a single bit
• Feedback path persists the value in the “cell”
1
![Page 48: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/48.jpg)
Carnegie Mellon
Store/Access Data
!13
row select
bitli
ne
_bitl
ine
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
1
• Two cross coupled inverters store a single bit
• Feedback path persists the value in the “cell”
1
1 0
![Page 49: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/49.jpg)
Carnegie Mellon
Store/Access Data
!13
row select
bitli
ne
_bitl
ine
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
1
• Two cross coupled inverters store a single bit
• Feedback path persists the value in the “cell”
• 4 transistors for storage
1
1 0
![Page 50: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/50.jpg)
Carnegie Mellon
Store/Access Data
!13
row select
bitli
ne
_bitl
ine
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
1
• Two cross coupled inverters store a single bit
• Feedback path persists the value in the “cell”
• 4 transistors for storage• 2 transistors for access
1
1 0
![Page 51: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/51.jpg)
Carnegie Mellon
Store/Access Data
!13
row select
bitli
ne
_bitl
ine
0.0V0.2V
0.9V1.1V
0 1 0
Low voltage High voltage
1 0
1
• Two cross coupled inverters store a single bit
• Feedback path persists the value in the “cell”
• 4 transistors for storage• 2 transistors for access• A “6T” cell
1
1 0
![Page 52: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/52.jpg)
Carnegie Mellon
!14
Transistors• Computers are made of transistors• Transistors have become smaller over the years
• Not so much anymore…
![Page 53: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/53.jpg)
Carnegie Mellon
!14
Transistors• Computers are made of transistors• Transistors have become smaller over the years
• Not so much anymore…
![Page 54: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/54.jpg)
Carnegie Mellon
!15
Why Limit Ourselves Only to Binary?• Voltage is continuous. Why interpret it only as 0s and 1s?
0.0V0.2V
0.9V1.1V
0 2 01 1
![Page 55: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/55.jpg)
Carnegie Mellon
!15
Why Limit Ourselves Only to Binary?• Voltage is continuous. Why interpret it only as 0s and 1s?• Answer: Noise
0.0V0.2V
0.9V1.1V
0 2 01 1
![Page 56: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/56.jpg)
Carnegie Mellon
!16
Why Limit Ourselves Only to Binary?• But, there are applications that can tolerate noise
![Page 57: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/57.jpg)
Carnegie Mellon
!16
Why Limit Ourselves Only to Binary?• But, there are applications that can tolerate noise• Classic Example: Camera Sensor
• Photoelectric Effect
![Page 58: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/58.jpg)
Carnegie Mellon
!16
Why Limit Ourselves Only to Binary?• But, there are applications that can tolerate noise• Classic Example: Camera Sensor
• Photoelectric Effect
![Page 59: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/59.jpg)
Carnegie Mellon
!16
Why Limit Ourselves Only to Binary?• But, there are applications that can tolerate noise• Classic Example: Camera Sensor
• Photoelectric Effect
![Page 60: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/60.jpg)
Carnegie Mellon
!16
Why Limit Ourselves Only to Binary?• But, there are applications that can tolerate noise• Classic Example: Camera Sensor
• Photoelectric Effect
![Page 61: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/61.jpg)
Carnegie Mellon
!17
Binary Notation
![Page 62: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/62.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)
![Page 63: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/63.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)
![Page 64: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/64.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)• 2110 = 1*100 + 2*101 = 21
![Page 65: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/65.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)• 2110 = 1*100 + 2*101 = 21• Weighted Positional Notation
• Each bit has a weight depending on its position
![Page 66: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/66.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)• 2110 = 1*100 + 2*101 = 21• Weighted Positional Notation
• Each bit has a weight depending on its position• 10112 = 1*20 + 1*21 + 0*22 + 1*23 = 1110
![Page 67: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/67.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)• 2110 = 1*100 + 2*101 = 21• Weighted Positional Notation
• Each bit has a weight depending on its position• 10112 = 1*20 + 1*21 + 0*22 + 1*23 = 1110
• b3b2b1b0 = b0*20 + b1*21 + b2*22 + b3*23
![Page 68: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/68.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)• 2110 = 1*100 + 2*101 = 21• Weighted Positional Notation
• Each bit has a weight depending on its position• 10112 = 1*20 + 1*21 + 0*22 + 1*23 = 1110
• b3b2b1b0 = b0*20 + b1*21 + b2*22 + b3*23
• Binary Arithmetic
![Page 69: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/69.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)• 2110 = 1*100 + 2*101 = 21• Weighted Positional Notation
• Each bit has a weight depending on its position• 10112 = 1*20 + 1*21 + 0*22 + 1*23 = 1110
• b3b2b1b0 = b0*20 + b1*21 + b2*22 + b3*23
• Binary Arithmetic
Decimal Binary0 00001 00012 00103 00114 01005 01016 01107 01118 10009 100110 101011 101112 110013 110114 111015 1111
![Page 70: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/70.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)• 2110 = 1*100 + 2*101 = 21• Weighted Positional Notation
• Each bit has a weight depending on its position• 10112 = 1*20 + 1*21 + 0*22 + 1*23 = 1110
• b3b2b1b0 = b0*20 + b1*21 + b2*22 + b3*23
• Binary Arithmetic
Decimal Binary0 00001 00012 00103 00114 01005 01016 01107 01118 10009 100110 101011 101112 110013 110114 111015 1111
0110 + 0101
1011
![Page 71: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/71.jpg)
Carnegie Mellon
!17
Binary Notation• Base 2 Number Representation (Binary)• C.f., Base 10 number representation (Decimal)• 2110 = 1*100 + 2*101 = 21• Weighted Positional Notation
• Each bit has a weight depending on its position• 10112 = 1*20 + 1*21 + 0*22 + 1*23 = 1110
• b3b2b1b0 = b0*20 + b1*21 + b2*22 + b3*23
• Binary Arithmetic
Decimal Binary0 00001 00012 00103 00114 01005 01016 01107 01118 10009 100110 101011 101112 110013 110114 111015 1111
0110 + 0101
1011
6 + 5
11
![Page 72: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/72.jpg)
Carnegie Mellon
!18
Hexdecimal (Hex) Notation• Base 16 Number Representation• Use characters ‘0’ to ‘9’ and ‘A’ to ‘F’ • Four bits per Hex digit • 111111102 = FE16
• Write FA1D37B16 in C as• 0xFA1D37B • 0xfa1d37b
Hex Decimal Binary0 0 00001 1 00012 2 00103 3 00114 4 01005 5 01016 6 01107 7 01118 8 10009 9 1001A 10 1010B 11 1011C 12 1100D 13 1101E 14 1110F 15 1111
![Page 73: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/73.jpg)
Carnegie Mellon
!19
Bit, Byte, Word• Byte = 8 bits• Binary 000000002 to 111111112; Decimal: 010 to 25510; Hex: 0016 to FF16 • Least Significant Bit (LSb) vs. Most Significant Bit (MSb)
10110111LSbMSb
![Page 74: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/74.jpg)
Carnegie Mellon
!19
Bit, Byte, Word• Byte = 8 bits• Binary 000000002 to 111111112; Decimal: 010 to 25510; Hex: 0016 to FF16 • Least Significant Bit (LSb) vs. Most Significant Bit (MSb)
10110111LSbMSb
• Word = 4 Bytes (32-bit machine) / 8 Bytes (64-bit machine)• Least Significant Byte (LSB) vs. Most Significant Byte (MSB)
![Page 75: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/75.jpg)
Carnegie Mellon
!20
Today: Representing Information in Binary
• Why Binary (bits)?• Bit-level manipulations• Integers
• Representation: unsigned and signed• Conversion, casting• Expanding, truncating• Addition, negation, multiplication, shifting• Summary
• Representations in memory, pointers, strings
![Page 76: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/76.jpg)
Carnegie Mellon
!21
Bit-level manipulations
Not■ ~A = 1 when A=0
![Page 77: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/77.jpg)
Carnegie Mellon
!21
Bit-level manipulations
Not■ ~A = 1 when A=0
Or■ A|B = 1 when either A=1 or B=1
![Page 78: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/78.jpg)
Carnegie Mellon
!21
Bit-level manipulations
Not■ ~A = 1 when A=0
Or■ A|B = 1 when either A=1 or B=1
And■ A&B = 1 when both A=1 and B=1
![Page 79: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/79.jpg)
Carnegie Mellon
!21
Bit-level manipulations
Not■ ~A = 1 when A=0
Or■ A|B = 1 when either A=1 or B=1
And■ A&B = 1 when both A=1 and B=1
Exclusive-Or (Xor)■ A^B = 1 when either A=1 or B=1, but not both
![Page 80: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/80.jpg)
Carnegie Mellon
!22
NOR (OR + NOT)
A B C
0 0 10 1 0
1 0 0
1 1 0
![Page 81: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/81.jpg)
Carnegie Mellon
!22
NOR (OR + NOT)
A B C
0 0 10 1 0
1 0 0
1 1 0
![Page 82: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/82.jpg)
Carnegie Mellon
!23
Bit Vector Operations• Operate on Bit Vectors• Operations applied bitwise
01101001 & 01010101 01000001
01101001 | 01010101 01111101
01101001 ^ 01010101 00111100
~ 01010101 10101010
![Page 83: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/83.jpg)
Carnegie Mellon
!23
Bit Vector Operations• Operate on Bit Vectors• Operations applied bitwise
01101001 & 01010101 01000001
01101001 | 01010101 01111101
01101001 ^ 01010101 00111100
~ 01010101 10101010 01000001
![Page 84: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/84.jpg)
Carnegie Mellon
!23
Bit Vector Operations• Operate on Bit Vectors• Operations applied bitwise
01101001 & 01010101 01000001
01101001 | 01010101 01111101
01101001 ^ 01010101 00111100
~ 01010101 10101010 01000001 01111101
![Page 85: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/85.jpg)
Carnegie Mellon
!23
Bit Vector Operations• Operate on Bit Vectors• Operations applied bitwise
01101001 & 01010101 01000001
01101001 | 01010101 01111101
01101001 ^ 01010101 00111100
~ 01010101 10101010 01000001 01111101 00111100
![Page 86: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/86.jpg)
Carnegie Mellon
!23
Bit Vector Operations• Operate on Bit Vectors• Operations applied bitwise
01101001 & 01010101 01000001
01101001 | 01010101 01111101
01101001 ^ 01010101 00111100
~ 01010101 10101010 01000001 01111101 00111100 10101010
![Page 87: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/87.jpg)
Carnegie Mellon
!24
Bit-Level Operations in C• Operations &, |, ~, ^ Available in C• Apply to any “integral” data type
• long, int, short, char, unsigned• View arguments as bit vectors• Arguments applied bit-wise
• Examples (Char data type)• ~0x41 ➙ 0xBE
• ~010000012 ➙ 101111102• ~0x00 ➙ 0xFF
• ~000000002 ➙ 111111112• 0x69 & 0x55 ➙ 0x41
• 011010012 & 010101012 ➙ 010000012• 0x69 | 0x55 ➙ 0x7D
• 011010012 | 010101012 ➙ 011111012
![Page 88: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/88.jpg)
Carnegie Mellon
!25
Contrast: Logic Operations in C• Contrast to Logical Operators• &&, ||, !
• View 0 as “False”• Anything nonzero as “True”• Always return 0 or 1• Early termination (e.g., 0 && 1 && 1)
• Examples (char data type)• !0x41 ➙ 0x00• !0x00 ➙ 0x01• !!0x41 ➙ 0x01
• 0x69 && 0x55 ➙ 0x01• 0x69 || 0x55 ➙ 0x01• p && *p (avoids null pointer access)
![Page 89: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/89.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
![Page 90: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/90.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
00010000
![Page 91: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/91.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
![Page 92: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/92.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
00011000
![Page 93: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/93.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
![Page 94: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/94.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
00011000
![Page 95: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/95.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
0001100000011000
![Page 96: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/96.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
0001100000011000
00010000
![Page 97: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/97.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
0001100000011000
0001000000010000
![Page 98: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/98.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
0001100000011000
00010000
00101000
00010000
![Page 99: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/99.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
0001100000011000
00010000
00101000
00010000
00101000
![Page 100: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/100.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
0001100000011000
00010000
00101000
11101000
00010000
00101000
![Page 101: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/101.jpg)
Carnegie Mellon
!26
Shift Operations• Left Shift: x << y • Shift bit-vector x left y positions
• Throw away extra bits on left• Fill with 0’s on right
• Right Shift: x >> y • Shift bit-vector x right y positions
• Throw away extra bits on right• Logical shift
• Fill with 0’s on left• Arithmetic shift
• Replicate most significant bit on left
• Undefined Behavior• Shift amount < 0 or ≥ word size
01100010Argument x
00010000<< 3
00011000Log. >> 2
00011000Arith. >> 2
10100010Argument x
00010000<< 3
00101000Log. >> 2
11101000Arith. >> 2
0001000000010000
0001100000011000
0001100000011000
00010000
00101000
11101000
00010000
00101000
11101000
![Page 102: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/102.jpg)
Carnegie Mellon
!27
Today: Representing Information in Binary
• Why Binary (bits)?• Bit-level manipulations• Integers
• Representation: unsigned and signed• Conversion, casting• Expanding, truncating• Addition, negation, multiplication, shifting• Summary
• Representations in memory, pointers, strings
![Page 103: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/103.jpg)
Carnegie Mellon
!28
Representing Numbers in Binary• Different types of number
• Integer (Negative and Non-negative) • Fractions • Irrationals
0 1 2 3 4 5 6 7-1-2-3-4-5-6-7 ……
![Page 104: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/104.jpg)
Carnegie Mellon
!28
Representing Numbers in Binary• Different types of number
• Integer (Negative and Non-negative) • Fractions • Irrationals
0 1 2 3 4 5 6 7-1-2-3-4-5-6-7 ……
![Page 105: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/105.jpg)
Carnegie Mellon
!29
Encoding Negative Numbers
![Page 106: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/106.jpg)
Carnegie Mellon
!29
Encoding Negative Numbers• So far we have been discussing non-negative numbers: so
called unsigned. How about negative numbers?
![Page 107: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/107.jpg)
Carnegie Mellon
!29
Encoding Negative Numbers• So far we have been discussing non-negative numbers: so
called unsigned. How about negative numbers?• Solution 1: Sign-magnitude
• First bit represents sign; 0 for positive; 1 for negative • The rest represents magnitude
![Page 108: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/108.jpg)
Carnegie Mellon
!29
Encoding Negative Numbers• So far we have been discussing non-negative numbers: so
called unsigned. How about negative numbers?• Solution 1: Sign-magnitude
• First bit represents sign; 0 for positive; 1 for negative • The rest represents magnitude
0 1 2 3 4 5 6 7
![Page 109: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/109.jpg)
Carnegie Mellon
!29
Encoding Negative Numbers• So far we have been discussing non-negative numbers: so
called unsigned. How about negative numbers?• Solution 1: Sign-magnitude
• First bit represents sign; 0 for positive; 1 for negative • The rest represents magnitude
0 1 2 3 4 5 6 7
000 001 010 011100 101 110 111
![Page 110: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/110.jpg)
Carnegie Mellon
!29
Encoding Negative Numbers• So far we have been discussing non-negative numbers: so
called unsigned. How about negative numbers?• Solution 1: Sign-magnitude
• First bit represents sign; 0 for positive; 1 for negative • The rest represents magnitude
0 1 2 3-1-2-3
000 001 010 011111 110 101 100
![Page 111: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/111.jpg)
Carnegie Mellon
!30
Sign-Magnitude Implications• Bits have different semantics
• Two zeros… • Normal arithmetic doesn’t work • Make hardware design harder
Signed Value
Binary
0 0001 0012 0103 011-0 100-1 101-2 110-3 111
![Page 112: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/112.jpg)
Carnegie Mellon
!30
Sign-Magnitude Implications• Bits have different semantics
• Two zeros… • Normal arithmetic doesn’t work • Make hardware design harder
Signed Value
Binary
0 0001 0012 0103 011-0 100-1 101-2 110-3 111
010 +) 101
111
![Page 113: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/113.jpg)
Carnegie Mellon
!30
Sign-Magnitude Implications• Bits have different semantics
• Two zeros… • Normal arithmetic doesn’t work • Make hardware design harder
Signed Value
Binary
0 0001 0012 0103 011-0 100-1 101-2 110-3 111
010 +) 101
111
2 +) -1
-3
![Page 114: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/114.jpg)
Carnegie Mellon
!30
Sign-Magnitude Implications• Bits have different semantics
• Two zeros… • Normal arithmetic doesn’t work • Make hardware design harder
Signed Value
Binary
0 0001 0012 0103 011-0 100-1 101-2 110-3 111
010 +) 101
111
2 +) -1
-3
![Page 115: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/115.jpg)
Carnegie Mellon
!31
Encoding Negative Numbers• Solution 2: Two’s Complement
![Page 116: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/116.jpg)
Carnegie Mellon
!31
Encoding Negative Numbers• Solution 2: Two’s Complement
0 1 2 3 4 5 6 7
Unsigned Binary0 0001 0012 0103 0114 1005 1016 1107 111
![Page 117: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/117.jpg)
Carnegie Mellon
!31
Encoding Negative Numbers• Solution 2: Two’s Complement
0 1 2 3-1-2-3-4
Unsigned Binary0 0001 0012 0103 0114 1005 1016 1107 111
![Page 118: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/118.jpg)
Carnegie Mellon
!31
Encoding Negative Numbers• Solution 2: Two’s Complement
0 1 2 3-1-2-3-4
Unsigned Binary0 0001 0012 0103 0114 1005 1016 1107 111
Signed0123-4-3-2-1
![Page 119: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/119.jpg)
Carnegie Mellon
!31
Encoding Negative Numbers• Solution 2: Two’s Complement
Signed Weight
Unsigned Weight
Bit Position
20 20 021 21 1-22 22 2
0 1 2 3-1-2-3-4
Unsigned Binary0 0001 0012 0103 0114 1005 1016 1107 111
Signed0123-4-3-2-1
![Page 120: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/120.jpg)
Carnegie Mellon
!31
Encoding Negative Numbers• Solution 2: Two’s Complement
Signed Weight
Unsigned Weight
Bit Position
20 20 021 21 1-22 22 2
0 1 2 3-1-2-3-4
Unsigned Binary0 0001 0012 0103 0114 1005 1016 1107 111
Signed0123-4-3-2-1
![Page 121: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/121.jpg)
Carnegie Mellon
!31
Encoding Negative Numbers• Solution 2: Two’s Complement
Signed Weight
Unsigned Weight
Bit Position
20 20 021 21 1-22 22 2
0 1 2 3-1-2-3-4
Unsigned Binary0 0001 0012 0103 0114 1005 1016 1107 111
Signed0123-4-3-2-11012 = 1*20 + 0*21 - 1*22 = -310
![Page 122: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/122.jpg)
Carnegie Mellon
!32
Two-Complement Encoding Example x = 15213: 00111011 01101101 y = -15213: 11000100 10010011
Weight' 15213' ,15213'1' 1' 1' 1' 1'2' 0' 0' 1' 2'4' 1' 4' 0' 0'8' 1' 8' 0' 0'16' 0' 0' 1' 16'32' 1' 32' 0' 0'64' 1' 64' 0' 0'128' 0' 0' 1' 128'256' 1' 256' 0' 0'512' 1' 512' 0' 0'1024' 0' 0' 1' 1024'2048' 1' 2048' 0' 0'4096' 1' 4096' 0' 0'8192' 1' 8192' 0' 0'16384' 0' 0' 1' 16384',32768' 0' 0' 1' ,32768'
Sum$ $ 15213$ $ )15213$
![Page 123: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/123.jpg)
Carnegie Mellon
!33
Two-Complement Implications• Only 1 zero• Usual arithmetic still works• There is a bit that represents sign!• Most widely used in today’s machines
Signed Binary0 0001 0012 0103 011-4 100-3 101-2 110-1 111
![Page 124: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/124.jpg)
Carnegie Mellon
!33
Two-Complement Implications• Only 1 zero• Usual arithmetic still works• There is a bit that represents sign!• Most widely used in today’s machines
010 +) 101
111
Signed Binary0 0001 0012 0103 011-4 100-3 101-2 110-1 111
![Page 125: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/125.jpg)
Carnegie Mellon
!33
Two-Complement Implications• Only 1 zero• Usual arithmetic still works• There is a bit that represents sign!• Most widely used in today’s machines
010 +) 101
111
2 +) -3
-1
Signed Binary0 0001 0012 0103 011-4 100-3 101-2 110-1 111
![Page 126: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/126.jpg)
Carnegie Mellon
!34
Numeric Ranges
![Page 127: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/127.jpg)
Carnegie Mellon
!34
Numeric Ranges• Unsigned Values
• UMin = 0 000…0
• UMax = 2w – 1 111…1
![Page 128: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/128.jpg)
Carnegie Mellon
!34
Numeric Ranges• Unsigned Values
• UMin = 0 000…0
• UMax = 2w – 1 111…1
• Two’s Complement Values▪ TMin = –2w–1
100…0 ▪ TMax = 2w–1 – 1
011…1
![Page 129: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/129.jpg)
Carnegie Mellon
!34
Numeric Ranges• Unsigned Values
• UMin = 0 000…0
• UMax = 2w – 1 111…1
• Two’s Complement Values▪ TMin = –2w–1
100…0 ▪ TMax = 2w–1 – 1
011…1
Decimal Hex Binary UMax 65535 FF FF 11111111 11111111 TMax 32767 7F FF 01111111 11111111 TMin -32768 80 00 10000000 00000000 -1 -1 FF FF 11111111 11111111 0 0 00 00 00000000 00000000
Values for W = 16
![Page 130: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/130.jpg)
Carnegie Mellon
!34
Numeric Ranges• Unsigned Values
• UMin = 0 000…0
• UMax = 2w – 1 111…1
• Two’s Complement Values▪ TMin = –2w–1
100…0 ▪ TMax = 2w–1 – 1
011…1• Other Values
▪ Minus 1 111…1
Decimal Hex Binary UMax 65535 FF FF 11111111 11111111 TMax 32767 7F FF 01111111 11111111 TMin -32768 80 00 10000000 00000000 -1 -1 FF FF 11111111 11111111 0 0 00 00 00000000 00000000
Values for W = 16
![Page 131: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/131.jpg)
Carnegie Mellon
!35
Data Representations in C (in Bytes)• By default variables are signed• Unless explicitly declared as unsigned (e.g., unsigned int)• Signed variables use two-complement encoding
C Data Type 32-bit 64-bit
char 1 1
short 2 2
int 4 4
long 4 8
![Page 132: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/132.jpg)
Carnegie Mellon
!36
Data Representations in C (in Bytes)
C Data Type 32-bit 64-bit
char 1 1
short 2 2
int 4 4
long 4 8
! W"! 8" 16" 32" 64"
UMax" 255! 65,535! 4,294,967,295! 18,446,744,073,709,551,615!TMax" 127! 32,767! 2,147,483,647! 9,223,372,036,854,775,807!TMin" -128! -32,768! -2,147,483,648! -9,223,372,036,854,775,808!
!!
![Page 133: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/133.jpg)
Carnegie Mellon
!36
Data Representations in C (in Bytes)
C Data Type 32-bit 64-bit
char 1 1
short 2 2
int 4 4
long 4 8
! W"! 8" 16" 32" 64"
UMax" 255! 65,535! 4,294,967,295! 18,446,744,073,709,551,615!TMax" 127! 32,767! 2,147,483,647! 9,223,372,036,854,775,807!TMin" -128! -32,768! -2,147,483,648! -9,223,372,036,854,775,808!
!! • C Language
•#include <limits.h>•Declares constants, e.g.,
•ULONG_MAX•LONG_MAX•LONG_MIN
•Values platform specific
![Page 134: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/134.jpg)
Carnegie Mellon
!37
Can We Represent Fractions in Binary?• What does 10.012 mean?• C.f., Decimal
• 12.45 = 1*101 + 2*100 + 4*10-1 + 5*10-2
• 10.012 = 1*21 + 0*20 + 0*2-1 + 1*2-2 = 2.2510
![Page 135: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/135.jpg)
Carnegie Mellon
!37
Can We Represent Fractions in Binary?• What does 10.012 mean?• C.f., Decimal
• 12.45 = 1*101 + 2*100 + 4*10-1 + 5*10-2
• 10.012 = 1*21 + 0*20 + 0*2-1 + 1*2-2 = 2.2510
Decimal Binary0 00.000.25 00.010.5 00.100.75 00.111 01.001.25 01.011.5 01.101.75 01.112 10.002.25 10.012.5 10.102.75 10.113 11.003.25 11.013.5 11.103.75 11.11
![Page 136: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/136.jpg)
Carnegie Mellon
!37
Can We Represent Fractions in Binary?• What does 10.012 mean?• C.f., Decimal
• 12.45 = 1*101 + 2*100 + 4*10-1 + 5*10-2
• 10.012 = 1*21 + 0*20 + 0*2-1 + 1*2-2 = 2.2510
Decimal Binary0 00.000.25 00.010.5 00.100.75 00.111 01.001.25 01.011.5 01.101.75 01.112 10.002.25 10.012.5 10.102.75 10.113 11.003.25 11.013.5 11.103.75 11.11
0 1 2 3 4 5 6 7 …. 15
![Page 137: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/137.jpg)
Carnegie Mellon
!37
Can We Represent Fractions in Binary?• What does 10.012 mean?• C.f., Decimal
• 12.45 = 1*101 + 2*100 + 4*10-1 + 5*10-2
• 10.012 = 1*21 + 0*20 + 0*2-1 + 1*2-2 = 2.2510
Decimal Binary0 00.000.25 00.010.5 00.100.75 00.111 01.001.25 01.011.5 01.101.75 01.112 10.002.25 10.012.5 10.102.75 10.113 11.003.25 11.013.5 11.103.75 11.11
0 1 2 3
![Page 138: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/138.jpg)
Carnegie Mellon
!37
Can We Represent Fractions in Binary?• What does 10.012 mean?• C.f., Decimal
• 12.45 = 1*101 + 2*100 + 4*10-1 + 5*10-2
• 10.012 = 1*21 + 0*20 + 0*2-1 + 1*2-2 = 2.2510
Decimal Binary0 00.000.25 00.010.5 00.100.75 00.111 01.001.25 01.011.5 01.101.75 01.112 10.002.25 10.012.5 10.102.75 10.113 11.003.25 11.013.5 11.103.75 11.11
0 1 2 3
01.10 + 01.01
10.11
1.50 + 1.25
2.75
![Page 139: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/139.jpg)
Carnegie Mellon
!37
Can We Represent Fractions in Binary?• What does 10.012 mean?• C.f., Decimal
• 12.45 = 1*101 + 2*100 + 4*10-1 + 5*10-2
• 10.012 = 1*21 + 0*20 + 0*2-1 + 1*2-2 = 2.2510
Decimal Binary0 00.000.25 00.010.5 00.100.75 00.111 01.001.25 01.011.5 01.101.75 01.112 10.002.25 10.012.5 10.102.75 10.113 11.003.25 11.013.5 11.103.75 11.11
0 1 2 3
01.10 + 01.01
10.11
1.50 + 1.25
2.75
Integer Arithmetic Still Works!
![Page 140: CSC 252: Computer Organization Spring 2020: Lecture 2 › ... › decks › Lecture2.pdf · !4 Previously in 252… Problem Algorithm Program Instruction Set Architecture (ISA) Microarchitecture](https://reader033.fdocuments.us/reader033/viewer/2022042402/5f11b883e11c0301a5426092/html5/thumbnails/140.jpg)
Carnegie Mellon
!38
Fixed-Point RepresentationDecimal Binary0 00.000.25 00.010.5 00.100.75 00.111 01.001.25 01.011.5 01.101.75 01.112 10.002.25 10.012.5 10.102.75 10.113 11.003.25 11.013.5 11.103.75 11.11
• Fixed interval between two representable numbers as long as the binary point stays fixed
• Each bit represents 0.2510 • Fixed-point representation of numbers
• Integer is one special case of fixed-point
0 1 2 3
01.10 + 01.01
10.11
1.50 + 1.25
2.75