Top Banner
1 CS/COE0447 Computer Organization & Assembly Language Pre-Chapter 2
23

CS/COE0447 Computer Organization & Assembly Language

Jan 15, 2016

Download

Documents

Ciara

CS/COE0447 Computer Organization & Assembly Language. Pre-Chapter 2. void swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+1]; v[k+1] = temp; }. swap: muli$2, $5, 4 add$2, $4, $2 lw$15, 0($2) lw$16, 4($2) sw$16, 0($2) sw$15, 4($2) jr$31. - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS/COE0447 Computer Organization & Assembly Language

1

CS/COE0447

Computer Organization & Assembly Language

Pre-Chapter 2

Page 2: CS/COE0447 Computer Organization & Assembly Language

2

“C Program” Down to “Numbers”

swap:muli $2, $5, 4add $2, $4, $2lw $15, 0($2)lw $16, 4($2)sw $16, 0($2)sw $15, 4($2)jr $31

void swap(int v[], int k){

int temp;temp = v[k];v[k] = v[k+1];v[k+1] = temp;

}

00000000101000010…00000000000110000…10001100011000100…10001100111100100…10101100111100100…10101100011000100…00000011111000000…

compiler

assemble

r

Page 3: CS/COE0447 Computer Organization & Assembly Language

3

“Numbers” in Memory

00000000101000010…00000000000110000…10001100011000100…10001100111100100…10101100111100100…10101100011000100…00000011111000000…

Page 4: CS/COE0447 Computer Organization & Assembly Language

4

Stored Program Concept

processor

main memoryhard disk

program A

program Bprogram C

program A

program B

data A

data B

program fetchdata load/store

disk I/Oprogramcounter

Page 5: CS/COE0447 Computer Organization & Assembly Language

5

Stored Program Concept

• Programs (instructions) are stored in memory as a stream of bits (numbers)– Indistinguishable from data– More than one programs can reside in memory at

the same time– Programs can be modified by the processor or I/O

just as data can be modified• Instructions are fetched by the processor, are

decoded and they determine processor actions• Program Counter determines which instruction is

fetched next

Page 6: CS/COE0447 Computer Organization & Assembly Language

6

Stored Program Concept

• In fact, one of the great ideas in computer science is the idea that programs could be stored just as data is stored.

• Before that, people envisioned the hardware running a fixed program, and data being stored in memory.

Page 7: CS/COE0447 Computer Organization & Assembly Language

7

Page 8: CS/COE0447 Computer Organization & Assembly Language

8

Page 9: CS/COE0447 Computer Organization & Assembly Language

9

Page 10: CS/COE0447 Computer Organization & Assembly Language

10

Page 11: CS/COE0447 Computer Organization & Assembly Language

11

Page 12: CS/COE0447 Computer Organization & Assembly Language

12

Addresses and Contents shown in Hex

Page 13: CS/COE0447 Computer Organization & Assembly Language

13

Number Systems

• Actual machine code is in binary – O, 1 are high and low signals to hardware

• Hex (base 16) is often used by humans (code, simulator, manuals, …) because– 16 is a power of 2 (while 10 is not); mapping

between hex and binary is easy– It’s more compact than binary– We can write, e.g., 0x90000008 in programs rather

than 10010000000000000000000000001000

Page 14: CS/COE0447 Computer Organization & Assembly Language

14

Base 10 (Decimal)

• Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (10 of them)

• Example:– 3217 = (3103) + (2102) + (1101) + (7100)– A shorthand form we’ll also use:

103 102 101 100

3 2 1 7

Page 15: CS/COE0447 Computer Organization & Assembly Language

15

Numbers and Bases in General

• Number Base B B unique values per digit– Base 10: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}– Base 2: {0, 1}– Base 16: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}

• (Unsigned) number representation

– d31d30…d1d0 is a 32-digit non-negative number

– Value = d31B31 + d30B30 + … + d1B1 + d0B0

• N-digit base B BN unique values

Page 16: CS/COE0447 Computer Organization & Assembly Language

16

Example: Base 2 (Binary)

• Digits: 0, 1 (2 of them)• “Binary digit” = “Bit”

• Example:

– 11010two = (124) + (123) + (022) + (121) + (020) = 16 + 8 + 0 + 2 + 0 = 26ten

• Choice for machine implementation!– 1 = on, 0 = off

Page 17: CS/COE0447 Computer Organization & Assembly Language

17

Base Conversion

• Let’s do decimal-to-binary conversion

– Aten = dn-1dn-2…d1d0two

– Given a base-10 number A, come up with n-digit binary number that has the same value!

• X = the number• Let N be the largest power of 2 that fits into X• Put a 1 in that position• X = X – 2^N• Repeat until you are done!

Page 18: CS/COE0447 Computer Organization & Assembly Language

18

Base Conversion, cont’d

• From binary to decimal

• From decimal to binary

• From binary to hexadecimal

• From hexadecimal to binary

• From decimal to hexadecimal? (more complicated; later)

Page 19: CS/COE0447 Computer Organization & Assembly Language

19

Base Conversion, cont’d

• Binary to hex (base 16), or hex to binary base conversion:– Take 4 bits in binary and convert them into one hex digit

and vice versa

• Since binary notation tends to be long, hex notation is frequently used in assembly language (and in C programs).

• More on binary number representation will be discussed when we study arithmetic

Page 20: CS/COE0447 Computer Organization & Assembly Language

20

Before moving on to chapter 2….

• We’ll mention some concepts in program performance, so you have ideas in mind

• The text covers this in the Chapter 1 questions and in Chapter 4. We’ll wait until Chapter 4 to cover this more fully.

Page 21: CS/COE0447 Computer Organization & Assembly Language

21

Program Performance

• Program performance is measured in terms of time!

• Program execution time has to deals with– Number of instructions executed to complete a

job– How many clock cycles are needed to execute a

single instruction– The length of the clock cycle (clock cycle time)

Page 22: CS/COE0447 Computer Organization & Assembly Language

22

Clock, Clock Cycle Time

• Circuits in computers are “clocked”• At each clock rising (or falling) edge, some specified actions

are done, usually within the next rising (or falling) edge• Instructions typically require more than one cycle to execute

Function block(made of circuits)

clock

clock cycle time

Page 23: CS/COE0447 Computer Organization & Assembly Language

23

Program Performance

• time = (# of clock cycles) (clock cycle time)

• # of clock cycles =

(# of instructions executed)

(average cycles per instruction)

• We’ll do specific calculations when we get to Chapter 4.

• But now, let’s move on to Chapter 2