1 / 31

What we want: execute H igh L evel L anguage ( HLL ) programs What we have: computer hardware

What we want: execute H igh L evel L anguage ( HLL ) programs What we have: computer hardware (a glorified calculator). Machine Code. Assembly Language. computer hardware: executes instructions written in machine language. assembler. assembly language. HLL source code. compiler.

Download Presentation

What we want: execute H igh L evel L anguage ( HLL ) programs What we have: computer hardware

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What we want: execute High Level Language (HLL) programs What we have: computer hardware (a glorified calculator)

  2. Machine Code

  3. Assembly Language

  4. computer hardware: executes instructions written in machine language assembler assembly language HLL source code compiler

  5. C source code C++ source code compiler Pascal source code compiler Fortran source code compiler compiler assembly language assembler machine code

  6. assembly language assembler machine code MIPS R2000 assembly language (with occasional x86 examples) the focus ofthis class

  7. VonNeumann Diagram CPU memory I/O CPU  processor  P

  8. Stored Program Concept memory Program Variables

  9. 00000.......00... 3012 11000.......01... 3013 3014 contents at address 3013 8056 8057 addresses memory: 9

  10. processor must fetch instruction load an operand store an operand (a result) • memory can read (given an address) write (given an address) • Therefore, fetch and load are read memory accesses, and store is a write memory access.

  11. mult aa, bb, cc The number of operands is fixed for each unique mnemonic (instruction). The meaning of the order of the operands is fixed. For this example, it could be aa bb * cc or cc aa * bb

  12. 00000.......00010 machine code formult aa, bb, cc somewhere in memory: 12

  13. To fetch and execute a single instruction, FETCH THE INSTRUCTION (do a read memory access)

  14. DECODE THE INSTRUCTION • look at the machine code to find the field representing the mnemonic (also called the op code), such that the processor knows what instruction it is executing • this also specifies the number of operands • for this example,it is a multiply instruction,and so there are 3 operands

  15. LOAD THE OPERANDS • this could be 2 steps (for 2 operands) • read memory accesses • load only necessary operandsread at address bbread at address cc

  16. DO THE INSTRUCTION'S OPERATION • most often an arithmetic operation applied to the loaded operands • for the multiply instruction,the loaded operand value for bb is multiplied by the loaded operand for cc

  17. STORE THE RESULTS • the result of the operation needs to go somewhere, so put it there! • for the multiply instruction,store the computed product at the memory location represented by aa

  18. programs contain many sequential instructions . . . 21 instr 1 instr 2 22 instr 3 23 instr 4 24 addresses

  19. Program Counter • usually called the PC • value maintained by the processor • the address of the next instruction to be fetched • Intel's terminology:Instruction pointer, or IP

  20. Instruction Fetch and Execute Cycle • fetch instruction • update PC • decode • load operands • do the operation • store result(s)

  21. Control Instructions • a category of instructions that may modify the PC, other than to update it • invented code example:here: beq x, y, elsewhere add z, y, xelsewhere: mult aa, bb, cc

  22. Possible instruction sequences: 1. if x equals ybeq x, y, elsewheremult aa, bb, cc 2. if x does not equal ybeq x, y, elsewhereadd z, y, xmult aa, bb, cc

  23. For this instruction,if x equals y, then 6. store result(s) places the third operand (the address elsewhere) into the PC

  24. beq x, y, elsewhere 564 add z, y, x 565 mult aa, bb, cc 566 (x) 8004 300 (y) 9300 300 addresses

  25. The name that architectures give to the control instructions is most often • branch • jump In functionality, a further categorization is • conditional • unconditional

  26. condition codes An alternative, but equivalent method for implementing control instructions A processor will have a minimum of 2 boolean variables • zero • negative

  27. step 6. store resultsalso changes the condition codes For example: add x, y, z if y = 1 and z = 2 then x is set to 3 and zero is set to Falsenegative is set to False

  28. bpos elsewhere if zero is False and negative is False then PC  elsewhere Must order the instructions such that the correct one to set the condition codes is directly before the one that depends on it . . .

  29. Just for fun: Invent instructions and write assembly language code to do: for (i = 1; i < 10; i++ ) { a = a + i; }

  30. Karen's first solution move i, 1 for: bge i, 10, end_for add a, a, i add i, i, 1 b for end_for: # next instruction would # go here

  31. Karen's condition codes solution move i, 1 for: compare i, 10 # sets C.C. bgez end_for add a, a, i add i, i, 1 b for end_for: # next instruction would # go here

More Related