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

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

Computer Architecture and Organization

MACHINE LANGUAGE AND ASSEMBLY LANGUAGE

Chapter 6: Datapath and Control. Principles of Computer Architecture. Principles of Computer Architecture by M. Murdocca and V.

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

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

Basic Processor Design

SPARC Architecture. SPARC Registers

Data Transfer Instructions

Computer Systems Lecture 9

Stack Frames. Compilers use the stack: to store the to to a subroutine for storage of declared in the subroutine and a place to

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

Chapter 4 Simple Calculations

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

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

Xuan Guo. Lecture XIV: Review of Chapter 3 & 4. CSC 3210 Computer Organization and Programming Georgia State University. March 5, 2015.

Instruction Set Architecture. "Speaking with the computer"

Stored Program Concept. Instructions: Characteristics of Instruction Set. Architecture Specification. Example of multiple operands

CPSC 213, Winter 2009, Term 2 Midterm Exam Date: March 12, 2010; Instructor: Mike Feeley

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

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

Course Administration

Summary: Direct Code Generation

Exam Computer Systems/Computer Architecture and Organisation Bachelor 2 nd year, EE and CS, EWI

Comparison InstruCtions

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

Computer Architecture and Organization

ARM Shift Operations. Shift Type 00 - logical left 01 - logical right 10 - arithmetic right 11 - rotate right. Shift Amount 0-31 bits

Module 8: Atmega32 Stack & Subroutine. Stack Pointer Subroutine Call function

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 4

CPE300: Digital System Architecture and Design

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

Chapter 2A Instructions: Language of the Computer


Subroutines and Stack Usage on the MicroBlaze. ECE 3534 Microprocessor System Design

Chapter 9 Subroutines and Control Abstraction. June 22, 2016

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

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

2) Save the Macro definition:- The processor must store the macro instruction definitions which it will need for expanding macro calls.

Announcements. Class 7: Intro to SRC Simulator Procedure Calls HLL -> Assembly. Agenda. SRC Procedure Calls. SRC Memory Layout. High Level Program

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

CSCE 5610: Computer Architecture

Assembling Programs. .o les (Unix).obj les (Windows/DOS)

Instruction Set Architecture

CS 314 Principles of Programming Languages

ECE232: Hardware Organization and Design

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

COMPILERS BASIC COMPILER FUNCTIONS

MIPS (SPIM) Assembler Syntax

Lecture 04: Machine Instructions

Procedures and Stacks

MIPS Assembly Programming

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

ECE/CS 552: Introduction To Computer Architecture 1. Instructor:Mikko H. Lipasti. University of Wisconsin-Madison. Basics Registers and ALU ops

Compiler, Assembler, and Linker

Computer System Architecture

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Review Topics

CSE 533: Advanced Computer Architectures Instructor: Gürhan Küçük. Instructions. Instructions cont d. Forecast. Basics. Basics

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

Instruction Set Architecture (Contd)

COE608: Computer Organization and Architecture

Orange Coast College. Business Division. Computer Science Department CS 116- Computer Architecture. The Instructions

MIPS Functions and the Runtime Stack

ARM Cortex-M4 Architecture and Instruction Set 4: The Stack and subroutines

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

18. Machine Language. Computer Systems. COMP1917: Computing 1. Machine Language Programming. History of Computer Technology

Procedure Call. Procedure Call CS 217. Involves following actions

2. Arithmetic Instructions addition, subtraction, multiplication, divison (HCS12 Core Users Guide, Sections 4.3.4, and ).

Reconfigurable Computing Systems ( L) Fall 2012 Tiny Register Machine (TRM)

Run-time Environment

CS3350B Computer Architecture MIPS Procedures and Compilation

COMPILER DESIGN. For COMPUTER SCIENCE

COSC 6385 Computer Architecture. Instruction Set Architectures

Lecture 5: Instruction Set Architectures II. Take QUIZ 2 before 11:59pm today over Chapter 1 Quiz 1: 100% - 29; 80% - 25; 60% - 17; 40% - 3

Chapter 11. Instruction Sets: Addressing Modes and Formats. Yonsei University

COMPILER DESIGN LECTURE NOTES

ECE 486/586. Computer Architecture. Lecture # 8

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

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

Lecture Topics. Branch Condition Options. Branch Conditions ECE 486/586. Computer Architecture. Lecture # 8. Instruction Set Principles.

CENG 450: Instruction Set (16-bit)

MC9S12 Assembler Directives A Summary of MC9S12 Instructions Disassembly of MC9S12 op codes. Summary of HCS12 addressing modes ADDRESSING MODES

The x86 Architecture

UNIT-IV: MACRO PROCESSOR

ARM Instruction Set 1

MICROPROGRAMMED CONTROL

Code generation and local optimization

