DOC PREVIEW
U of I CS 231 - Lecture notes

This preview shows page 1-2-3-19-20-38-39-40 out of 40 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 40 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Today's AgendaProgramming and CPUsHigh-level languages vs Low Level LanguagesAssembly and machine languagesData manipulation instructionsMore data manipulation instructionsRelation to the Datapath and hence the restrictionsLoading a register from RAMStoring a register to RAMLoading a register with a constantStoring a constant to RAMThe # and ( ) are important!A small exampleA simple questionA jump instruction always changes the value of the PC. The operand specifies exactly how to change the PC. For simplicity, we often use labels to denote actual addresses. For example, a program can skip certain instructions. You can also use jumps to repeat instructions.BranchesTypes of branchesWe can use branch instructions to translate high-level conditional statements into assembly code. Sometimes it’s easier to invert the original condition. Here, we effectively changed the R1 < 0 test into R1 >= 0.Translating the C for loopWrite the assembly code for the given C programThe assembly code for the program given on the previous pageSumming up…Block diagram of a processorA specific instruction setFrom assembly to machine languageRegister formatImmediate formatJump and branch formatInstruction format uniformityInstruction formats and the datapathThe usual beaten to death questionOrganizing our instructionsRegister format ALU operationsMemory write operationsSelecting opcodesALU and shift instructionsBranch instructionsSample opcodesConvert the following assembly program to machine codeSummaryISA 1Today's Agenda•Instruction Set Architecture: assembly language•Instruction Set Encoding: machine language•Things to remember–HW9 is due immediately after the thanks giving break(on Monday, 26th november)–HW 10.1 and 10.2 will be released this week.–All the numbers in the assembly instructions in hw9 are in DECIMAL.ISA 2Programming and CPUs•Programs written in a high-level language like C++ must be compiled to produce an executable program.•The result is a CPU-specific machine language program. This can be loaded into memory and executed by the processor.•CS231 focuses on stuff below the dotted blue line, but machine language serves as the interface between hardware and software.DatapathHigh-level programExecutable fileControl wordsCompilerControl UnitHardwareSoftwareISA 3High-level languages vs Low Level Languages•High-level languages provide many useful programming constructs.–For, while, and do loops–If-then-else statements–Functions and procedures for code abstraction–Variables and arrays for storage–Static and dynamic typechecking–Garbage collection•High-level languages are also relatively portable.Theoretically, you can write one program and compile it on many different processors.•On the other hand Low Level Languages provided none of those, but..•thats the only thing the CPU would understand•Hence the job of compilers which convert a high level language into low machine level codeISA 4Assembly and machine languages•Machine language instructions are sequences of bits in a specific order. •To make things simpler, people typically use assembly language.–We assign “mnemonic” names to operations and operands.–There is (almost) a one-to-one correspondence between these mnemonics and machine instructions, so it is very easy to convert assembly programs to machine language.•We’ll use assembly code this today to introduce the basic ideas, and switch to machine language next time.•But always remember Assembly Language is NOT Machine Language.ISA 5Data manipulation instructions•Data manipulation instructions correspond to ALU operations. •For example, here is a possible addition instruction, and its equivalent using our register transfer notation:•This is similar to a high-level programming statement likeR0 = R1 + R2•Here, all of the operands are registers.ADD R0, R1, R2operationdestination sourcesoperandsR0  R1 + R2Register transfer instruction:ISA 6More data manipulation instructions•Here are some other kinds of data manipulation instructions.NOT R0, R1 R0  R1’ADD R3, R3, #1 R3  R3 + 1SUB R1, R2, #5 R1  R2 - 5•Some instructions, like the NOT, have only one operand.•In addition to register operands, constant operands like 1 and 5 are also possible. Constants are denoted with a hash mark in front.ISA 7Relation to the Datapath and hence the restrictions•Recall that our ALU has direct access only to the register file.•There are at most two source operands in each instruction, since our ALU has just two inputs.•The two sources can be two registers, or one register and one constant.•Instructions have just one destination operand, which must be a register.•RAM contents must be copied to the registers before they can be used as ALU operands.•Similarly, ALU results must go through the registers before they can be stored into memory.•We rely on data movement instructions to transfer data between the RAM and the register file.D data Write D address A address B addressA data B dataRegister FileWRDAAA BAQ D1 D0 S RAM ADRS DATA CS WROUTMW+5VA BALUFZNCVFSFS MDS D1 D0 Q Constant MBISA 8Loading a register from RAM•A load instruction copies data from a RAM address to one of the registers.LD R1,(R3) R1  M[R3] •Remember in our datapath, the RAM address must come from one of the registers—in the example above, R3.•The parentheses help show which register operand holds the memory address.D data Write D address A address B addressA data B dataRegister FileWRDAAA BA RAM ADRS DATA CS WROUTMW+5VA BALUFZNCVFSFS MDS D1 D0 Q Constant MBQ D1 D0 SISA 9Storing a register to RAM•A store instruction copies data from a register to an address in RAM.ST (R3),R1 M[R3]  R1•One register specifies the RAM address to write to—in the example above, R3.•The other operand specifies the actual data to be stored into RAM—R1 above.Q D1 D0 SA BALUFZNCVFSFS MDS D1 D0 Q Constant MB RAM ADRS DATA CS WROUTMW+5VD data Write D address A address B addressA data B dataRegister FileWRDAAA BAISA 10Loading a register with a constant•With our datapath, it’s also possible to load a constant into the register file:LD R1, #0 R1  0 •Our example ALU has a “transfer B” operation (FS=10000) which lets us pass a constant up to the register file.•This gives us an easy way to initialize registers.D data Write D address A address B addressA data B dataRegister FileWRDAAA BAQ D1 D0 S RAM ADRS DATA CS


View Full Document

U of I CS 231 - Lecture notes

Documents in this Course
Counters

Counters

23 pages

Latches

Latches

22 pages

Lecture

Lecture

33 pages

Lecture

Lecture

16 pages

Lecture

Lecture

4 pages

Datapaths

Datapaths

30 pages

Lecture

Lecture

6 pages

Registers

Registers

17 pages

Datapaths

Datapaths

28 pages

Decoders

Decoders

20 pages

Load more
Download Lecture notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?