EC 413 Computer Organization

Similar documents
MIPS Assembly Language Programming

MIPS Assembly Language Programming

EC 413 Computer Organization

Lecture 7: Examples, MARS, Arithmetic

CENG3420 Lecture 03 Review

ECE232: Hardware Organization and Design

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA.

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

Chapter 2A Instructions: Language of the Computer

CS3350B Computer Architecture MIPS Instruction Representation

syscall takes a service ID (number) in $v0 Read integer $v0=5, after syscall, $v0 holds the integer read from keyboard

Lecture 4: Instruction Set Architecture

We will study the MIPS assembly language as an exemplar of the concept.

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions

CENG3420 L03: Instruction Set Architecture

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

Instructions: Language of the Computer

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

Five classic components

CS/COE0447: Computer Organization

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

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

Instruction Set Architecture

MIPS Memory Access Instructions

Computer Architecture. MIPS Instruction Set Architecture

ECE232: Hardware Organization and Design

Lecture 4: MIPS Instruction Set

Computer Architecture

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

ECE 154A Introduction to. Fall 2012

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes

Review of instruction set architectures

Computer Organization MIPS ISA

5.2 Defining and Initializing Arrays Statically in the Data Segment

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook)

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

A crash course in MIPS assembly programming

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

LECTURE 2: INSTRUCTIONS

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week.

Computer Organization Lab #3.

CS 61C: Great Ideas in Computer Architecture Strings and Func.ons. Anything can be represented as a number, i.e., data or instruc\ons

CS3350B Computer Architecture MIPS Procedures and Compilation

ECE 473 Computer Architecture and Organization Lab 4: MIPS Assembly Programming Due: Wednesday, Oct. 19, 2011 (30 points)

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009

Reduced Instruction Set Computer (RISC)

1/26/2014. Previously. CSE 2021: Computer Organization. The Load/Store Family (1) Memory Organization. The Load/Store Family (2)

ECE 30 Introduction to Computer Engineering

EEC 581 Computer Architecture Lecture 1 Review MIPS

CSCI 402: Computer Architectures. Instructions: Language of the Computer (4) Fengguang Song Department of Computer & Information Science IUPUI

ECE 486/586. Computer Architecture. Lecture # 6

COMPUTER ORGANIZATION AND DESIGN

MIPS and QTSPIM Recap. MIPS Architecture. Cptr280. Dr Curtis Nelson. Cptr280, Autumn

Chapter 1. Computer Abstractions and Technology. Lesson 3: Understanding Performance

MIPS Instruction Set Architecture (1)

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

מבנה מחשבים Amar Lior Based on lectures notes from Arie Schlesinger

MIPS Functions and the Runtime Stack

I ve been getting this a lot lately So, what are you teaching this term? Computer Organization. Do you mean, like keeping your computer in place?

Lecture 6: Assembly Programs

Reduced Instruction Set Computer (RISC)

ELEC / Computer Architecture and Design Fall 2013 Instruction Set Architecture (Chapter 2)

CS 61C: Great Ideas in Computer Architecture Intro to Assembly Language, MIPS Intro

Pointers (1A) Young Won Lim 2/6/18

QtSPIM and MARS : MIPS Simulators

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture

Assembly labs start this week. Don t forget to submit your code at the end of your lab section. Download MARS4_5.jar to your lab PC or laptop.

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

Practical Malware Analysis

Previously. CSE 2021: Computer Organization. Memory Organization. The Load/Store Family (1) 5/26/2011. Used to transfer data to/from DRAM.

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

2.1 DOWNLOAD AND INSTALL MARS

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Under the Hood: Data Representations, Memory and Bit Operations. Computer Science 104 Lecture 3

CS 110 Computer Architecture Lecture 5: Intro to Assembly Language, MIPS Intro

COMP3221: Microprocessors and. and Embedded Systems. Instruction Set Architecture (ISA) What makes an ISA? #1: Memory Models. What makes an ISA?

CS61C Machine Structures. Lecture 8 - Introduction to the MIPS Processor and Assembly Language. 9/14/2007 John Wawrzynek

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Compiling Techniques

MIPS (SPIM) Assembler Syntax

Pointers (1A) Young Won Lim 2/10/18

Lecture 3: Instruction Set Architecture

Course Administration

CS 61c: Great Ideas in Computer Architecture

Instruction Set Architectures. CS301 Prof. Szajda

Thomas Polzer Institut für Technische Informatik

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