EECE.3170: Microprocessor Systems Design I Summer 2017 Homework 4 Solution

CS2214 COMPUTER ARCHITECTURE & ORGANIZATION SPRING 2014

LECTURE 3. Compiler Phases

Computer Organization MIPS ISA

Code generation and local optimization

Compiler Architecture

Typical Processor Execution Cycle

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

Lecture 2: The Instruction Set Architecture

CS 4201 Compilers 2014/2015 Handout: Lab 1

Branch Instructions. R type: Cond

Transcription:

5-1 CPSC 352 Computer Organization Chapter 5: Languages and the Machine

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

5-3 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 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 st %r2, %r0, [A]! Get variable B into a register.! Compute the value of the expression! Make the assignment.

5-5 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 Assembly Example We explore how the assembly process proceeds by hand assembling a simple ARC assembly language program.! This program adds two numbers.begin.org 2048 main: ld [x], %r1! Load x into %r1 ld [y], %r2! Load y into %r2 addcc %r1, %r2, %r3! %r3 %r1 + %r2 st %r3, [z]! Store %r3 into z jmpl %r15 + 4, %r0! Return x: 15 y: 9 z: 0.end

5-7 op SETHI Format 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 0 0 rd op2 imm22 Instruction Formats and PSR Format for the ARC Branch Format CALL format Arithmetic Formats Memory Formats op 00 01 10 11 Format SETHI/Branch CALL Arithmetic Memory 0 0 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 0 1 0 cond op2 010 100 Inst. branch sethi op2 op3 (op=10) 010000 010001 010010 010110 100110 111000 addcc andcc orcc orncc srl jmpl disp30 op3 (op=11) 000000 000100 disp22 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 1 0 rd op3 1 0 rd op3 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 1 1 rd op3 1 1 rd op3 rs1 rs1 rs1 rs1 i 0 1 0 1 0 0 0 0 0 0 0 0 rs2 0 0 0 0 0 0 0 0 rs2 ld st simm13 simm13 cond 0001 0101 0110 0111 1000 branch be bcs bneg bvs ba PSR 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 n z v c

5-8 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 Forward Referencing An example of forward referencing:. call sub_r. sub_r: st %r1, [w].! Subroutine is invoked here! Subroutine is defined here

5-10! This program sums LENGTH numbers! Register usage: %r1 Length of array a! %r2 Starting address of array a! %r3 The partial sum! %r4 Pointer into array a! %r5 Holds an element of a.begin! Start assembling.org 2048! Start program at 2048 a_start.equ 3000! Address of array a loop: done: ld [length], %r1! %r1 length of array a ld [address],%r2! %r2 address of a andcc %r3, %r0, %r3! %r3 0 andcc %r1, %r1, %r0! Test # remaining elements be done! Finished when length=0 addcc %r1, -4, %r1! Decrement array length addcc %r1, %r2, %r4! Address of next element ld %r4, %r5! %r5 Memory[%r4] addcc %r3, %r5, %r3! Sum new element into r3 Symbol ba loop! Repeat loop. Value jmpl %r15 + 4, %r0! Return to calling routine a_start 3000 length length: 20! 5 numbers (20 bytes) in a address: a_start.org a_start! Start of array a (a) a: 25! length/4 values follow 10 33 5 7.end! Stop assembling Creating a Symbol Table Symbol Value a_start 3000 length (a) Symbol Value a_start 3000 length 2092 address 2096 loop 2060 done 2088 a 3000 (b)

5-11 Assembled Program Location counter Instruction Object code.begin.org 2048 a_start.equ 3000 ld [length],%r1 11000010 00000000 00101000 00101100 ld [address],%r2 11000100 00000000 00101000 00110000 andcc %r3,%r0,%r3 10000110 10001000 11000000 00000000 loop: andcc %r1,%r1,%r0 10000000 10001000 01000000 00000001 be done 00000010 10000000 00000000 00000110 addcc %r1,-4,%r1 10000010 10000000 01111111 11111100 addcc %r1,%r2,%r4 10001000 10000000 01000000 00000010 ld %r4,%r5 11001010 00000001 00000000 00000000 2048 2052 2056 2060 2064 2068 2072 2076 2080 ba loop 00010000 10111111 11111111 11111011 2084 addcc %r3,%r5,%r3 10000110 10000000 11000000 00000101 2088 done: jmpl %r15+4,%r0 10000001 11000011 11100000 00000100 2092 length: 20 00000000 00000000 00000000 00010100 2096 address: a_start 00000000 00000000 00001011 10111000.org a_start 3000 a: 25 00000000 00000000 00000000 00011001 3004-10 11111111 11111111 11111111 11110110 3008 33 00000000 00000000 00000000 00100001 3012-5 11111111 11111111 11111111 11111011 3016 7 00000000 00000000 00000000 00000111.end

