24
EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Embed Size (px)

Citation preview

Page 1: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

EEC4133Computer Organization &

ArchitectureChapter 6: Languages and the Machine

by Muhazam Mustapha, May 2014

Page 2: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Learning Outcome

• By the end of this chapter, students are expected to have some theoretical concept of how high performance assembly coding is done

Most of the material in this slide set is adopted from Murdocca & Heuring 2007

Page 3: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Chapter Content

• Process of Generating Machine Code– Compile, Assemble, Link, Load– Macro

• High Performance Computing– Pipelining– Overlapping Register– Low Power Coding

Page 4: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Generating Machine Code

Page 5: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Compilation

• [Definition] Compilation is a process of converting high level language code into assembly language code

• The high level languages include: C, C++, C#, Java, Pascal, BASIC, etc

• These high level languages are machine (microprocessor) independent

Page 6: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Compilation

• Example (a C language code):– a = b+c;– This code may convert to:

MOV A, [b];ADD A, [c];MOV [a], A;

Page 7: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Assembly

• [Definition] Assembly is a process of converting assembly language instructions into machine language opcode that consist of 1-s and 0-s

• Assembly language instruction and its corresponding machine language opcode is highly dependent to the microprocessor being used

Page 8: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Assembly

• Example:– MOV A, B;– This assembly code may convert to machine

code:

1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1

Op

Addressing Type

Target Source

Page 9: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Macro

• [Definition] Macro is a piece of assembly code that is invoked like a subroutine but actually is expanded inline into the program during preprocessing before assembly

• Having macros in assembly language program while avoid overhead of subroutine calls (faster runtime), but the resulting machine code will be larger

Page 10: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Macro

Page 11: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Linking

• [Definition] Linking is a process after assembly to resolve (finalize) the resources pointer or location that have been defined in separate modules either in libraries or user defined

• After linking, all off module or clashing parameters will be resolved to the correct references

Page 12: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Loading

• A finished executable code will references within itself or external locations

• External references most likely is fixed

• Internal references will need to be adjusted as the code won’t have prior knowledge about the exact location where it is put in during execution

Page 13: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Loading

• [Definition] Loading is a process to load an executable into main memory and re-calculate the references to reflect the actual resources location at runtime

Page 14: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

High Performance Computing

Page 15: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Pipelining

• In the fetch-execute cycle, one would realize that there is no need to wait for one instruction to complete the entire cycle before beginning the next one

Page 16: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Pipelining

• [Definition] Pipelining is an enhancement to the fetch-execute cycle, whereby a subsequent instruction can begin a stage in the cycle when the previous instruction is at the next stage, without waiting for that previous instruction to finish the entire cycle

Page 17: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Pipelining

Page 18: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Pipelining

• Obviously pipelining can be smoothly done if the sequence of instructions are properly synchronized and do not depend on the result of the earlier ones before they complete the cycle

• The logic to automatically re-arrange the instructions so that pipelining is at its optimum level is done by the compiler– Sometimes forced delay might be needed

Page 19: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Pipelining

Page 20: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Overlapping Register Use

• With pipelining, a further improvement can be made if the microprocessor has a large no. registers that can be set to input registers and output registers

• [Definition] Overlapping register use is the use input registers by a second procedure call, while the first procedure call has NOT yet returned, but already finished using those input registers

Page 21: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Overlapping Register Use

Page 22: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Low Power Coding

• Consider the following code:ld [2096], %r16ld [2100], %r17ld [2104], %r18ld [2108], %r19

• The corresponding machine code is:

2

Page 23: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Low Power Coding

• The no. transitions in the previous code is 8, and can be reduced to 6 if they are re-arranged:

Page 24: EEC4133 Computer Organization & Architecture Chapter 6: Languages and the Machine by Muhazam Mustapha, May 2014

Low Power Coding

• With less transitions in the machine code there will be less power used

• This can be achieved by Gray code sequencing of instruction code

• This is just one way to power optimized our machine code