Midterm #1 Review February 1, 2013 1 / 11 I will provide . . . - - PowerPoint PPT Presentation

midterm 1 review
SMART_READER_LITE
LIVE PREVIEW

Midterm #1 Review February 1, 2013 1 / 11 I will provide . . . - - PowerPoint PPT Presentation

Midterm #1 Review February 1, 2013 1 / 11 I will provide . . . ASCII character encoding table powers of 2 up to 2 15 a list of relevant instructions for assembly problems just the names! you should know the difference between:


slide-1
SLIDE 1

Midterm #1 Review

February 1, 2013

1 / 11

slide-2
SLIDE 2

I will provide . . .

  • ASCII character encoding table
  • powers of 2 up to 215
  • a list of relevant instructions for assembly problems
  • just the names!
  • you should know the difference between: add and addi;

move, lw, sw, and la

  • the interfaces of relevant system calls

2 / 11

slide-3
SLIDE 3

You should bring . . .

  • a pencil and eraser
  • one page of notes (optional)

No calculator!

3 / 11

slide-4
SLIDE 4

Structure of test

Part 1: Computer architecture vocabulary

  • FDX cycle, datapath, control unit, bus
  • multiplexor, control signal, conditional signal, clock
  • program counter, instruction register, register file, ALU
  • memory, text segment, data segment

Part 2: Representing integers and base conversion

  • decimal ⇔ binary
  • binary ⇔ hexadecimal
  • two’s complement representation

4 / 11

slide-5
SLIDE 5

Structure of test

Part 3: Representing strings

  • ASCII character encoding
  • null-terminated strings and null-padding
  • big-endian vs. little endian

Part 4: Integer arithmetic

  • adding and multiplying signed integers

(helpful to understand carryout vs. overflow)

5 / 11

slide-6
SLIDE 6

Structure of test

Part 5: MIPS assembly

  • encode math expressions as sequence of instructions
  • declare variables and constants in data memory
  • how to read and write memory (lw and sw)
  • how to use system calls

6 / 11

slide-7
SLIDE 7

Representing integers and base conversion

Assume all integers are signed and in big-endian form

  • Use two’s complement notation for negative numbers

Exercises

  • 1. Convert decimal 102 into an 8-bit integer in binary
  • 2. Convert decimal -102 into an 8-bit integer in binary
  • 3. Convert decimal -844 into a 16-bit integer in binary
  • 4. Write decimal -844 as a 16-bit integer in hexadecimal
  • 5. Convert signed 16-bit integer 0xFACE into decimal

Powers of 2 n 1 2 3 4 5 6 7 8 9 10 . . . 2n 1 2 4 8 16 32 64 128 256 512 1024 . . .

7 / 11

slide-8
SLIDE 8

Representing strings

ASCII character encodings Assume 32-bit words and addressable bytes (as in MIPS) Encode “Aye, aye!” as a null-terminated ASCII string

  • using big-endian byte ordering
  • using little-endian byte ordering

(Give each byte in hexadecimal)

8 / 11

slide-9
SLIDE 9

Binary arithmetic

Assume all numbers are signed, 8-bit integers For each arithmetic expression:

  • 1. convert the arguments to binary
  • 2. perform the operation on the binary representation
  • 3. convert back to hexadecimal
  • 0x53 + 0x1B
  • 0xB3 + 0xE9
  • 0x0B × 0x06

← multiply!

9 / 11

slide-10
SLIDE 10

Assembly programming

# Pseudocode: # c = (a+3) * (b-2) + a # Register mappings: # a: $t0 # b: $t1 # c: $t2

Instructions you may need:

  • li, add, addi, sub, subi, mul
  • note: mul is a macro instruction that takes three registers:

mul $t0,$t1,$t2 # hi,lo = $t1 * $t2; $t0 = lo

  • you can assume result is 32-bits (hi = 0)

10 / 11

slide-11
SLIDE 11

Assembly programming (solution)

# Pseudocode: # c = (a+3) * (b-2) + a # Register mappings: # a: $t0, b: $t1, c: $t2 # tmp1: $t3, tmp2: $t4, tmp3: $t5

+ + * a 3 a

  • b

2 tmp1 tmp2 tmp3

addi $t3, $t0, 3 # tmp1 = a+3 subi $t4, $t1, 2 # tmp2 = b-2 mul $t5, $t3, $t4 # tmp3 = tmp1 * tmp2 add $t2, $t5, $t0 # c = tmp3 + a

Register optimization (optional)

addi $t3, $t0, 3 # tmp1 = a+3 subi $t2, $t1, 2 # c = b-2 mul $t2, $t3, $t2 # c = tmp1 * c add $t2, $t2, $t0 # c = c + a

11 / 11