Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer?...

21
Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation • How is data manipulated inside a computer? – How is data input? – How is it stored? – How is it output? – How is it transmitted to other computers? – What is machine language and how does it work?

Transcript of Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer?...

Page 1: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

1

Data Manipulation

• How is data manipulated inside a computer?– How is data input?– How is it stored?– How is it output?– How is it transmitted to other computers?– What is machine language and how does it

work?

Page 2: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

2

Computer Architecture

• Central Processing Unit

• Main Memory

• Peripherals

• Bus (and sometimes Bluetooth devices, switches) for connecting parts

• Bus is a collection of wires and circuitry for transferring data, addresses, control information

Page 3: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

3

PCI bus

monitor

Graphicscontroller

Processor(s)

cache(s)

memorycontroller

USB controller for USB bus/devices

SCSI controller to SCSI bus and multiple disks

ISA controller

IDE controller to disks

Parallel printers modem

ISA bus mouse keyboard Serial printers, cameras, etc.

Page 4: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

4

USB and FireWire

• Serial communication standards to handle a variety of devices to communicate through the serial port (bits sent one by one rather than in parallel)– Sample USB devices include

• Mice• Keyboards• Printers• Scanners• Digital cameras

Page 5: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

5

DMA

• Controller that allows device to place data into assigned address or retrieve data from assigned address in main memory directly (direct memory access)– Device driver (via CPU) sends controller

address of source, destination, amount of data to be transferred, operation

– Controller informs device driver (via interrupt register in CPU) when operation completes

Page 6: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

6

Communication devices for local loop

• Ethernet (IEEE802.3 wired LAN) NICs – Connected to port with cat 5 (3,6) twisted copper wire

• WiFi (IEEE 802.11) wireless adaptor/NIC) • Dial-up modem through existing telephone lines

• Modems for modulating digital input over analog waves

• DSL through existing telephone lines• Cable modems through CATV cables• FiOS – fiber and modem for the local loop• Cellular phones – some WiFi enabled.• Data rates in Kbps, Mbps, Gbps

Page 7: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

7

Communicating with Devices

• Look at figure of PCI bus – today even memory has a controller (cache does not)

• Controller may be circuitry that is manufactured with device attached to it– controls and “translates” all data going between

device & CPU (software in CPU is called a device driver)

• May be a general purpose controller that handles a number of different devices (SCSI, USB, or firewire controller)

Page 8: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

8

Central Processing Unit

• Small 2” x 2” wafer with connecting pins– Connects to motherboard (main circuit board)

1) Control unit– Brains of the computer; sends signals (volts) to other

units telling them what to do

2) Arithmetic/ Logic unit (ALU)performs data operations (+, and, etc.)

3) Registers, high speed memory buffers data, addresses that are being

manipulated

Page 9: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

9

Registers

• Some register functions– Hold input and output to/ from ALU– Hold addresses for Main Memory (MAR)– Hold data that will be written to memory; retrieved

from memory (MDR)– Hold instruction being executed

• This register is called an Instruction Register (IR)

– Hold address of next instruction to be executed. • This register is called a program counter (PC).

Page 10: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

10

Sample execution of instruction

• First part – fetch instruction• Fetch instruction that is stored at address in PC• Increment PC (even though the value may be overwritten)

• Second part- execute instruction– Example: C = A + B (A, B, C are memory locations)– Step 1. Get value in A from memory; store in register R1– Step 2. Get value in B from memory; store in register R2– Activate circuitry to output values from R1 and R2 (in

turn) to ALU; add with result placed in temporary register in ALU; output this value to R3

– Store R3 into location C in memory

Page 11: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

11

Stored program concept• Initially, program was implemented with

circuitry (e.g., data flow machines)• Read/write memory held only data, not

programs• Stored program concept places program and

data in memory– Originally, code was self modifying; operations

could change instructions– Today there are efforts to protect code – only

allow it to be executed (DEP)

Page 12: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

12

Cache

• High speed memory directly available to CPU– Faster, smaller than main memory

• Hierarchies – L1, L2, L3

– Slower, larger than registers (1, 2MB perhaps)– Used to store parts of memory that have been

recently accessed• Principle of locality of reference

• There are also caches on devices

Page 13: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

13

Machine Language

• Machine language is the language that the CPU interprets

• All machine instructions (except HALT) contain (at least):– Operation code

• Transfer of data to/from CPU (LOAD, STORE)• Arithmetic/ logic operations (ADD, AND, SHIFT)• Control (JUMP)

– Operand (location or value)• Location may be register, memory, even device address

Page 14: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

14

Program Execution

• Machine cycles (these are continually repeated)– Fetch (next instruction)

• Place into instruction register contents of memory address in program counter

• Increment program counter (in our machine by 2)

– Decode op code• Interpret operands based on specific operation

– Execute instruction

Page 15: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

15

Simple Machine

CPU ---- BUS --- Main memoryRegisters/ALU/control unit cell addresses R0 (in hex) 00000000(00 in hex) R1 (in hex) 00000001 PC 00000010 IR 00000011 MDR 00000100 MAR 11111111 (FF in hex)

Page 16: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

16

Machine Language

Op codes for instructions (p.551)4bit Op code 12bit operand Action0001 RiXY Ri (XY)

Copy bit string stored in memory location XY into register i

0010 R1XY Ri XYCopy the value XY ( XY is some bit string) into register i

0011 RiXY XY (Ri) Copy the bit string stored in register i into the memory location XY

0100 0RiRk Rk (Ri) Copy the bit string in Register i into Register k

0101 RiRkRm Ri (Rk)+(Rm) In 2’s complement integer addition, add the values inside Register k and m and store result in register i

0110 RiRkRm Ri (Rk)+(Rm) Floating point addition

Page 17: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion 17

Machine Language

0111 R1R2R3 R1 (R2) OR (R3)

1000 R1R2R3 R1 (R2) AND (R3)

1001 R1R2R3 R1 (R2) XOR (R3) logical operations between registers

1010 R10X R1 (rotate x bits in R1 to the right)

1011 R1XY PC (XY) if (R0) = (R1) else ignore

RoXY is an unconditional jump (go to XY) 1100 - HALTExample: 0001000010100111 in hexadecimal is

10A7; place value stored in A7 into R0

Page 18: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

18

Question • Explain the execution of each step of the following

program (implementation of adding two values stored in memory). Assume program starts at address 00.

00 156C02 166D04 505606 306E08 C000(1) copy value stored at 6C into register 5(2) copy value stored at 6D into register 6(3) Add values in register 5 and 6; place result into register 0(4) Store value in register 0 into 6E(5) Halt

Page 19: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Intro to CS Chapt 2 Data Manipualtion

19

Code vs Data

• Note that code is data to compilers and other types of programs

• In the early days, code could be modified as if it were data

• Today code and data are kept separate, but if you were allowed to write into the code you could harm the system (discuss C pointers, viruses)

Page 20: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

CISC vs RISC architecture• Complex instruction set computing

– Many complex instructions in hardware • easier, faster for programmer to write

• even Apple has switched desktop from PowerPC to Intel

• Reduced Instruction set computing– Machine language composed of a minimal set of machine

instructions• Op code is represented by smaller number of bits (less op codes)

• Less expensive to manufacture

• Low power consumption (ARM)

– Used widely in wireless systems

Intro to CS Chapt 2 Data Manipualtion

20

Page 21: Intro to CS Chapt 2 Data Manipualtion 1 Data Manipulation How is data manipulated inside a computer? –How is data input? –How is it stored? –How is it.

Logical operations in Python

Intro to CS Chapt 2 Data Manipualtion

21