<<

Lecture Outline CS1101: Lecture 28 The Microarchitecture Level

Dr. Barry O’Sullivan • What is a microarchitecture? [email protected] • OPCODE

• Stacks

• How does a stack works?

• Use of a stack for storing local variables

• Operand Stacks

Course Homepage • Use of an Operand Stack http://www.cs.ucc.ie/˜osullb/cs1101 • Reading: Tanenbaum, Chapter 4: 4.1, 4.2, 4.5.1

Department of , University College Cork Department of Computer Science, University College Cork 1

CS1101: Systems Organisation The Microarchitecture Level CS1101: Systems Organisation The Microarchitecture Level Where are we now? Introduction

• The level above the digital logic level is the microarchitecture level. Level 5 Problem-oriented language level

Translation (compiler) • Its job is to implement the ISA (Instruction Set

Level 4 level Architecture) level above it, as illustrated in Fig. 1-2. Translation (assembler) Level 3 Operating system machine level • The design of the microarchitecture level Partial interpretation (operating system) depends on the ISA being implemented, as

Level 2 Instruction set architecture level well as the cost and performance goals of the computer. Interpretation (microprogram) or direct execution

Level 1 Microarchitecture level • Many modern ISAs, particularly RISC designs,

Hardware have simple instructions that can usually be executed in a single clock cycle. Level 0 Digital logic level • More complex ISAs may require many cycles Figure 1-2. Our six-level computer. to execute a single instruction. • Executing an instruction may require locating the operands in memory, reading them, and storing results back into memory.

Department of Computer Science, University College Cork 2 Department of Computer Science, University College Cork 3 What is a microarchitecture? OPCODE

• A convenient model for the design of the • Each instruction has a few fields, usually one or microarchitecture is to think of the design as a two, each of which has some specific purpose. programming problem, where each instruction at the ISA level is a function to be called by a • master program. The first field of every instruction is the opcode (short for operation code). • In this model, the master program is a simple, endless loop that determines a function to be • The opcode identifies the instruction, telling invoked, calls the function, then starts over. whether it is an ADD or a BRANCH, or something else. • The microprogram has a set of variables, called the state of the computer, which can be • Many instructions have an additional field, accessed by all the functions. which specifies the operand.

• Each function changes at least some of the • For example, instructions that access a local variables making up the state. variable need a field to tell which variable.

• For example, the Program is part of • This model of execution is sometimes called the state – the memory location for the next the fetch-execute cycle. instruction.

Department of Computer Science, University College Cork 4 Department of Computer Science, University College Cork 5

CS1101: Systems Organisation The Microarchitecture Level CS1101: Systems Organisation The Microarchitecture Level Stacks How does a stack works?

• Virtually all programming languages support the concept of procedures (methods), which • Instead, an area of memory, called the stack, is have local variables. reserved for variables, but individual variables do not get absolute addresses in it. • These variables can be accessed from inside the procedure but cease to be accessible once • Instead, a register, say, LV, is set to point to the procedure has returned. the base of the local variables for the current procedure. • Where should these variables be kept in memory? • Another register, SP,points to the highest word of the local variables. • The simplest solution, to give each variable an absolute memory address, does not work, • since a procedure may call itself (be recursive). Variables are referred to by giving their offset (distance) from LV. • Why? • The data structure between LV and SP (and • If a procedure is active (i.e., called) twice, it including both words pointed to) is called a is impossible to store its variables in absolute variable’s local variable frame. memory locations because the second invocation will interfere with the first.

Department of Computer Science, University College Cork 6 Department of Computer Science, University College Cork 7 eateto optrSine nvriyCleeCr 10 Cork College University Science, Computer of Department CS1101 • • • • CS1101: Systems Organisation The Microarchitecture Le ial,tetpwr a eppe f the off a1. popped variable local be in back can stored word and stack top the Finally, stack. the the onto pushes back and result together, them adds now off stack, by words the two done pops that be instruction an can executing computation actual The stack. the onto the pushed is at a3 Next, stored operand SP. first by to the pointed now been address and word, has a SP 4, in bytes here say, of – number the stack by the incremented onto a2 Push

ytm Organisation Systems : Use of a stack for storing local variables s fa prn Stack Operand an of Use

SP c2 LV c1 SP d5 SP b4 b4 d4 b3 b3 d3 b2 b2 d2 LV b1 b1 LV d1 SP a3 108 a3 a3 a3 a2 104 a2 a2 a2 LV a1 100 a1 a1 a1 (a) (b) (c) (d)

h iracietr Level Microarchitecture The Figure 4-8. Use of a stack for storing local variables. (a) While A is activ (b) After A calls B. (c) After B calls C. (d) After C and B return and A calls D

Department of Computer Science, University College Cork eateto optrSine nvriyCleeCr 9 Cork College University Science, Computer of Department • • • • CS1101: Systems Organisation The Microarchitecture Level

hnue hswy h tc srfre oas to referred is stack the the way, this used When expression. arithmetic during an operands of holding computation for the used be can They holding to variables. addition local in use, another have Stacks xml:spoeta eoecligB has computation: A the B, do calling to before that suppose Example:

Use of an Operand Stack stack operand

prn Stacks Operand

SP a3 SP a2 a2 SP a2 + a3 a3 a3 a3 SP a3 a

a2 a2 a2 a2 = 1

LV a1 LV a1 LV a1 LV a2 + a3 . (a) (b) (c) (d) a Figure 4-9. Use of an operand stack for doing an arithmetic computation. + 2 a 3

Department of Computer Science, University College Cork 11