5-12 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.! Main program.begin.org 2048.extern sub main: ld [x], %r2 ld [y], %r3 call sub jmpl %r15 + 4, %r0 x: 105 y: 92.end! Subroutine library ONE sub:.begin.equ 1.org 2048.global sub orncc %r3, %r0, %r3 addcc %r3, ONE, %r3 jmpl %r15 + 4, %r0.end

5-13 Linking and Loading: Symbol Tables Symbol tables for the previous example: Symbol Value Global/ External Symbol Value Global/ External Relocatable Relocatable sub External ONE 1 No No main 2048 No Yes sub 2048 Global Yes x 2064 y 2068 No No Yes Yes Subroutine Library Main Program

5-14 Example ARC Program Chapter 5: Languages A + B and the Machine! Perform a 64-bit addition: C! Register usage: %r1 Most significant 32 bits of A! %r2 Least significant 32 bits of A! %r3 Most significant 32 bits of B! %r4 Least significant 32 bits of B! %r5 Most significant 32 bits of C! %r6 Least significant 32 bits of C! %r7 Used for restoring carry bit.begin! Start assembling.global main.org 2048! Start program at 2048 main: ld [A], %r1! Get high word of A ld [A+4], %r2! Get low word of A ld [B], %r3! Get high word of B ld [B+4], %r4! Get low word of B call add_64! Perform 64-bit addition st %r5, [C]! Store high word of C st %r6, [C+4]! Store low word of C..org 3072! Start add_64 at 3072 add_64: addcc %r2, %r4, %r6! Add low order words bcs lo_carry! Branch if carry set addcc %r1, %r3, %r5! Add high order words jmpl %r15 + 4, %r0! Return to calling routine lo_carry: addcc %r1, %r3, %r5! Add high order words bcs hi_carry! Branch if carry set addcc %r5, 1, %r5! Add in carry jmpl %r15, 4, %r0! Return to calling routine hi_carry: addcc %r5, 1, %r5! Add in carry sethi #3FFFFF, %r7! Set up %r7 for carry addcc %r7, %r7, %r0! Generate a carry jmpl %r15 + 4, %r0! Return to calling routine A: 0! High 32 bits of 25 25! Low 32 bits of 25 B: #FFFFFFFF! High 32 bits of -1 #FFFFFFFF! Low 32 bits of -1 C: 0! High 32 bits of result 0! Low 32 bits of result.end! Stop assembling

5-15 A macro definition for push: Macro Definition! Macro definition for 'push'.macro push arg1! Start macro definition addcc %r14, -4, %r14! Decrement stack pointer st arg1, %r14! Push arg1 onto stack.endmacro! End macro definition

5-16 Recursive Macro Expansion! A recursive macro definition.macro recurs_add X! Start macro definition.if X > 2! Assemble code if X > 2 recurs_add X 1! Recursive call.endif! End.if construct addcc %r1, %rx, %r1! Add argument into %r1.endmacro! End macro definition recurs_add 4! Invoke the macro Expands to: addcc %r1, %r2, %r1 addcc %r1, %r3, %r1 addcc %r1, %r4, %r1

5-17 Intel MMX (MultiMedia extensions) Vector addition of eight bytes by the Intel PADDB mm0, mm1 instruction: mm0 mm1 mm0 11111111 00000000 01101001 10111111 00101010 01101010 10101111 10111101 + + + + + + + + 11111110 11111111 00001111 10101010 11111111 00010101 11010101 00101010 = = = = = = = = 11111101 11111111 01111000 01101001 00101001 01111111 10000100 11100111

5-18 Intel and Motorola Vector Registers Intel aliases the floating point registers as MMX registers. This means that the Pentium s 8 64-bit floating-point registers do double-duty as MMX registers. Motorola implements 32 128-bit vector registers as a new set, separate and distinct from the floating-point registers. Intel MMX Registers 63 0 MM7 MM0 Motorola AltiVec Registers 127 0 VR31 VR30 VR1 VR0

5-19 MMX and AltiVec Arithmetic Instructions

5-20 Comparing Two MMX Byte Vectors for Equality mm0 mm1 mm0 11111111 00000000 00000000 10101010 00101010 01101010 10101111 10111101 == == == == == == == == 11111111 11111111 00000000 10101010 00101011 01101010 11010101 00101010 11111111 00000000 11111111 11111111 00000000 11111111 00000000 00000000 (T) (F) (T) (T) (F) (T) (F) (F)

5-21 Conditional Assignment of an MMX Byte Vector mm0 AND mm2 mm2 11111111 00000000 11111111 11111111 00000000 11111111 00000000 00000000 10110011 10001101 01100110 10101010 00101011 01101010 11010101 00101010 10110011 00000000 01100110 10101010 00000000 01101010 00000000 00000000