Chapter 2 Instruction: Language of the Computer

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY

Lecture 3: The Instruction Set Architecture (cont.)

Lecture 3: The Instruction Set Architecture (cont.)

EITF20: Computer Architecture Part2.1.1: Instruction Set Architecture

Chapter 2. Instructions: Language of the Computer

Programming in MIPS. Tutorial

Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer

Review Session 1 Fri. Jan 19, 2:15 pm 3:05 pm Thornton 102

Transcription:

EC 413 Computer Organization Program Compilation Process Prof. Michel A. Kinsy

The Full View System Applica2ons So)ware Hardware Systems So)ware

The Full View System Processor Applica2ons Compiler Firmware ISA Memory organiza2on Digital Design Circuit Design Opera2ng System Datapath & Control Layout I/O system

Application Side Higher-level languages Allow the programmer to think in a more natural language and for their intended use Improve programmer productivity Improve program maintainability Allow programs to be independent of the computer on which they are developed Compilers and assemblers can translate high-level language programs to the binary instructions of any machine

Application Side Higher-level languages Allow the programmer to think in a more natural language and for their intended use Improve programmer productivity Improve program maintainability Allow programs to be independent of the computer on which they are developed Emergence of optimizing compilers that produce very efficient assembly code As a result, very little programming is done today at the assembler level

System Software Side System software Operating system supervising program that interfaces the user s program with the hardware (e.g., Linux, MacOS, Windows) Handles basic input and output operations Allocates storage and memory Provides for protected sharing among multiple applications Compiler translate programs written in a highlevel language (e.g., C, Java) into instructions that the hardware can execute

Application Compiling Process C Language Human Readable C program compiler assembly code assembler object code library rou6nes linker executable Machine Code loader memory

Assembly Code Three types of statements in assembly language Typically, one statement per a line 1. Executable assembly instructions Operations to be performed by the processor 2. Pseudo-Instructions and Macros Translated by the assembler into real assembly instructions Simplify the programmer task 3. Assembler Directives Provide information to the assembler while translating a program Used to define segments, allocate memory variables, etc.

