0% found this document useful (0 votes)
30 views

CS Unit 2

The document discusses data manipulation and machine language at a low level, explaining concepts like CPU components, machine instructions, and how programs are executed through fetching, decoding, and executing instructions in a repeating cycle. It also covers higher level programming concepts like variables, functions, control structures, and how programming languages allow users to manipulate data and perform operations without knowing the underlying machine instructions.

Uploaded by

mcgowinamazon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

CS Unit 2

The document discusses data manipulation and machine language at a low level, explaining concepts like CPU components, machine instructions, and how programs are executed through fetching, decoding, and executing instructions in a repeating cycle. It also covers higher level programming concepts like variables, functions, control structures, and how programming languages allow users to manipulate data and perform operations without knowing the underlying machine instructions.

Uploaded by

mcgowinamazon
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

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.

2.2 Machine Language


Machine Instruction: An instruction encoded as a bit pattern recognizable by the CPU
Machine Language: The set of all instructions recognized by a machine

Machine Language Philosopheies


Reduced instruction Set Computing (RISC)
Few, simple, efficient, and fast instructions
Examples: PowerPC from Apple/IBM/Motorola and ARM
Complex Instruction Set Computing (CISC)
Many, convenient, and powerful instructions
Example: Intel

Machine Instruction Types


Data Transfer: copy data from one location to another (ex: LOAD, STORE)
Arithmetic/Logic: operations on bit patterns (ex: +, -, *, /, AND, OR, SHIFT, ROTATE)
Control: direct the execution of the program (ex:JUMP, BRANCH)

Parts of a Machine Instruction


Op-code: specifies which operation to execute
Operand: gives more detailed information about the operation
interpretation of operand varies depending on the opcode

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

0x2 RXY LOAD the register R with the bit pattern XY


EX: : 0x20A3 would cause the value 0xA3 to be placed in register 0

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

0x4 0RS MOVE the bit pattern found in register R to register S


EX: 0x40A4 would cause the contents of register 0xA to be copied into register
0x4

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.

0xC 000 HALT execution


EX: 0xC000 would cause program execution to stop

2.3 Program Execution

Controlled by two special purpose registers


Instruction register
Holds current instruction
Program counter
Holds address of next instruction

Machine Cycle: (repeat these 3 steps)


Fetch: Retrieve the next instruction from memory (as indicated by the program
counter) and then increment the program counter
Decode: Decode the bit pattern in the instruction register
Execute: Perform the action required by the instruction in the instruction register

2.4 Arithmetic/Logic Instruction


Logic Operations:
AND, OR, XOR
Often used to mask an operand
Rotation and Shift Operations:
circular shift, logical shift, arithmetic shift
Arithmetic Operations
Add, subtract, multiply, divide
Two's complement versus floating-point

2.5 Communicating with Other devices


Controller: handles communication between the computer and other devices
specialized (by types of device)
general purpose (USB, HDMI)
Port: the point at which a device connects to a computer
Memory-mapped I/O: devices appear to the CPU as though they were memory locations
Direct memory access (DMA): main memory acces by a controller over the bus
Von Neumann Bottleneck: occurs when the CPU and controllers compete for bus
access
Handshaking: the process of coordination the transfer of data between the computer and
the peripheral device
Popular communication media
Parallel communication: several signals transferred at the same time, each on a
separate "line" (computer's internal bus)
Serial communication: signals are transferred one after the other over a single
"line" (USB, FireWire)

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

2.6 Programming Data manipulation

Programming languages shields users from details of the machine:


A single Python statement might map to one, tens, or hundreds of machine
instructions
Programmer does not need to know if the processor is RISC or CISC
Assigning variables surely involves LOAD, STORE, and MOVE op-codes

Bitwise Problems as Python Code

print(bin(0b10011010 & 0b11001001))


# Prints '0b10001000'

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'

Argument Value: a value plugged into a parameter


Fruitful functions return a value
Void functions, or procedures, do not return a value

sideA = 3.0
sideB = 4.0
#calculate third side via Pythagorean Theorem
hypotenuse = math.sqrt(sideA**2 + sideB**2)
print(hypotenuse)

# Calculates the hypotenuse of a right triangle


import math
# Inputting the side lengths, first try
sideA=int(input('Length of side A? '))
sideB=int(input('Length of side B? '))
# Calculate third side via Pythagorean Theorem
hypotenuse=math.sqrt(sideA**2 + sideB**2)
print(hypotenuse)

# Marathon training assistant


import math
# This function converts a number of minutes and number of seconds into just
seconds
def total_seconds(min,sec):
return min * 60 + sec
# This function calculates a speed in miles per hour given
# a time (in seconds) to run a single mile
def speed(time):
return 3600/time
# Prompt user for pace and mileage
pace_minutes = int(input('Minutes per mile? '))
pace_seconds = int(input('Seconds per mile? '))
miles = int(input('Total miles? '))

# Calculate and print speed.


mph = speed(total_seconds(pace_minutes, pace_seconds))
print('Your speed is ' + str(mph) + 'mph')

# Calculate elapsed time for planned workout.


total = miles * total_seconds(pace_minutes, pace_seconds)
elapsed_minutes = total // 60
elapsed_seconds = total % 60

print('Your elapsed time is ' + str(elapsed_minutes) + 'mins' +


str(elapsed_seconds) + 'secs')

2.7 Other Architectures

● Technologies to increase throughout:


○ Pipelining: Overlap steps of the machine cycle
○ Parallel processing: Use multiple processors simultaneously
■ SISD: single instruction, single data
● No parallel processing
■ MIMD: multiple instruction, multiple data
● Different programs, different data
■ SIMD: single instruction, multiple data
● Same program, different data

You might also like