Computer programming{week 01}
Hudson Valley Community CollegeCISS-110 – Programming & Logic IDavid Goldschmidt, Ph.D.
Computer subsystems
Hardware consists of five key subsystems:
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Fetch/Execute cycle
Each instruction goes through this cycle:
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Example ADD instruction (i)
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Example ADD instruction (ii)
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Example ADD instruction (iii)
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Example ADD instruction (iv)
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Example ADD instruction (v)
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Example ADD instruction (vi)
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Even faster!
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Counting
We use ten symbols to count Digits: 0 1 2 3 4 5 6 7 8 9
Computers use two symbols to count Digits: 0 1 (why?)
What is the exact mechanism for counting? How do we count from 1 to 20?
Convert binary to decimal
The powers of 2 give us the decimal weights Convert 10011001 from binary to decimal:
10011001 in decimal is 128 + 16 + 8 + 1 = 153
powers of 2 27 26 25 24 23 22 21 20
decimal weights
128
64 32 16 8 4 2 1
binary digits 1 0 0 1 1 0 0 1
Hexadecimal
Hexadecimal is base 16 It uses 16 digits: 0 1 2 3 4 5 6 7 8 9 A B C D E F
Why use hex? Binary numbers are too long
What’s 2BAD in decimal?
decimal
binary
hexadecimal
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
ASCII
Representprintableand specialcharacters
What aboutUnicode?
from Fluency with Information Technology, 4th edition by Lawrence Snyder, Addison-Wesley, 2010, ISBN 0-13-609182-2
Java compilation and execution
public static void main( String[] args ){ float x;
System.out. println( "
...
Java source code
7A 56 789F FE F265 58 9976 6D 4E
intermediate code(byte code)
translation program
(compiler)
virtual machine
(JVM)
A6 65 5498 8F ABAE 33 388F DA 44
intermediate code ofprecompiled libraries
(java.util.Scanner byte code)
program execution