Assembly Code There are 3 main types of assembly instructions Arithmetic - add, sub, mul, shifts, and, or, etc. Load/store Conditional - branches Assembly language instructions have the format: [label:] mnemonic [operands] [#comment] Label: (optional) Marks the address of a memory location Typically appear in data and text segments

Assembly Code Mnemonic Identifies the operation (e.g. add, sub, etc.) Operands Specify the data required by the operation Operands can be registers, memory variables, or constants In MIPS most instructions have three operands L1: addiu $t0, $t0, 1 #increment $t0

Assembly Languages Assemblers: Convert mnemonic operation codes to their machine language equivalents Convert symbolic operands to their equivalent machine addresses Build the machine instructions in the proper format Convert the data constants to internal machine representations Write the object program and the assembly listing

Why is assembly level view? To become familiar with the process of compiling a program/application (e.g., C) onto a computer system To know what assemblers are and what compilers do To understand the computer hardware view of the program/application

Why is assembly level view? To become familiar with the process of compiling a program/application (e.g., C) onto a computer system To, then, fully realize why computers are built the way they are In turn, you will gain new insights into how to write better and more efficient code And explore new opportunities in the field of embedded system programming

Illustration Through MIPS.DATA directive Defines the data segment of a program containing data The program's variables should be defined under this directive.text directive Defines the code segment of a program containing instructions.globl directive Declares a symbol as global

Assembly Through MIPS Sets aside storage in memory for a variable May optionally assign a name (label) to the data Syntax: [name:] directive initializer [, initializer]... var1:.word 5.WORD Directive Stores the list as 32-bit values aligned on a word boundary All initializers become binary data in memory

Assembly Through MIPS.BYTE Directive Stores the list of values as 8-bit bytes.half Directive Stores the list as 16-bit values aligned on half-word boundary.word w:n Directive Stores the 32-bit value w into n consecutive words aligned on a word boundary.float Directive.DOUBLE Directive

Assembly Through MIPS.ASCII Directive Allocates a sequence of bytes for an ASCII string.asciiz Directive Same as.ascii directive, but adds a NULL char at end of string Strings are null-terminated, as in the C programming language.space n Directive Allocates space of n uninitialized bytes in the data segment

Assembly Through MIPS # Description: The program reads and prints a string ################# Data segment #####################.data str:.space 10 # array of 10 bytes ################# Code segment #####################.text.globl main main: # main program entry la $a0, str # $a0 = address of str li $a1, 10 # $a1 = max string length li $v0, 8 # read string syscall li $v0, 4 # Print string str syscall li $v0, 10 # Exit program syscall

System Calls Programs do input/output through system calls To obtain services from the operating system Using the syscall system services In MIPS: Load the service number in register $v0 Load argument values, if any, in registers $a0, $a1, etc. Issue the syscall instruction Retrieve return values, if any, from result registers

Big Endian Little Endian Processors can order bytes within a word in two ways Little Endian Least significant byte stored at lowest byte address Intel IA-32, Alpha, AMD MSB Byte 3 Byte 2 Byte 1 32-bit Register LSB Byte 0 Big Endian Most significant byte stored at lowest byte address SPARC, PA-RISC, IBM MSB Byte 3 Byte 2 Byte 1 32-bit Register LSB Byte 0 Memory address A A+1 A+2 A+3... Byte 0 Byte 1 Byte 2 Byte 3... Memory Memory address A A+1 A+2 A+3... Byte 3 Byte 2 Byte 1 Byte 0... Memory

Big Endian Little Endian int main(void) { int var; char *ptr; // Integer values // Pointer // Assign 'var' and output it in byte order and as a value var = 0x12345678; ptr = (char *) &var; printf("ptr[0] = %02X \n", ptr[0]); // Prints 78 printf("ptr[1] = %02X \n", ptr[1]); // Prints 56 printf("ptr[2] = %02X \n", ptr[2]); // Prints 34 printf("ptr[3] = %02X \n", ptr[3]); // Prints 12 } printf("var = %08X \n", var); // Prints 12345678

Big Endian Little Endian int main(void) { int var; char *ptr; // Integer values // Pointer } // Assign 'var' and output it in byte order and as a value var = 0x12345678; ptr = (char *) &var; printf("ptr[0] = %02X \n", ptr[0]); // Prints 78 printf("ptr[1] = %02X \n", ptr[1]); // Prints 56 printf("ptr[2] = %02X \n", ptr[2]); // Prints 34 printf("ptr[3] = %02X \n", ptr[3]); // Prints 12 Big Endian printf("var = %08X \n", var); // Prints 12345678 Solaris on SPARC Little Endian Windows on Intel ptr[0] = 12 ptr[1] = 34 ptr[2] = 56 ptr[3] = 78 ptr[0] = 78 ptr[1] = 56 ptr[2] = 34 ptr[3] = 12 var = 12345678 var = 12345678

Application Compiling Process High-level language program (in C) swap (int v[], int k) { int temp; one-to-many temp = v[k]; v[k] = v[k+1]; v[k+1] = temp;} C compiler Assembly language program (for MIPS) swap: sll$2, $5, 2 add$2, $4, $2 lw $15, 0($2) lw $16, 4($2) sw $16, 0($2) sw $15, 4($2) jr $31

Application Compiling Process A compiler is a software program that translates a human-oriented high-level programming language code into computer-oriented machine language Input Source Program (C, C++, etc.) Compiler Target Program (MIPS, x86,etc.) Error messages Output

Application Compiling Process Detailed compilation process Language-focused transforma6ons Architecture-focused transforma6ons High-level language Scanner (lexical analysis) Parser (syntax analysis) Seman6c Analysis (IC generator) Code Op6mizer Code Generator Target language Symbols & AMributes Table More on this later when you take a course on compilers

Application Compiling Process Symbol Table Identifiers are names of variables, constants, functions, data types, etc. Store information associated with identifiers Information associated with different types of identifiers can be different Information associated with variables are name, type, address, size (for array), etc.

Higher Addresses Program memory management Bottom of the stack Top of the stack Stack Segment [Stack frames consisting of parameters, return addresses and local variables] Variable Size Free space Lower Addresses Heap Segment [Dynamic variables managed by malloc(), free(), etc.] BSS Segment [Initialized global and static variables] Data Segment [Initialized global and static variables] Text Segment [Program code] Variable Size Fixed Size Fixed Size Fixed Size

Application Compiling Process Assembly language program (for MIPS) swap: sll $2, $5, 2 add $2, $4, $2 one-to-one lw $15,0($2) lw $16,4($2) sw $16,0($2) assembler sw $15,4($2) jr $31 Machine (object, binary) code (for MIPS) 000000 00000 00101 0001000010000000 000000 00100 00010 0001000000100000...

Next Class Instruction Set Architecture