• 沒有找到結果。

Introduction to Part II Introduction to Part II

N/A
N/A
Protected

Academic year: 2021

Share "Introduction to Part II Introduction to Part II"

Copied!
10
0
0

加載中.... (立即查看全文)

全文

(1)

Introduction to Computing Systems

from bits & gates to C & beyond

Introduction to Part II Introduction to Part II

HLL Structures

Variables

Activation records

(2)

Higher Level Languages Higher Level Languages

HLLs allow symbolic naming of variables

 After mastering Assemly, you can now appreciate what a luxury this is!

HLLs provide expressiveness

 Compare an if statement to a conditional Branch instruction!

HLLs abstract from the underlying hardware

 While each microprocessor has its own ISA, HLL code is usually portable between many different platforms

etc., etc.

(3)

Translation Translation

HLL code has to be translated into the ISA of each machine it runs on:

 Interpretation:

 The HLL code is simply a set of commands for a program called an interpreter, which is a virtual machine that translates the HLL code a piece at a time into Machine Language, executes it on the spot, then goes back for another piece.

 Both the HLL source code and the interpreter are required every time the program is run.

 Compilation

 The HLL code is translated into an entire ML program (an executable image) by a program called a compiler.

 Only the executable image is needed to run the program.

(4)

Variables Variables

Symbolic names for variables

 The compiler creates a symbol table which holds information about each variable:

 Identifier (name), data type, memory location (as an offset from a

“frame pointer”), scope, etc.

 Suppose a variable “seconds” has been assigned an offset of -5 from the frame pointer, which is maintained in R5: then we can access seconds by the Base+Offset addressing mode:

 LDR R0, R5, # -5

 i.e. each reference to the variable seconds is translated by the compiler to (R5) - 5

 We have finally found a use for the offset in LDR!

(5)

Activation Records Activation Records

A Record

 A collection of contiguous memory locations treated as one entity

 The struct construct in C/C++ describes a record

Activation Record

 Is allocated for each function invocation in memory

 The area of memory where activation records are allocated is called the stack memory or run-time stack

In LC-3, R6 is the stack pointer: it points to the top of the stack (TOS)

R5 is the frame pointer: it points to the first local variable

Each element on the stack is an activation record

(6)

Function calls Function calls

When a function call is made:

 The calle saves space on the stack for the return value

 this is located immediately on top of the callee’s parameters

The callee pushes a copy of the return address (in R7) onto the stack

The callee pushes a copy of the dynamic link (the callee’s frame pointer, in R5) onto the stack

 The callee allocates enough space on the stack for its local variables, and adjusts R5 to point to the base of the local variables, and R6 to point to the top of the stack.

(7)

Main calls Main calls

Watt, Watt,

which calls which calls

Volta

Volta

(8)

Watt Watt

prepares prepares

to call to call

Volta

Volta

(9)

Volta is Volta is ready to ready to

run run

(10)

Returning from a call Returning from a call

Ending the callee function:

 If there is a return value, it is written into the return value entry of the activation record

 The local variables are popped off the stack

 The dynamic link (the caller’s frame pointer) is restored

 The return address is restored (R7)

 The RET instruction returns control to the caller function

Returning to the caller function:

 The return value is popped off the stack

 The arguments are popped off the stack

參考文獻

相關文件

z The caller sent signaling information over TCP to an online Skype node which forwarded it to callee over TCP. z The online node also routed voice packets from caller to callee

了⼀一個方案,用以尋找滿足 Calabi 方程的空 間,這些空間現在通稱為 Calabi-Yau 空間。.

6 《中論·觀因緣品》,《佛藏要籍選刊》第 9 冊,上海古籍出版社 1994 年版,第 1

 Promote project learning, mathematical modeling, and problem-based learning to strengthen the ability to integrate and apply knowledge and skills, and make. calculated

- Informants: Principal, Vice-principals, curriculum leaders, English teachers, content subject teachers, students, parents.. - 12 cases could be categorised into 3 types, based

How does drama help to develop English language skills.. In Forms 2-6, students develop their self-expression by participating in a wide range of activities

Now, nearly all of the current flows through wire S since it has a much lower resistance than the light bulb. The light bulb does not glow because the current flowing through it

Hope theory: A member of the positive psychology family. Lopez (Eds.), Handbook of positive