Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 136 Lab 1: 135 Review.

Similar presentations


Presentation on theme: "CSCI 136 Lab 1: 135 Review."— Presentation transcript:

1 CSCI 136 Lab 1: 135 Review

2 Our machine uses 32 bit memory addresses.
A memory address refers to a single byte in memory. (“Byte Addressable”) 0x Memory 0xFFFFFFFF

3 But our data path out of memory is designed to move 32 bit words (or multiples of 32 bits) at a time. 0x Data Path Memory 0xFFFFFFFF Life is simpler and we get MUCH better performance if we divide memory in to 4 byte chunks (“words”) and always access these word size chunks.

4 00 This is called “Word Alignment” Memory
0x Data Path Memory 0xFFFFFFFF An address is “word aligned” if its 2 least significant bits are 0… (and thus is divisible by 4) 00 Disclaimer: You can use lb (load byte) and sb (store byte) to get a specific byte… but these commands are slow and often use lw (load word) and sw (store word) “inside the machine” along with a couple other commands to implement lb and sb.

5 Accessing Bytes When might we use lb (load byte) and sb (store byte)?

6 Assume 32 bit word: Big Endian vs. Little Endian
Byte Ordering Assume 32 bit word: Big Endian vs. Little Endian Byte address: 0x Byte address: 0x Byte address: 0x Byte address: 0x On a Big Endian machine the Most Significant Byte (MSB) of a 32 bit word is stored at the lowest memory address. What is this number on a Big Endian machine?

7 Byte Ordering Byte address: 0x Byte address: 0x Byte address: 0x Byte address: 0x On a Little Endian machine the Most Significant Byte (MSB) of a 32 bit integer is stored at the highest memory address. What is the above integer on a Little Endian machine? Byte address: 0x Byte address: 0x Byte address: 0x Byte address: 0x What is the above integer on a Little Endian machine? What is it on a Big Endian machine?

8 Byte Ordering Computer designers can’t seem to agree on whether to use Big Endian or Little Endian. Neither design is really superior to the other. What kind of Endian are Intel PCs? What kind of Endian are Macs? Sun SPARC Stations can be set in either mode… (but Solaris OS requires Big Endian). Most of the time.. you probably won’t notice Endianness. But SPIM simulator uses the “Endianness” of the machine you run it on!

9 Where does it matter? When does “Endianness” matter?
We will grade projects using PCSpim. If you use a Mac or XSPIM on Sun, make sure you test on a PC before submitting.

10 Load Immediate (li) li $t0, 4 lui $t0, 0 ori $t0, $t0, 4
What does the following instruction do? li $t0, 4 What does the following sequence of instructions do? lui $t0, 0 ori $t0, $t0, 4

11 li (load immediate) instruction is really “pseudocode”
When the assembler sees an li instruction it substitutes: lui (load upper immediate) followed by an ori (or immediate) In the place of the li (load immediate) We’ll use li in the next few examples

12 Binary and Hex Review What is 0xAF (32 bit word) in decimal?
What is 23 in binary?

13 2’s Complement Numbers To get negative number from a positive.. Invert all digits and add 1. To get a positive number from a negative… Invert all digits and add 1. Assume 8 bit word. What is -57 in 2’s complement notation? How do we do change a number’s sign in assembly language?

14 Sign Extension Sign extension can be used when you shift a register right… the sign bit is repeated to keep a negative number negative… This is referred to as “Arithmetic” variety of shift If the sign bit isn’t extended.. (i.e. empty spots filled with 0s) then the shift is called “Logical” variety of shift

15 Assume 8 bit words… What is result of logical right shifting -11 by 2? assembly: srl (shift right logical) srlv (shift right logical variable) What is result of arithmetic right shift -11 by 2? assembly: sra (shift right arithmetic) srav (shift right arithmetic variable) What is result of rotate right -11 by 2? assembly: ror (rotate right) What is the assembly code to do this?

16 What is result of rotating left -11 by 2?
assembly: rol (rotate left) What is the result of logical shift left -11 by 2? assembly: sll (shift left logical) sllv (shift left logical variable) What is the assembly code to do this? Why isn’t there a sla (shift left arithmetic) assembly instruction?

17 Useful Shifts Considering an 8 bit word… how would we compute dividing -6 by 2? Consider an 8 bit word… how would we compute multiplying -7 by 4?

18 Useful Shifts Shifts are fast. Compilers will often substitute shifts for multiplication and division of integers by powers of 2. Note that rotate instructions require that rotation amount be supplied by a register. There is no “shift amount” constant value in a rotate instruction.

19 MIPS Adding and Subtracting
What does following instruction do? add $t1, $t2, $t3 How about the following? addi $t1, $t2, 4 sub $t1, $t2, $t3

20 What is Overflow? Consider unsigned 8 bit integers.. What happens when we add 0x73 and 0xA9 ? Can we get overflow when we add a positive and a negative number? Consider signed 8 bit (2’s complement) integers.. what happens when we add 0xBC and 0xB0?

21 Multiplication Math Review
What is result of multiplying unsigned integers 0xF and 0xF? If we multiply two 32 bit unsigned integers… what is the size in bits of the largest possible result?

22 Multiplication Instruction
What does the following do? mul $t2, $t3 What do mfhi (move from hi) and mflo (move from lo) instructions do? What does the following instruction do? mul $t5, $t7, $t3

23

24 Memory Space In our SPIM simulator memory space, what percentage of our memory is reserved for the OS? With 32 bit addresses and byte addressing… how much memory can our machine have?

25

26 Offsets in lw and sw In our lw (load word) and sw (store word) instructions we can only supply a 16 bit offset. This offset is sign extended. What does this command do? lw $s0, 0x0004($t0) lw $s0, 0xFFFC($t0) How many bytes can offset?

27 Global Pointer ($gp) Where does our data segment begin?
If we want to load the word stored at 0x the following code would be required: lui $s0,0x1001 # What does this do? lw $s1,0x0020($s0) # and this? This is kind of inefficient. We’re always using 2 instructions to read any word in the data segment (example from Hennessy et al. page A-21)

28 Solution Register $gp (decimal number 28) holds the constant value 0x This allows us to offset back 32k bytes to the beginning of the data segment. Or offset forward 32k bytes. To load the word stored at 0x we can use: lw $s1, 0x8020 ($gp)

29 Offsets in Branch and Jump instructions
In load word and store word instructions the 16 bit offset field of instruction counted number of bytes. In branch (16 bit offset field) and jump (26 bit offset field) the offset fields count the number of instructions to offset. Since instructions are 4 bytes.. This is also the number of words to offset…

30 Time Units How long is a microsecond? How long is a nanosecond?
How long is a picosecond? If a clock runs at 450MHZ how long is a clock cycle? If a clock runs at 1.2GHZ how long is clock cycle?

31 Cycles Per Instruction
Different Instructions may take different numbers of clock cycles to execute. CPI (Cycles Per Instruction) refers to number of clock cycles an instruction takes in a design What is average CPI of the following 600 MHZ machine? What is the MIPS rating? Instruction Class CPI Freq Load Word % Store Word % ALU (R format) % Branch % Jump %

32 Registers $s0,$s1,…,$s7 (16 through 23) are “callee saved”.
What does this mean? Notes on Stack Pointer: Our stack pointer will always point to the last word in the stack. In the real world, the stack pointer occasionally points to the next free space below the stack.


Download ppt "CSCI 136 Lab 1: 135 Review."

Similar presentations


Ads by Google