Csci 136 Computer Architecture II – More on MIPS ISA Xiuzhen Cheng

Slides:



Advertisements
Similar presentations
Henk Corporaal TUEindhoven 2011
Advertisements

1 Lecture 3: MIPS Instruction Set Today’s topic:  More MIPS instructions  Procedure call/return Reminder: Assignment 1 is on the class web-page (due.
Goal: Write Programs in Assembly
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
MIPS ISA-II: Procedure Calls & Program Assembly. (2) Module Outline Review ISA and understand instruction encodings Arithmetic and Logical Instructions.
ECE 232 L6.Assemb.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 6 MIPS Assembly.
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.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
Systems Architecture Lecture 5: MIPS Instruction Set
Chapter 2.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /17/2013 Lecture 12: Procedures Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL.
The University of Adelaide, School of Computer Science
Lecture 8: MIPS Instruction Set
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.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
14:332:331 Computer Architecture and Assembly Language Spring 06 Week 4: Addressing Mode, Assembler, Linker [Adapted from Dave Patterson’s UCB CS152 slides.
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.
S. Barua – CPSC 440 CHAPTER 2 INSTRUCTIONS: LANGUAGE OF THE COMPUTER Goals – To get familiar with.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
RISC Concepts, MIPS ISA and the Mini–MIPS project
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
ECE 232 L5 Assembl.1 Adapted from Patterson 97 ©UCBCopyright 1998 Morgan Kaufmann Publishers ECE 232 Hardware Organization and Design Lecture 5 MIPS Assembly.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
CDA 3101 Fall 2012 Introduction to Computer Organization Instruction Set Architecture MIPS Instruction Format 04 Sept 2013.
MIPS coding. SPIM Some links can be found such as:
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
Mohamed Younis CMCS 411, Computer Architecture 1 CMCS Computer Architecture Lecture 5 Addressing Mode & Architectural Design Guidelines February.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 2 Part 4.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
Lecture 4: MIPS Instruction Set
CMPE 325 Computer Architecture II
Csci 136 Computer Architecture II – Summary of MIPS ISA Xiuzhen Cheng
Chapter 2 CSF 2009 The MIPS Assembly Language. Stored Program Computers Instructions represented in binary, just like data Instructions and data stored.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
MIPS Instructions Instructions: Language of the Machine
Chapter 2 — Instructions: Language of the Computer — 1 Conditional Operations Branch to a labeled instruction if a condition is true – Otherwise, continue.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
The Assembly Process Computer Organization and Assembly Language: Module 10.
Computer Organization Instructions Language of The Computer (MIPS) 2.
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.
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface Chapter 2 Instructions: Language of the Computer.
Lecture 3 Translation.
MIPS Assembly.
Computer Architecture & Operations I
Lecture 6: Assembly Programs
MIPS Instruction Set Advantages
Instruction Sets Chapter 2
Lecture 4: MIPS Instruction Set
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
The University of Adelaide, School of Computer Science
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
CS170 Computer Organization and Architecture I
Henk Corporaal TUEindhoven 2010
The University of Adelaide, School of Computer Science
Computer Instructions
Computer Architecture
COMS 361 Computer Organization
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
COMS 361 Computer Organization
CPU Structure CPU must:
Program Assembly.
Presentation transcript:

Csci 136 Computer Architecture II – More on MIPS ISA Xiuzhen Cheng

Announcement Project #1 is due on 11:59PM, Feb 13, 2005.

What is an ISA? A very important abstraction Provide the interface between the low-level software and hardware May have multiple hardware implementations Needs to answer the following questions What is the minimum instruction set to be supported? Use general purpose register or not? CIRS or RISC design? Instruction format? Addressing mode? …

Summary: Salient features of MIPS 32-bit fixed format inst (3 formats) bit GPR (R0 contains zero) and 32 FP registers (and HI LO) –3-address, reg-reg arithmetic instr. Single addressing mode for load/store: base+displacement – no indirection, scaled 16-bit immediate plus LUI Simple branch conditions – compare against zero or two registers for =,  – no integer condition codes

Summary: MIPS Instruction set design Use general purpose registers with a load-store architecture: yes or no? Provide 32 general purpose registers plus separate floating-point registers: What’s the addressing mode supported by MIPS? An ISA uses fixed instruction encoding if interested in performance and use variable instruction encoding if interested in code size. What does MIPS ISA do?

Summary: MIPS Instruction set design Support these data sizes and types: 8-bit, 16-bit, 32-bit integers and 32-bit and 64-bit IEEE 754 floating point numbers: Support these simple instructions, since they will dominate the number of instructions executed: load, store, add, subtract, move register-register, and, shift, compare equal, compare not equal, branch, jump, call, and return: Aim for a minimalist instruction set:

More Details of MIPS ISA Register 0 always has the value 0 even if you try to write it Branch and jump use the PC+4 as the reference point All instructions change all 32 bits of the destination register (including lui, lb, lh) and use all 32 bits of source register Immediate arithmetic and logical instructions are extended as follows: Logical immediate are zero-extended to 32 bits Arithmetic immediate are sign-extended to 32 bits The data loaded by the instructions lb and lh are extended as follows: lbu, lhu are zero-extended lb, lh are sign-extended Overflow can occur in add, sub, addi, but does not in other arithmetic and logical operations

MIPS Hardware Design Principles Simplicity favors regularity Keeping the hardware simple! R-Type instruction format Smaller is faster 32 general purpose registers, no more, no less. Good design demands good compromises R, I, J, 3 types of instruction formats Make the common case fast! I-type instructions for constant numbers

Symbolic Assembly Form … Loop:slti $t0, $s1, 100 # if $s1<100 then $t0=1; else $t0=0 Label: optional Location reference of an instruction Often starts in the 1 st column and ends with “:” Mnemonic: symbolic name for operations to be performed which directs assembler to Arithmetic, data transfer, logic, branch, etc OperandExp: value or address of an operand Comments: Don’t forget me!

MIPS Assembly Language Refer to the Companion CD. Pseudo-instruction Provided by assembler but not implemented by hardware Disintegrated by assembler to one or more instructions Example:blt $16, $17, Less  slt $1, $16, $17 bne $1, $0, Less Directives Tells assembler how to interpret or where to put code; no machine code is generated. Examples: str1:.ascii“I am a string” str2:.asciiz“I am a null-terminated string”.byte8, 12, 16.word8, 12, 16.space12# allocate 12 bytes in data segment.data# put the following in data segment.text# put the following in text segment.align 2# put the following value on word boundary

Compiler, Assembler, Linker, Loader The compiler takes one or more source programs and converts them to an assembly program The assembler takes an assembly program and converts it to machine code: an object file (or a library) The linker takes multiple object files and libraries, decides memory layout and resolves references to convert them to a single program: an executable (or executable file) The loader takes an executable, stores it in memory, initializes the segments and stacks, and jumps to the initial part of the program. The loader also calls exit once the program completes.

MIPS Memory Layout (1/2) 0x x00 0x xA0 0x x3E 0x x10 … … … … 0xFFFFFFFC0x90 0xFFFFFFFD0x6F 0xFFFFFFFE0xA1 0xFFFFFFFF0x00 Memory Organization Reserved Text segment --Data segment— … … … … … Stack segment MIPS Memory Layout Instructions 0x x $sp  0x7FFFFFFF Dynamic data Static data $gp  0x

MIPS Memory Layout (2/2) How to load a word in the data segment at address 0x into register $s0? lw/sw can not directly reference data objects with their 16-bit offset fields lui $t0 0x1001 lw $s0, 0x0020($t0) Global pointer $gp points to 0x lw $s0, 0x8020($gp)

Assembler Convert an assembly language instruction to a machine language instruction: fill fields of the machine instruction for the assembly language instruction Compute space for data statements, and store data in binary representation Put information for placing instructions in memory – see object file format Example:j loop Fill op code: Fill address field corresponding to the local label (loop in this eg) Questions: How to find the address of a local or an external label?

Local Label Address Resolution Assembler reads the program twice First Pass: If an instruction has a label, add an entry in the symbol table Second Pass: if an instruction branches to a label, search for an entry with that label in the symbol table and resolve the label address Produce machine code External label can not be assembled! – need help from linker! Assembler reads the program once Produce machine code If an instruction has a unresolved label, record the label and the instruction address in the backpatch table. After the label is defined, the assembler consults the backpatch table to correct all binary representation of the instructions with that label.

Object File Format Object file header Size and position of each piece of the file Text segment Machine language instructions Data segment Binary representation of the data in the source file Relocation information Identifies instruction and data words that depend on the absolute addresses; In MIPS, only lw/sw and jal needs absolute address. Symbol table Global symbols defined in the file External references in the file Debugging information

Example Object files Object file header NameProcedure A Text Size0x100 Data size0x20 Text SegmentAddressInstruction 0lw $a0, 0($gp) 4jal 0 …… Data segment0(X)(X) …… Relocation informationAddressInstruction TypeDependency 0lwX 4jalB Symbol TableLabelAddress X – B –

Linker Why needs a linker? Save computing resources and time! A linker converts all object files to an executable file Resolve external symbols in all files Use symbol table in all files Search libraries for library functions Assign address to data and instruction in all files Place data and text segments of a file relative to other files Determine size of text and data segments for the program

Linking Object Files – An Example Object file header NameProcedure A Text Size0x100 Data size0x20 Text SegmentAddressInstruction 0lw $a0, 0($gp) 4jal 0 …… Data segment0(X)(X) …… Relocation informationAddressInstruction TypeDependency 0lwX 4jalB Symbol TableLabelAddress X – B –

The 2 nd Object File Object file header NameProcedure B Text Size0x200 Data size0x30 Text SegmentAddressInstruction 0sw $a1, 0($gp) 4jal 0 …… Data segment0(Y)(Y) …… Relocation informationAddressInstruction TypeDependency 0swswY 4jalA Symbol TableLabelAddress Y – A –

Solution Executable file header Text size0x300 Data size0x50 Text segmentAddressInstruction 0x Lw $a0, 0x8000($gp) 0x Jal 0x …… 0x Sw $a1, 0x8020($sp) 0x Jal 0x …… Data segmentAddress 0x (x) …… 0x (Y) ……

Loader A loader starts execution of a program Determine the size of text and data through executable’s header Allocate enough memory for text and data Copy data and text into the allocated memory Initialize registers Stack pointer Copy parameters to registers and stack Branch to the 1 st instruction in the program

Processor Fetch-Execute Cycle Instruction Fetch Instruction Decode Operand Fetch Execute Result Store Next Instruction Obtain instruction from program storage Determine required actions and instruction size Locate and obtain operand data Compute result value or status Deposit results in storage for later use Determine successor instruction

Example: Reverse a String (2/1) Write a MIPS procedure to reverse a null-terminated character string. Assume the address of the string is in $a0 and the address of the reversed string is in $a1. Also assume the spaces needed by the reversed string have been pre-allocated.

Example: Reverse a String (2/2) Write a MIPS procedure to reverse a null-terminated character string. Assume the address of the string is in $a0 and the address of the reversed string is in $a1. Also assume the spaces needed by the reversed string have been pre-allocated. reverseStr: addiu$sp, $sp, -32 sw$s0, 16($sp) sw$s1, 20($sp) move$s0, $a0 move$s1, $a1 addi$sp, $sp, -1 sb$zero, 0($sp) push:lbu$t0, 0($s0) beq$t0, $zero, pop addi$s0, $s0, 1 addi$sp, $sp, -1 sb$t0, 0($sp) jpush pop:lbu$t0, 0($sp) addi$sp, $sp, 1 sb$t0, 0($s1) beq$t0, $zero, done addi$s1, $s1, 1 jpop done:lw$s0, 16($sp) lw$s1, 20($sp) addi$sp, $sp, 32 jr$ra

Questions?