Principles of Computer Architecture. Chapter 5: Languages and the Machine

Similar documents
CPSC 352. Computer Organization. Chapter 5: Languages and the

Computer Architecture and Organization

Computer Architecture and Organization

Chapter 7 Subroutines. Richard P. Paul, SPARC Architecture, Assembly Language Programming, and C

JAM 16: The Instruction Set & Sample Programs

Topics. Structured Computer Organization. Assembly language. IJVM instruction set. Mic-1 simulator programming

Compiling Techniques

Recap: Printing Trees into Bytecodes

Xuan Guo. Lecture XIX: Subroutines (2) CSC 3210 Computer Organization and Programming Georgia State University. March 31, 2015.

Computer Systems Architecture I. CSE 560M Lecture 3 Prof. Patrick Crowley

A Tour of Language Implementation

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

Final Exam. 12 December 2018, 120 minutes, 26 questions, 100 points

CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

ECE251: Tuesday September 18

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

The von Neumann Architecture. IT 3123 Hardware and Software Concepts. The Instruction Cycle. Registers. LMC Executes a Store.

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Chapter 5. A Closer Look at Instruction Set Architectures

Instruction Set Architectures

//

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

Instruction Set Architectures

CS4215 Programming Language Implementation

Syntax-Directed Translation. Lecture 14

Machine-level Representation of Programs. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 5. A Closer Look at Instruction Set Architectures

Chapter 5. A Closer Look at Instruction Set Architectures. Chapter 5 Objectives. 5.1 Introduction. 5.2 Instruction Formats

Code Generation. Frédéric Haziza Spring Department of Computer Systems Uppsala University

Run-time Environments

Virtual Machine Tutorial

Run-time Environments

Highlights. FP51 (FPGA based 1T 8051 core)

Implementing Subroutines. Outline [1]

COMPILER DESIGN. For COMPUTER SCIENCE

ECE251: Intro to Microprocessors Name: Solutions Mid Term Exam October 4, 2018

Static Program Analysis

LECTURE 3. Compiler Phases

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

Systems I. Machine-Level Programming V: Procedures

Where We Are. Lexical Analysis. Syntax Analysis. IR Generation. IR Optimization. Code Generation. Machine Code. Optimization.

The Structure of a Syntax-Directed Compiler

When do We Run a Compiler?

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

Chapter 9 Subroutines and Control Abstraction. June 22, 2016

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Final Exam. 11 May 2018, 120 minutes, 26 questions, 100 points

A crash course in MIPS assembly programming

Practical Malware Analysis


Today's Topics. CISC 458 Winter J.R. Cordy

Compiler construction 2009

CSC 4181 Handout : JVM

Problem with Scanning an Infix Expression

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Turning C into Object Code Code in files p1.c p2.c Compile with command: gcc -O p1.c p2.c -o p Use optimizations (-O) Put resulting binary in file p

MACHINE LANGUAGE AND ASSEMBLY LANGUAGE

ARM Cortex A9. ARM Cortex A9

Run-Time Data Structures

Giving credit where credit is due

Assembly Programmer s View Lecture 4A Machine-Level Programming I: Introduction

A Simple Syntax-Directed Translator

94 CPU (CM8051) Incompatible Instruction ERRATA AND DATASHEET CLARIFICATION V1.0. Leader of Microcontroller Technology A Fabless Semiconductor Company

Systems I. Machine-Level Programming I: Introduction

Computer Organization MIPS ISA

The Microarchitecture Level

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

COE608: Computer Organization and Architecture

CSC 2400: Computer Systems. Using the Stack for Function Calls

The Procedure Abstraction Part I: Basics

CSIS1120A. 10. Instruction Set & Addressing Mode. CSIS1120A 10. Instruction Set & Addressing Mode 1

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) WINTER-15 EXAMINATION Model Answer Paper

CS 314 Principles of Programming Languages

CNIT 127: Exploit Development. Ch 1: Before you begin. Updated

Buffer-Overflow Attacks on the Stack

Roadmap. Java: Assembly language: OS: Machine code: Computer system:

Programming Languages Third Edition. Chapter 7 Basic Semantics

Last Time: Floating Point. Intel x86 Processors. Lecture 4: Machine Basics Computer Architecture and Systems Programming ( )

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Meet & Greet! Come hang out with your TAs and Fellow Students (& eat free insomnia cookies) When : TODAY!! 5-6 pm Where : 3rd Floor Atrium, CIT

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Computer Systems Lecture 9

