DOC PREVIEW
U of I CS 231 - Lecture notes

This preview shows page 1-2-3-24-25-26 out of 26 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 26 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 26 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 26 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 26 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 26 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 26 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 26 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

ISA 1Instruction set architectures• Last time we built a simple, but complete, datapath.• The datapath is ultimately controlled by a programmer, so today we’lllook at several aspects of this programming in more detail.– How programs are executed on processors– An introduction to instruction set architectures– Example instructions and programs• Next, we’ll see how programs are encoded in a processor. Following that,we’ll finish our processor by designing a control unit, which converts ourprograms into signals for the datapath.ISA 2Programming and CPUs• Programs written in a high-levellanguage like C++ must be compiledto produce an executable program.• The result is a CPU-specific machinelanguage program. This can be loadedinto memory and executed by theprocessor.• CS231 focuses on stuff below thedotted blue line, but machinelanguage serves as the interfacebetween hardware and software.DatapathHigh-level programExecutable fileControl wordsCompilerControl UnitHardwareSoftwareISA 3High-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• Many languages provide safety features as well.– Static and dynamic typechecking– Garbage collection• High-level languages are also relatively portable.Theoretically, you canwrite one program and compile it on many different processors.• It may be hard to understand what’s so “high-level” here, until youcompare these languages with...ISA 4Low-level languages• Each CPU has its own low-level instruction set, or machine language,which closely reflects the CPU’s design.• Unfortunately, this means instruction sets are not easy for humans towork with!– Control flow is limited to “jump” and “branch” instructions, whichyou must use to make your own loops and conditionals.– Support for functions and procedures may be limited.– Memory addresses must be explicitly specified. You can’t justdeclare new variables and use them!– Very little error checking is provided.– It’s difficult to convert machine language programs to differentprocessors.• Later we’ll look at some rough translations from C to machine language.ISA 5Compiling• Processors can’t execute programs written in high-level languagesdirectly, so a special program called a compiler is needed to translatehigh-level programs into low-level machine code.• In the “good” old days, people often wrote machine language programsby hand to make their programs faster, smaller, or both.• Now, compilers almost always do a better job than people.– Programs are becoming more complex, and it’s hard for humans towrite and maintain large, efficient machine language code.– CPUs are becoming more complex. It’s difficult to write code thattakes full advantage of a processor’s features.• Some languages, like Perl or Lisp, are usually interpreted instead ofcompiled.– Programs are translated into an intermediate format.– This is a “middle ground” between efficiency and portability.ISA 6Exampleint main( ){ int a,b,c; scanf ("%d",&a); scanf ("%d",&b); if (a > b) c = a - b; else c = a + b; printf ("c:%d \n", c);}example.cgcc -o example example.ccsil:example42C: 2gcc -S example.ccsil: cat example.s …… ld [%fp+2027], %g4 ld [%fp+2023], %g1 cmp %g4, %g1 ble %icc, .LL2 nop ld [%fp+2027], %g1 ld [%fp+2023], %g4 sub %g1, %g4, %g1 st %g1, [%fp+2019] ba,pt %xcc, .LL3 nopLL2: ld [%fp+2027], %g1 ld [%fp+2023], %g4 add %g1, %g4, %g1 st %g1, [%fp+2019].LL3: ld [%fp+2019], %g1…..ISA 7Imagine writing assembly language …Like most of the early hardware and software systems, Fortran was late in delivery,and didn’t really work when it was delivered. At first people thought it would never bedone. Then when it was in field test, with many bugs, and with some of the mostimportant parts unfinished, many thought it would never work. It gradually got to thepoint where a program in Fortran had a reasonable expectancy of compiling all theway through and maybe even running. This gradual change of status from anexperiment to a working system was true of most compilers. It is stressed here in thecase of Fortran only because Fortran is now almost taken for granted, as it were builtinto the computer hardware. Saul RosenProgramming Languages and SystemsMcGraw Hill 1967In late 1953, John W. Backus submitted a proposal to his superiors at IBM to develop amore efcient alternative to assembly language for programming their IBM 704mainframe computer. …The rst manual for FORTRAN appeared in October 1956, with the rst FORTRANcompiler delivered in April 1957. From the Wikipedia.ISA 8Assembly 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 thesemnemonics and machine instructions, so it is very easy to convertassembly programs to machine language.• We’ll use assembly code this today to introduce the basic ideas, andswitch to machine language next time.ISA 9Data manipulation instructions• Data manipulation instructions correspond to ALU operations.• For example, here is a possible addition instruction, and its equivalentusing 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 10More 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 alsopossible. Constants are denoted with a hash mark in front.ISA 11Relation to the datapath• These instructions reflect the design ofour datapath from last week.• There are at most two source operandsin each instruction, since our ALU hasjust two inputs.• The two sources can be two registers, orone register and one constant.• More complex operations


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?