Review Chpt 2 and 3 - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Review Chpt 2 and 3

Description:

Memory in Calculator. One register R, which is implicit. Its content ... In a calculator, ALU performs operation between R and the new number typed on key pad ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 29
Provided by: Weipi2
Learn more at: http://dropzone.tamu.edu
Category:

less

Transcript and Presenter's Notes

Title: Review Chpt 2 and 3


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
Think of a Calculator
  • Components in a calculator
  • Input
  • Output
  • Memory
  • ALU
  • One type of information
  • Data

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
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
  • 1K1024210, 1M1024K220, 1G1024M230

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
Memory Address
0
1
2
3
00000000
00000004
00000008
...
FFFFFFF8
FFFFFFFC
7
Example Memory content
  • chara .word 0x00000061 assume starting mem 0
  • msg1 .asciiz ab01cd
  • msg2 .ascii ab
  • value .word 15

0
1
2
3
00000000
00000004
00000008
0000000C
00000010
...
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
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 (_at_, , , , , , _, , \)
  • control (back space, tab, line return, null)

10
Data Encoding
  • Unicode (universal encoding)
  • Capable of expressing most languages in the world

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
Example on Numbers
  • What is the following hexadecimal?
  • 8D280000 as binary
  • 1000 1101 0010 1000 0000 0000 0000 0000
  • 8D280000 as integer (in decimal)
  • -(227226224221)
  • 8D280000 as floating-point (in decimal)
  • 1000 1101 0010 1000 0000 0000 0000 0000
  • (-1) 226-127(10.0250.0625)
  • 8D280000 as instruction
  • 1000 1101 0010 1000 0000 0000 0000 0000
  • lw 8 0(9)

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 a26
  • a1 61 00 64 63
  • lbu a1, -7(a2) assume a212
  • a1 00 00 00 62

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
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
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
IEEE 754 Standard Exception
  • Normal case
  • e1 to 254 (-1)S 2e-127 1.M
  • Special cases
  • Exponent0, mantissa0 0
  • Exponent0, mantissa?0 denormalized
  • (-1)S 2-127 0.M
  • Exponent255, mantissa0 ?Infty
  • Exponent255, mantissa ?0 NaN

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. PCPC4, go to 2
  • If there is branch instruction, PC is modified

19
Exercise
  • Count the number of 1s in a0 and store result
    in s0
  • or s0, zero, zero s00
  • addi t0, zero, 1 t000000001
  • loop beq t0, zero, exit if t00, 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
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
Five Addressing Mode (contd)
  • Base (or displacement) addressing
  • Data address is base (register content) plus
    displacement
  • For example, lw a1, 12(a0)

22
Five Addressing Mode (contd)
  • The last two modes are for branch only. Address
    is instruction address.
  • PC-relative addressing
  • Branch address is PC4offset4
  • 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
Addressing Mode Example
  • C program, assume i and k correspond to s3 and
    s5, and base address of array a is in s6
  • while (ai k)
  • i i 1
  • MIPS assembly code
  • loop sll t1, s3, 2 t1 i4
  • add t1, t1, s6 t1 addr of ai
  • lw t0, 0(t1) t0 ai
  • bne t0, s5, exit if ai ! k, exit
  • addi s3, s3, 1 i i1
  • j loop go to loop

24
Addressing Mode Example
  • loop sll t1, s3, 2 t1 i4
  • add t1, t1, s6 t1 addr of ai
  • lw t0, 0(t1) t0 ai
  • bne t0, s5, exit if ai ! k, exit
  • addi s3, s3, 1 i i1
  • j loop go to loop
  • exit

FFFF0004
FFFF0008
FFFF000C
FFFF0010
FFFF0014
FFFF0018
25
Homework 2, due Friday
  • 2.21, 2.36
  • 3.27, 3.42

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 50ten , 52ten , 0ten (the
    null-terminated string 24), then when the
    program stops, register v0 should contain the
    value 24ten .

27
Exercise 2.36
  • Consider the following fragment of C code
  • for (i0 i
  • ai bi 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
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
Write a Comment
User Comments (0)
About PowerShow.com