02 B The Java Virtual Machine

Plan for Today. Safe Programming Languages. What is a secure programming language?

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

! What do we care about? n Fast program execution. n Efficient memory usage. n Avoid memory fragmentation. n Maintain data locality

Buffer-Overflow Attacks on the Stack

+ Machine Level Programming: x86-64 History

Where we are going (today)

Symbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu.

CS 2505 Computer Organization I Test 2. Do not start the test until instructed to do so! printed

Compiling Regular Expressions COMP360

CENG3420 Lab 2-1: LC-3b Simulator

Page # CISC 360. Machine-Level Programming I: Introduction Sept. 18, IA32 Processors. X86 Evolution: Programmerʼs View.

Project Compiler. CS031 TA Help Session November 28, 2011

Keywords: CRC, CRC-7, cyclic redundancy check, industrial output, PLC, programmable logic controller, C code, CRC generation, microprocessor, switch

Transcription:

5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture Miles Murdocca and Vincent Heuring Chapter 5: Languages and the Machine

5-2 Chapter 5 - Languages and the Machine 5.1 The Compilation Process 5.2 The Assembly Process 5.3 Linking and Loading 5.4 Macros Chapter Contents 5.5 Case Study: Extensions to the Instruction Set The Intel MMX and Motorola AltiVec SIMD Instructions

5-3 Chapter 5 - Languages and the Machine The Compilation Process Compilation translates a program written in a high level language into a functionally equivalent program in assembly language. Consider a simple high-level language assignment statement: A = B + 4; Steps involved in compiling this statement into assemby code: Reducing the program text to the basic symbols of the language (for example, into identifiers such as A and B), denotations such as the constant value 4, and program delimiters such as = and +. This portion of compilation is referred to as lexical analysis. Parsing symbols to recognize the underlying program structure. For the statement above, the parser must recognize the form: Identifier = Expression, where Expression is further parsed into the form: Identifier + Constant. Parsing is sometimes called syntactic analysis.

5-4 Chapter 5 - Languages and the Machine The Compilation Process Name analysis: associating the names A and B with particular program variables, and further associating them with particular memory locations where the variables are located at run time. Type analysis: determining the types of all data items. In the example above, variables A and B and constant 4 would be recognized as being of type int in some languages. Name and type analysis are sometimes referred to together as semantic analysis: determining the underlying meaning of program components. Action mapping and code generation: associating program statements with their appropriate assembly language sequence. In the statement above, the assembly language sequence might be as follows: ld [B], %r0, %r1 add %r1, 4, %r2! Get variable B into a register.! Compute the value of the expression st %r2, %r0, [A]! Make the assignment.

5-5 Chapter 5 - Languages and the Machine The Assembly Process The process of translating an assembly language program into a machine language program is referred to as the assembly process. Production assemblers generally provide this support: Allow programmer to specify locations of data and code. Provide assembly-language mnemonics for all machine instructions and addressing modes, and translate valid assembly language statements into the equivalent machine language. Permit symbolic labels to represent addresses and constants. Provide a means for the programmer to specify the starting address of the program, if there is one; and provide a degree of assemble-time arithmetic. Include a mechanism that allows variables to be defined in one assembly language program and used in another, separately assembled program. Support macro expansion.

5-6 Chapter 5 - Languages and the Machine Assembly Example We explore how the assembly process proceeds by hand assembling a simple ARC assembly language program.

5-7 Chapter 5 - Languages and the Machine Instruction Formats and PSR Format for the ARC

5-8 Chapter 5 - Languages and the Machine Assembled Code ld [x],%r1 1100 0010 0000 0000 0010 1000 0001 0100 ld [y],%r2 1100 0100 0000 0000 0010 1000 0001 1000 addcc %r1,%r2,%r3 1000 0110 1000 0000 0100 0000 0000 0010 st %r3,[z] 1100 0110 0010 0000 0010 1000 0001 1100 jmpl%r15+4, %r0 1000 0001 1100 0011 1110 0000 0000 0100 15 0000 0000 0000 0000 0000 0000 0000 1111 9 0000 0000 0000 0000 0000 0000 0000 1001 0 0000 0000 0000 0000 0000 0000 0000 0000

