180 likes | 285 Views
CS 300 – Lecture 19. Intro to Computer Architecture / Assembly Language C Coding & The Simulator Caches. A Test. We'll have a test on Thursday. 45 minutes. Open book / notes but no computing allowed. You'll need to understand MIPS programming and C. Also numeric stuff.
E N D
CS 300 – Lecture 19 Intro to Computer Architecture / Assembly Language C Coding & The Simulator Caches
A Test We'll have a test on Thursday. 45 minutes. Open book / notes but no computing allowed. You'll need to understand MIPS programming and C. Also numeric stuff. We'll review the worksheet and Quicksort before the test. You WILL be writing code!
Assembly Language Coding Why is assembly language so hard? The instructions are so far removed from what's really going on. It's up to you to place GOOD comments in your code so that others can read it. And so you can understand it too. Remember this on the test!
Good / Bad Comments The bad: (from an anonymous student) j done # Jump to done addi $s2, $s1, 1 # increment $s1 into $s2 The good: addi $s2, $zero, 1 # set flag to say a swap happened noswap: addi $s0, $s0, 4 # bump pointer to next element of arr ($s0) addi $s1, $s1, -1 # number of remaining compares
What's The Problem? * Registers don't have names that make sense – if you increment $s1, what's really in $s1? * Control flow is hard to understand: refer back to C code, use good labels, state what condition the program is in at a code point * Data structures are implicit: relate your code to C level structures to make it more readable.
Optimizing Quicksort How fast can we make quicksort run? As assembly language programmers we have a lot of control over this … What are some concrete ideas? How do these ideas translate into compiler optimizations?
Next Homework This is a C project that will last two weeks – I'll collect it on the 21st. There will be a turnin next week to demonstrate progress – I will get the details in the wiki. Will anyone be gone Thanksgiving week?
A Mini Homework This will be due Thursday. It's mainly to help you with the test – I won't grade it in detail but you do have to turn it in. Let's do a few problems in class.
Writing Your Own SPIM Need to decode and execute NOVA instructions. We'll skip the IO instructions except for a few special ones. Two basic instructions: arithmetic (add, subtract, …) memory reference (LDA, STA, JMP, JSR, ISZ, DSZ)
Machine Layout 16 Bit Architecture 4 Registers: 0,1,2,3 1 "Carry bit" PC (15 bits) Memory: 15 bit address (max is 32K words), 16 bits per word.
Arithmetics Instruction layout: Op code (1 bit) (topmost bit = 1) Source AC (2 bits) (AC number) Destination AC (2 bits) (AC Number) Arithmetic function (3 bits) (ADD, SUB, ADC, MOV, INC, COM, NEG) Initial carry (2 bits) (O, Z, C) Shift (2 bits) (L, R, S) Skip condition (3 bits) (SZR, SNR, SZC, SNC, SEZ, SBN, SKP) No Load (1 bit) (#)
Memory References Address: 8 bit unsigned (page 0) or 8 bit signed + PC / AC2 / AC3 Indirect addressing (@) uses top bit of an address
Functionality * Load programs into memory * Start at a given address * Inspect processor state * Set a breakpoint (one will be enough) * Simple IO (just printing a character) * Statistics (# of instructions executed) * Performance of your C code is important!
The Memory Hierarchy This is an essential part of the course … How do we manage storage? Where is the storage? * Network (the entire WWW!) * Disk (may cache network) * Memory (may cache disk) * On chip / off chip caches * Registers Each is smaller / faster than the one above.
Prediction Storage strategies often need to predict what will happen next: * If a program opens a file, it usually needs to read it starting at the beginning * If a program reads a memory address, it will likely use adjacent addresses too * If a program writes a memory address it will usually read the value again soon Hardware / software often has to take a guess at what will happen next.
Locations We address data using locations (pointers). These may refer to url, disk, memory word, or register number. Locations have to work "correctly" when a value is shared in any way. The operation of the storage device requires that readers see what the most recent writer has written.
Cache A cache replicates a portion of a larger memory. It makes use of the fact that most references are to a relatively small number of locations.