Computer Architecture

Slides:



Advertisements
Similar presentations
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
Advertisements

1 Lecture 3: Instruction Set Architecture ISA types, register usage, memory addressing, endian and alignment, quantitative evaluation.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
1 Lecture 4: Procedure Calls Today’s topics:  Procedure calls  Large constants  The compilation process Reminder: Assignment 1 is due on Thursday.
Lecture 8 Sept 23 Completion of Ch 2 translating procedure into MIPS role of compilers, assemblers, linking, loading etc. pitfalls, conclusions Chapter.
CS3350B Computer Architecture Winter 2015 Lecture 4
Assembler/Linker/Loader Mooly Sagiv html:// Chapter 4.3 J. Levine: Linkers & Loaders
Computer Organization CS224 Fall 2012 Lesson 12. Synchronization  Two processors or threads sharing an area of memory l P1 writes, then P2 reads l Data.
1 Starting a Program The 4 stages that take a C++ program (or any high-level programming language) and execute it in internal memory are: Compiler - C++
Lec 9Systems Architecture1 Systems Architecture Lecture 9: Assemblers, Linkers, and Loaders Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
1 Lecture 5: MIPS Examples Today’s topics:  the compilation process  full example – sort in C Reminder: 2 nd assignment will be posted later today.
CS 61C L14Introduction to MIPS: Instruction Representation II (1) Garcia, Spring 2004 © UCB Roy Wang inst.eecs.berkeley.edu/~cs61c-tf inst.eecs.berkeley.edu/~cs61c.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Enabling the ARM Learning in INDIA ARM DEVELOPMENT TOOL SETUP.
MIPS coding. SPIM Some links can be found such as:
Instruction Set Architecture
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 5 Addressing Mode & Architectural Design Guidelines February.
CS35101 Computer Architecture Spring 2006 Week 5 Paul Durand ( Course url:
Computer Architecture Instruction Set Architecture Lynn Choi Korea University.
Languages and the Machine Chapter 5 CS221. Topics The Compilation Process The Assembly Process Linking and Loading Macros We will skip –Case Study: Extensions.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Topic 2d High-Level languages and Systems Software
C OMPUTER A RCHITECTURE & O RGANIZATION Assemblers and Compilers Engr. Umbreen Sabir Computer Engineering Department, University of Engg. & Technology.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /29/2013 Lecture 13: Compile-Link-Load Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
CMPE 325 Computer Architecture II
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
1 Lecture 6: Assembly Programs Today’s topics:  Large constants  The compilation process  A full example  Intro to the MARS simulator.
CSc 453 Linking and Loading
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 14, 15 Addressing Mode.
Chapter 2 Instructions: Language of the Computer.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Hello world !!! ASCII representation of hello.c.
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface Chapter 2 Instructions: Language of the Computer.
Lecture 3 Translation.
MIPS Assembly.
Assemblers, linkers, loaders
Instruction Set Architectures
ECE3055 Computer Architecture and Operating Systems Chapter 2: Procedure Calls & System Software These lecture notes are adapted from those of Professor.
Computer Architecture & Operations I
Lecture 6: Assembly Programs
Computer Science 210 Computer Organization
Computer Architecture Instruction Set Architecture
Computer Architecture Instruction Set Architecture
The University of Adelaide, School of Computer Science
ELEN 468 Advanced Logic Design
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
Topic 2e High-Level languages and Systems Software
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Computer Science 210 Computer Organization
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
CSCE Fall 2013 Prof. Jennifer L. Welch.
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
Lecture 7: Examples, MARS, Arithmetic
Computer Organization and Design Assembly & Compilation
CSCE Fall 2012 Prof. Jennifer L. Welch.
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Lecture 6: Assembly Programs
Computer Architecture
10/6: Lecture Topics C Brainteaser More on Procedure Call
Lecture 4: Instruction Set Design/Pipelining
Program Assembly.
Presentation transcript:

Computer Architecture Prof. Dr. Nizamettin AYDIN naydin@yildiz.edu.tr nizamettinaydin@gmail.com http://www.yildiz.edu.tr/~naydin Copyright 2000 N. AYDIN. All rights reserved.

MIPS Address Modes and Translating Programs

Outline MIPS Adressing Modes Translating Programs Immediate Addressing Register Addressing Base Addressing PC-relative Addressing Pseudodirect Addressing MIPS Instruc-on Formats – Summary Other ISAs Translating Programs C Code Translation Hierarchy Compiler Flags - Example Assembly Language Object File Executable Loading a Program Dynamic Linking Java Code Transla-on Hierarchy

Immediate Addressing The operand is a constant within the instruction itself Example add $s1, $s2, 200  $s1= $s2 + 200

Register Addressing The operand is in a register Example add $s1, $s2, $s3  $s1= $s2 + $s3

Base Addressing The operand is in the memory location whose address is the sum of a register and a constant in the instruction Example lw $s1, 200($s2)  $s1= mem[200 + $s2]

PC-relative Addressing The address is the sum of the PC and a constant in the instruction I-Type instruction Example beq $s1, $s2 , 200  if ($s1 ==$s2) PC= PC+4+200*4

Pseudodirect Addressing the jump address is the 26 bits of the instruction concatenated with the upper bits of the PC J-Type instruction Example j 4000  PC = (PC[31:28], 4000*4)

MIPS Instruction Formats - Summary

Uniformity and Compiler Friendliness in MIPS 3 instruction formats: I, R and J R-type: Register-register arithmetic I-type: immediate arithmetic, load/stores, conditional branches J-type: Jumps, non-conditional branches Opcodes are always in the same place rs and rt are always in the same place, as is rd if it exists The immediate is always in the same place Similar amounts of work per instruction 1 read from instruction memory <=1 arithmetic operations <=2 register reads <=1 register write <= 1 data load/store Fixed instruction length

Other ISAs CISC (Complex Instruction Set Computing) Combine memory and computation operations into a single operation Multiple-step operations Examples: System/360, Motorola 68k, x86, VAX Dominant in desktops and servers RISC (Reduced Instruction Set Computing) a.k.a load/store architecture (memory accesses are not part of an arithmetic instruction) Arithmetic instructions just operate on registers Examples: MIPS, ARM, PowerPC, SPARC Dominant in cell phones, embedded systems

ARM and MIPS Instruction Encoding

x86 Instruction Encoding Variable length encoding Postfix bytes specify addressing mode Prefix bytes modify operation Operand length, repetition, locking, … Intel and AMD use x86

Concluding Remarks on ISA Design principles for a good ISA Simplicity favors regularity Smaller is faster Make the common case fast Good design demands good compromises Layers of software/hardware Compiler, assembler, linker, hardware MIPS: typical of RISC ISAs x86 typical of CISC ISAs

C Code Translation Hierarchy gcc –S src.c gcc –c src.s or gcc –c src.c gcc src.o or gcc src.c specifiy output filename with -o  A translation hierarchy for C. A high-level language program is first compiled into an assembly language program and then assembled into an object module in machine language. The linker combines multiple modules with library routines to resolve all references. The loader then places the machine code into the proper memory locations for execution by the processor. To speed up the translation process, some steps are skipped or combined. Some compilers produce object modules directly, and some systems use linking loaders that perform the last two steps. To identify the type of file, UNIX follows a suffix convention for files: C source files are named x.c, assembly files are x.s, object files are named x.o, statically linked library routines are x.a, dynamically linked library routes are x.so, and executable files by default are called a.out. MS-DOS uses the suffixes .C, .ASM, .OBJ, .LIB, .DLL, and .EXE to the same effect. ./a.out Copyright 2000 N. AYDIN. All rights reserved.

Compiler Flags - Example gcc –S src.c #creates .s file Generates assembly code (compile only) gcc –c src.s #creates .o file Generates object file (compile and assemble) gcc src.o #creates a.out file Generates an executable from object files gcc sum.o -o sum.exe #creates an executable sum.exe Generates an executable with a specified output name gcc src.c #creates an executable by default name a.out Compile, assemble and link

Assembly Language Assembly language is the symbolic representation of a computer’s binary encoding, which is called machine language. Assembly language is more readable than machine language because it uses symbols instead of bits. Assembly language permits programmers to use labels to identify and name particular memory words that hold instructions or data. A tool called assembler translates assembly language into binary instructions. An assembler reads a single assembly language source file and produces object file containing machine instructions and bookkeeping information that helps combine several object files into a program.

Object File Not directly executable Contains object code (relocatable format machine code) Input to the linker Provides information for building a complete program from the pieces Header: described contents of object module Text segment: translated instructions Static data segment: data allocated for the life of the program Relocation info: for contents that depend on absolute location of loaded program Symbol table: global definitions and external refs Debug info: for associating with source code

Linking Object Files Link editor or linker links the object files Linker takes all the independently assembled object files and stitches them together Resolves all the undefined labels into an executable file Relocation Linker merges object files and assigns runtime addresses to each symbol and section As a result, instructions and data will have unique runtime addresses Output is an executable file

Executable Its format is similar to an object file But contains almost no unresolved references It can contain symbol tables and debugging information and partially linked files, such as library routines, that still have unresolved addresses. Might need to do another relocation at the execution time Loader executes the executable

Loading a Program A loader is the part of an operating system Load from image file (executable) on disk into memory Read header to determine size of the text and data segments Create an address space for the segments Copy text and data from the executable file into memory Set up arguments (if any) on stack Initialize registers (including $sp, $fp, $gp) Jump to startup routine Copies arguments to $a0, … and calls ”main” Note that loader is the caller and ”main” is the callee When main returns, program exits

Dynamic Linking Static linking is fast The application can be certain that all its libraries are present with static libraries Static linking will result in a significant performance improvement Static linking can also allow the application to be contained in a single executable file, simplifying distribution and installation. Dynamically link/load library when it is called Requires procedure code to be relocatable Avoids large image files caused by static linking of all (transitively) referenced libraries Automatically picks up new library versions

What time? Compile Time Link Time Load Time Runtime (Execution Time) The source of the error and error messages differ.

Java Code Translation Hierarchy Portable instruction set for the JVM Interprets bytecodes at runtime Compiles bytecodes of “hot” methods into native code for host machine A translation hierarchy for Java. A Java program is first compiled into a binary version of Java bytecodes, with all addresses defined by the compiler. The Java program is now ready to run on the interpreter, called the Java Virtual Machine (JVM). The JVM links to desired methods in the Java library while the program is running. To achieve greater performance, the JVM can invoke the JIT compiler, which selectively compiles methods into the native machine language of the machine on which it is running. Copyright 2000 N. AYDIN. All rights reserved.