programmer's view on computer architecture by istvan haller
DESCRIPTION
Programmer's view on Computer Architecture by Istvan Haller. Basic purpose of a processor (CPU). Perform computations between data. Addition of a feed-back loop. Temporary storage to reuse computations. Registers. Registers allow reuse of computations Efficiency ↔ Keep data on processor - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/1.jpg)
Programmer's view on Computer Architecture
by Istvan Haller
![Page 2: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/2.jpg)
Basic purpose of a processor (CPU)● Perform computations between data
![Page 3: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/3.jpg)
Addition of a feed-back loop● Temporary storage to reuse computations
![Page 4: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/4.jpg)
Registers● Registers allow reuse of computations● Efficiency ↔ Keep data on processor● Uniquely addressable by name● Multiple types
– General purpose: managed explicitly by program– Special purpose: implicit usage
● Some can be accesses explicitly as-well
![Page 5: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/5.jpg)
Set up and forget → Memory● Minimize user interaction through storage
![Page 6: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/6.jpg)
Content of memory● Commands to be executed (instructions)● Input data ← What does the application
need?● Output data ← Final result of computations● Temporary data ← Registers are limited
![Page 7: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/7.jpg)
Accessing memory● Memory is contiguous string of bytes
– No structure!!!– Structure is defined through usage
● Access based on address ← Offset in memory
● Can be both read or written
![Page 8: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/8.jpg)
Instructions in memory● Components of an instruction:
– Command to be executed– Registers to be used– Numeric constants (including memory
addresses)● Instructions executed in sequence
– Address generated by Program Counter
![Page 9: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/9.jpg)
Accessing data in memory● 2 main addressing modes● Direct addressing
– Supply the concrete address in memoryint var1;reg1 = load_from (&var1)
● Indirect addressing– Use running computation from register as
addressreg1 = &var1 + 10reg2 = load_from (reg1)
![Page 10: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/10.jpg)
Issues with memory● Can only serve a single request at a time● Requirements to process instruction:
– Read instruction from memory (always)– Read/write any memory operands (typically)
● Limit number of memory operands– X86: maximum 1 memory operand– Simple processors (ARM): no memory operands
● Special memory manipulation instructions: load, store
![Page 11: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/11.jpg)
Memory organization: Harvard● Simplest design, inefficient memory usage
![Page 12: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/12.jpg)
Memory organization: Neumann● Traditional design, contention for memory
![Page 13: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/13.jpg)
Memory organization: current● Single memory, but separation of access
![Page 14: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/14.jpg)
Changing the program flow● Until now we considered sequential order● What happens for the following construction?
if (cond) codeA;else codeB;
● PC needs to change based on conditional● New sources for PC value
![Page 15: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/15.jpg)
Influences on Program Counter● Jumping: non-sequential change in PC● Relative jump ↔ Skip block of code● Absolute jump ↔ Go to specific line of code
![Page 16: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/16.jpg)
Conditionals● Evaluate conditional → Change program flow
if (a < b)● Components:
– Operands “a” and “b”– Operation “<”– Jump targets (what should happen with PC)
● Too much for single instruction
![Page 17: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/17.jpg)
Evaluator vs Conditional Jump● Separate evaluation from program flow● Evaluator: instruction that compares operands
– Similar to arithmetic and logic instructions– Result is binary flag (True/False)
● Propagate result to conditional jump– Change program flow based on state of flag
Compare(“<”, a, b)→Flag Register→Flag ? Target1 : Target2
![Page 18: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/18.jpg)
Conditional jump● Two targets too much for single instruction● Implicit target is next instruction
– Fall-through edge● Pseudo-code interpretation
if (cond) goto explicit_target;implicit_target:…explicit_target:
![Page 19: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/19.jpg)
Restructuring conditional code
![Page 20: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/20.jpg)
Restructuring conditional code
![Page 21: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/21.jpg)
Restructuring conditional code
![Page 22: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/22.jpg)
Restructuring conditional code
![Page 23: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/23.jpg)
Restructuring conditional code
![Page 24: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/24.jpg)
Supporting function calls● What is a function call?
1) Start executing function code↔Jump to function2) Return to caller location↔Jump back to call site
● But where was the function called from?● Store return address when calling function
– Multiple functions in program!– Function may be called multiple times (re-entrant)!– Need for designated storage
![Page 25: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/25.jpg)
Function call in a nut-shell
![Page 26: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/26.jpg)
Managing the return address
![Page 27: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/27.jpg)
Managing the return address
![Page 28: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/28.jpg)
Managing the return address
![Page 29: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/29.jpg)
Managing the return address
![Page 30: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/30.jpg)
Managing the return address
![Page 31: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/31.jpg)
The stack!● Last return address stored used by first return● Last In – First Out ↔ Stack● Stack Requirements:
– Contiguous sequence of memory– Stack Pointer ← Special Purpose Register
![Page 32: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/32.jpg)
Other function related concepts● Function arguments
– Unique for every instance of the function call– Passed in registers?
● Possible if no other functions called● Otherwise registers need to be saved (where?)
– Typically passed on the stack● Instance specific storage as with return address● No limit on argument count (variable length possible)
![Page 33: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/33.jpg)
Other function related concepts● Function local variables
– Similar to function arguments– Unique for every instance of the function call
● Temporary storage of registers– Function execution may be interrupted– Need to save registers in the function context– Use the stack as “unlimited” storage
![Page 34: Programmer's view on Computer Architecture by Istvan Haller](https://reader035.vdocuments.mx/reader035/viewer/2022062323/56816133550346895dd08a11/html5/thumbnails/34.jpg)
Function frames● Elements related to given function instance
– Arguments, return address, locals, temporaries● Stack pointer volatile inside function● How to find beginning of function frame?
– Base Pointer Register● What about the previous function?
– Store chain of base pointers on stack