5-9 Chapter 5 - Languages and the Machine Forward Referencing An example of forward referencing:

5-10 Chapter 5 - Languages and the Machine

5-11 Chapter 5 - Languages and the Machine Assembled Program

5-12 Chapter 5 - Languages and the Machine Linking: Using.global and.extern A.global is used in the module where a symbol is defined and a.extern is used in every other module that refers to it.

5-13 Chapter 5 - Languages and the Machine Linking and Loading: Symbol Tables Symbol tables for the previous example:

5-14 Chapter 5 - Languages and the Machine Example ARC Program

5-15 Chapter 5 - Languages and the Machine Macro Definition A macro definition for push:

5-16 Chapter 5 - Languages and the Machine Recursive Macro Expansion

5-17 Chapter 5 - Languages and the Machine Intel MMX (MultiMedia extensions) Vector addition of eight bytes by the Intel PADDB mm0, mm1 instruction:

5-18 Chapter 5 - Languages and the Machine Intel aliases the floating point registers as MMX registers. This means that the Pentium s 8 64-bit floating-point registers do doubleduty as MMX registers. Intel and Motorola Vector Registers Motorola implements 32 128-bit vector registers as a new set, separate and distinct from the floating-point registers.

5-19 Chapter 5 - Languages and the Machine MMX and AltiVec Arithmetic Instructions

5-20 Chapter 5 - Languages and the Machine Comparing Two MMX Byte Vectors for Equality

5-21 Chapter 5 - Languages and the Machine Conditional Assignment of an MMX Byte Vector

5-22 Chapter 5 - Languages and the Machine Addressing Modes Four ways of computing the address of a value in memory: (1) a constant value known at assembly time, (2) the contents of a register, (3) the sum of two registers, (4) the sum of a register and a constant. The table gives names to these and other addressing modes.

5-23 Chapter 5 - Languages and the Machine Subroutine Linkage Registers Subroutine linkage with registers passes parameters in registers.

5-24 Chapter 5 - Languages and the Machine Subroutine Linkage Data Link Area Subroutine linkage with a data link area passes parameters in a separate area in memory. The address of the memory area is passed in a register ( %r5 here).

5-25 Chapter 5 - Languages and the Machine Subroutine Linkage Stack Subroutine linkage with a stack passes parameters on a stack.

5-26 Chapter 5 - Languages and the Machine Stack Linkage Example A C program illustrates nested function calls.

5-27 Chapter 5 - Languages and the Machine Stack Linkage Example (cont ) (a-f) Stack behavior during execution of the program shown in previous slide.

5-28 Chapter 5 - Languages and the Machine Stack Linkage Example (cont ) (g-k) Stack behavior during execution of the C program shown previously.

5-29 Chapter 5 - Languages and the Machine Input and Output for the ISA Memory map for the ARC, showing memory mapped I/O.

5-30 Chapter 5 - Languages and the Machine Touchscreen I/O Device A user selecting an object on a touchscreen:

5-31 Chapter 5 - Languages and the Machine Flowchart for I/O Device Flowchart illustrating the control structure of a program that tracks a touchscreen.

5-32 Chapter 5 - Languages and the Machine Java Virtual Machine Architecture

5-33 Chapter 5 - Languages and the Machine Java Program and Compiled Class File

5-34 Chapter 5 - Languages and the Machine A Java Class File

5-35 Chapter 5 - Languages and the Machine A Java Class File (Cont )

5-36 Chapter 5 - Languages and the Machine Byte Code for Java Program Disassembled byte code for previous Java program. Location Code Mnemonic Meaning 0x00e3 0x10 bipush Push next byte onto stack 0x00e4 0x0f 15 Argument to bipush 0x00e5 0x3c istore_1 Pop stack to local variable 1 0x00e6 0x10 bipush Push next byte onto stack 0x00e7 0x09 9 Argument to bipush 0x00e8 0x3d istore_2 Pop stack to local variable 2 0x00e9 0x03 iconst_0 Push 0 onto stack 0x00ea 0x3e istore_3 Pop stack to local variable 3 0x00eb 0x1b iload_1 Push local variable 1 onto stack 0x00ec 0x1c iload_2 Push local variable 2 onto stack 0x00ed 0x60 iadd Add top two stack elements 0x00ee 0x3e istore_3 Pop stack to local variable 3 0x00ef 0xb1 return Return