CS Unit 2
CS Unit 2
1 Data Manipulation
Computer Architechture
Central Processing Unit (CPU)
Arithmetic/Logic Unit
Control Unit
Register Unit
General Purpose Registers
Special Purpose Registers
Bus
Main Memory
Stored Program Concept
A program can be encoded as bit patterns and stored in Main Memory. From there, the
Control Unit can extract, decode, and execute instructions.
Instead of rewiring the CPU, the program can be altered by changing the control of Main
Memory.
0x1 RXY LOAD the register R with the bit pattern found in the memory cell whose affress
is XY
EX: 0x14A3 would cause the contents of the memory cell located at address A3
to be placed in register 4
0x3 RXY STORE the bit pattern found in register R in the memory cell whose address is
XY
EX: 0x35B1 would cause the contents of register 0x5 to be placed in the memory
cell whose address is 0xB1
0x5 RST ADD the bit patterns in registers S and T as though the were two's complement
representation and leave the result in register R
EX: 0x5726 would cause the binary values in registers 0x2 and 0x6 to be added
and the sum placed in register 0x7
0x6 RST ADD the bit patterns in registers S and T as though they represented values in
floating-point notation and leave the floating-point result in register R
EX: 0x634E would cause the values in registers 0x4 and 0xE to be added as
floating-point values and the result to be placed in register 0x3
0x7 RST OR the bit patterns in registers S and T and place the result in register R
EX: 0x7CB4 would cause the result of ORing the contents of registers 0xB and
0x4 to be placed in register 0xC
0x8 RST AND the bit patterns in registers S and T and place the result in register R
EX: 0x8045 would cause the result of ANDing the contents of registers 0x4 and
0x5 to be placed in register 0x0
0x9 RST XOR the bit patterns in registers S and T and place the result in register R
EX: 0x95F3 would cause the result of XORing the contents of registers 0xF and
0x3 to be placed in register 0x5
0xA R0X ROTATE the bit pattern in register R one bit to the right X times. Each time, place
the bit that started at the low-order end at the high-order end
EX: 0xA403 would cause the contents of register 0x4 to be rotated 3 bits to the
right in a circular fashion
0xB RXY JUMP to the instruction located in the memory cell at address XY if the bit pattern
in register R is equal to the bit pattern in register number 0. Otherwise, continue with the normal
sequence of execution. (The jump is implemented by copying XY into the program counter
during the execute phase.)
EX: 0xB43C would first compare the contents of register 0x4 with the contents of
register 0x0. If the two were equal, the pattern 0x3C would be placed in the program counter so
that the next instruction executed would be the one located at that memory address. Otherwise,
nothing would be done and program execution would continue in its normal sequence.
Measurement Units
bps: bits per second
Kbps: kilo (1,000) bps
Mbps: mega (1,000,000) bps
Gbps: giga (1,000,000,000) bps
Bandwidth: maximum available rate
print(bin(0b10011010 | 0b11001001))
# Prints '0b11011011'
print(bin(0b10011010 ^ 0b11001001))
# Prints '0b1010011'
Control intructures
if statement
if(water_temp > 140):
print('Bath water too hot!')
while statement
while(n < 10):
print(n)
n=n+1
Functions
Function: a name for a series of operations that should be performed on the
given parameter or paremeters
Function call: appearance of a function in an expression or statement
x = 1034
y = 1056
z = 2078
biggest = max(x, y, z)
print(biggest) #Prints '2078'
sideA = 3.0
sideB = 4.0
#calculate third side via Pythagorean Theorem
hypotenuse = math.sqrt(sideA**2 + sideB**2)
print(hypotenuse)