CS111 – Fundamentals of CS�Lecture 12�Data Manipulation II
(Many Slides by Pearson Edu.)
Copyright © 2015 Pearson Education, Inc.
Intelligent Design ☺
Random ☹
Copyright © 2015 Pearson Education, Inc.
The Miracle of the Hand�https://cutt.ly/fUogc2Y
Marvelous Engineering ☺
Haphazardness ☹
Copyright © 2015 Pearson Education, Inc.
What Will We Study?
1
أ ب ت
2
3
Programs
Algorithms
4
5
2
10001110111
10001110111
Copyright © 2015 Pearson Education, Inc.
Stored Program Concept
A program can be encoded as bit patterns and stored in main memory. From there, the CPU can then extract the instructions and execute them. In turn, the program to be executed can be altered easily.
2-5
Copyright © 2015 Pearson Education, Inc.
Computer Architecture Influence
from memory to CPU
Memory
CPU
1-6
add 4+8
subtract
compare
12
Copyright © 2015 Pearson Education, Inc.
Try FCI Machine Simulator
0-7
https://github.com/Megadardery/machine-language/releases
Developed to be used with this course on Windows
A good explanation video for von Neumann (Arabic) – numerous English ones exist
https://www.youtube.com/watch?v=wC6rfZaF3fM
Copyright © 2015 Pearson Education, Inc.
Chapter 2: Data Manipulation
2-8
Copyright © 2015 Pearson Education, Inc.
0-9
Copyright © 2015 Pearson Education, Inc.
0-10
Copyright © 2015 Pearson Education, Inc.
Exam Question
0-11
Copyright © 2015 Pearson Education, Inc.
0-12
Another Exam Question
Copyright © 2015 Pearson Education, Inc.
0-13
Copyright © 2015 Pearson Education, Inc.
Solution
C equivalent:
int x, y;
x = 2; y =1;
while (y != 4) {
x = x + y;
y = y + 1;
}
0-14
Copyright © 2015 Pearson Education, Inc.
0-15
x = 2
y = 1
Load y in R1 and 4 in R0
If y == 4 jump to end
If not load x in R2
Add x + y
store result in x (x = x+y)
Store 1 in R0, add it to y
Then store result in y
Jump to loop start
Copyright © 2015 Pearson Education, Inc.
0-16
Copyright © 2015 Pearson Education, Inc.
Boolean Operations
1-17
Copyright © 2015 Pearson Education, Inc.
Figure 1.1 The possible input and output values of Boolean operations AND, OR, and XOR (exclusive or)
1-18
The NOT operation
NOT 1 NOT 0
0 1
Copyright © 2015 Pearson Education, Inc.
Figure 1.1 The possible input and output values of Boolean operations AND, OR, and XOR (exclusive or)
1-19
AND
OR
XOR
1 1 ▬► 1
1 1 ▬► 1
1 0 ▬► 1
0 1 ▬► 1
1 0 ▬► 1
0 1 ▬► 1
Copyright © 2015 Pearson Education, Inc.
0-20
Copyright © 2015 Pearson Education, Inc.
0-21
Copyright © 2015 Pearson Education, Inc.
0-22
Copyright © 2015 Pearson Education, Inc.
IV. Arithmetic/Logic Operations
AND, OR, XOR
2-23
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
Copyright © 2015 Pearson Education, Inc.
Exam Question - Even or Odd
0-25
Copyright © 2015 Pearson Education, Inc.
Exam Question - Even or Odd Algo
0-26
Copyright © 2015 Pearson Education, Inc.
0-27
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
Turn off a bit / flag Get value of bit / flag
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
The XOR operation can be used to invert all of the bits of an RGB bitmap
image, resulting in an “inverted” color image in which light colors have been
replaced by dark colors, and vice versa.
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
Copyright © 2015 Pearson Education, Inc.
Exam Question
0-32
Copyright © 2015 Pearson Education, Inc.
0-33
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
2-34
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
2-35
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
2-36
Copyright © 2015 Pearson Education, Inc.
Figure 2.12 Rotating the bit pattern 65 (hexadecimal) one bit to the right
2-37
Copyright © 2015 Pearson Education, Inc.
0-38
Copyright © 2015 Pearson Education, Inc.
Arithmetic/Logic Operations
2-39
Copyright © 2015 Pearson Education, Inc.
Exam Question
0-40
Copyright © 2015 Pearson Education, Inc.