Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Review Chpt 2 and 3 Five components of a computer Input Output Memory Arithmetic & Logic Unit (ALU) Control Two types of information Data and instruction.

Similar presentations


Presentation on theme: "1 Review Chpt 2 and 3 Five components of a computer Input Output Memory Arithmetic & Logic Unit (ALU) Control Two types of information Data and instruction."— Presentation transcript:

1 1 Review Chpt 2 and 3 Five components of a computer Input Output Memory Arithmetic & Logic Unit (ALU) Control Two types of information Data and instruction

2 2 Think of a Calculator Components in a calculator Input Output Memory ALU One type of information Data

3 3 Memory in Calculator One register R, which is implicit Its content is shown at the LCD panel Arithmetic operations are performed on R One memory M, which is explicit Its content is not shown. Arithmetic operation on M is limited M is additional storage in case R is not enough Copy data from R to M is done by MS Copy data from M to R is done by MR

4 4 Memory in Computer (MIPS) More registers 32 integer registers: $0 to $31 32 floating-point registers: $f0 to $f31 More memory 4 Giga Byte (GB) memory, organized as 1 Gita Word A word is 32 bits (b), a Byte (B) is 8 bits A unique address is designated for each memory byte 1K=1024=2 10, 1M=1024K=2 20, 1G=1024M=2 30

5 5 Examples Which one can store more information: a 128MB memory card or a half Gb memory chip? How many times more data can a 40GB hard disk store than a 256KB memory?

6 6 Memory Address 00000004 FFFFFFFC 00000000 00000008 FFFFFFF8 0123...

7 7 Example: Memory content chara:.word 0x00000061# assume starting mem 0 msg1:.asciiz “ab01cd” msg2:.ascii “ab” value:.word 15 00 61 31306261 006463 ?? 62 00 0F 00000004 00000000 00000008 0123 0000000C 00000010...

8 8 Data and Instruction Memory contains data and instruction The content itself does not tell if it is data or instruction Each instruction takes one word, and instruction address must be a word address

9 9 Data Encoding ASCII code (American Standard Code for Information Interchange) Total 128 characters, including digits (0-9) alphabets (a-z, A-Z) math (+, -, *, /, >, <, =, (, ), {, }, [, ], %) punctuations (!,,,., ?, :, ;, ‘, “, `,,) special (@, #, $, ^, &, ~, _, |, \) control (back space, tab, line return, null)

10 10 Data Encoding Unicode (universal encoding) Capable of expressing most languages in the world TextASCIIUTF-8UTF-16 big62 69 67 0062 0069 0067 gro  67 72 6f ??67 72 6f c3 9f0067 0072 006f 00df

11 11 Data Encoding Fixed point integer Single precision floating point Double precision floating point Question: Which format is most efficient in expressing a number, say 12345678? How about 1234.5678? ASCII character string Fixed point Floating point

12 12 Example on Numbers What is the following hexadecimal? 8D280000 as binary: 1000 1101 0010 1000 0000 0000 0000 0000 8D280000 as integer (in decimal): -(2^27+2^26+2^24+2^21) 8D280000 as floating-point (in decimal): 1000 1101 0010 1000 0000 0000 0000 0000 (-1) 2^{26-127}*(1+0.025+0.0625)= 8D280000 as instruction: 1000 1101 0010 1000 0000 0000 0000 0000 lw $8 0($9)

13 13 Word v.s. Byte Memory can be addressed either as words, each 32 bits, or as bytes, each 8 bits Whether an address is word address or byte address depends on the instruction lw $a1, 0($zero)# $a1 = 00 00 00 61 lw $a1, 2($a2)# assume $a2=6 # $a1 = 61 00 64 63 lbu $a1, -7($a2)# assume $a2=12 # $a1 = 00 00 00 62

14 14 ALU In a calculator, ALU performs operation between R and the new number typed on key pad 12+ enter 12 into R and operation is + 3= enter 3, and perform addition with R In a computer, ALU performs more complex operations between registers

15 15 Example Convert temperature from Fahrenheit in $f0 to Celsius: C=(5/9)*(F-32) Assume 5.0 is in $f16, 9.0 is in $f17, and 32.0 is in $f18 div.s $f16, $f16, $f17#.s is single precision sub.s $f0, $f0, $f18 mul.s $f0, $f0, $f16 Puzzle: How to swap values in $a1 and $a2 without using additional register?

16 16 Fixed Point Mult/Div Assume F temperature is in $a0, store C temperature result in $a1 addi$a1, $a0, -32# $a1 = F-32 addi$t0, $zero, 5# $t0 = 5 mult$a1, $t0# mult first reduces error mflo$a1# $a1 = (F-32)*5 addi$t0, $zero, 9# $t0 = 9 div$a1, $t0 mflo$a1

17 17 IEEE 754 Standard Exception Normal case e=1 to 254: (-1) S * 2 e-127 * 1.M Special cases: Exponent=0, mantissa=0: 0 Exponent=0, mantissa  0: denormalized (-1) S * 2 -127 * 0.M Exponent=255, mantissa=0:  Infty Exponent=255, mantissa  0: NaN

18 18 Control In a calculator, human controls the operation at each step In a computer, control follows from the instruction 1. Program Counter (PC) points to the first instruction to be executed 2. Execute the instruction pointed by PC 3. PC=PC+4, go to 2 If there is branch instruction, PC is modified

19 19 Exercise Count the number of 1’s in $a0 and store result in $s0 or $s0, $zero, $zero# $s0=0 addi $t0, $zero, 1# $t0=00000001 loop:beq $t0, $zero, exit# if $t0=0, exit and $t1, $a0, $t0# check one bit sll $t0, $t0, 1# shift $t0 left 1 bit beq $t1, $zero, loop addi $s0, $s0, 1# found a 1 j loop exit:

20 20 Five Address Modes (p. 101) Address Mode tells where to find the data or branch address Immediate addressing It is rather “immediate” than “addressing” since the data is included in the instruction For example, addi $a1, $a1, 100 Register addressing Data address is register number For example, add $a1, $a1, $a0

21 21 Five Addressing Mode (cont’d) Base (or displacement) addressing Data address is base (register content) plus displacement For example, lw $a1, 12($a0)

22 22 Five Addressing Mode (cont’d) The last two modes are for branch only. Address is instruction address. PC-relative addressing Branch address is PC+4+offset*4 For example, beq $a1, $zero, 100 Pseudo-direct addressing Branch address is 26 bits in instruction concatenated with top 4 bits of PC For example, j 10000

23 23 Addressing Mode Example C program, assume i and k correspond to $s3 and $s5, and base address of array a is in $s6: while (a[i] == k) i = i + 1; MIPS assembly code loop:sll $t1, $s3, 2# $t1 = i*4 add $t1, $t1, $s6# $t1 = addr of a[i] lw $t0, 0($t1)# $t0 = a[i] bne $t0, $s5, exit# if a[i] != k, exit addi $s3, $s3, 1# i = i+1 j loop# go to loop

24 24 Addressing Mode Example loop:sll $t1, $s3, 2# $t1 = i*4 add $t1, $t1, $s6# $t1 = addr of a[i] lw $t0, 0($t1)# $t0 = a[i] bne $t0, $s5, exit# if a[i] != k, exit addi $s3, $s3, 1# i = i+1 j loop# go to loop exit 0019920 09229032 35980 58212 819 1 21111 1111 1111 0000 0000 0000 01 FFFF0004 FFFF0008 FFFF000C FFFF0010 FFFF0014 FFFF0018

25 25 Homework 2, due Friday 2.21, 2.36 3.27, 3.42

26 26 Exercise 2.21 Write a subroutine convert to convert an ASCII decimal string to an integer. You can expect register $a0 to hold the address of a null-terminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character, including “-” or “.”, appears anywhere in the string, your program should stop with the value –1 in register $v0. For example, if register $a0 points to a sequence of three character 50 ten, 52 ten, 0 ten (the null-terminated string “24”), then when the program stops, register $v0 should contain the value 24 ten.

27 27 Exercise 2.36 Consider the following fragment of C code: for (i=0; i<=100; i=i+1) a[i] = b[i] +c; Assume that a and b are arrays of words and the base address of a is in $a0 and the base address of b is in $a1. Register $t0 is associated with variable i and register $s0 with c. Write the code for MIPS. How many instructions are executed during the running of this code? How many memory data references will be made during execution?

28 28 Chapter 4 Performance What is performance? Response time: The time between start and completion of the task. (unit is time, say sec) Throughput: the total amount of work done at a given time. (unit is jobs/sec) Do the following changes to a computer system increase/decrease performance? Replacing the processor by a faster one Adding additional processors to a multi-processor system, such as google search engine


Download ppt "1 Review Chpt 2 and 3 Five components of a computer Input Output Memory Arithmetic & Logic Unit (ALU) Control Two types of information Data and instruction."

Similar presentations


Ads by Google