CS153 Greg Morrisett. Quick overview of the MIPS instruction set.  We're going to be compiling to MIPS assembly language.  So you need to know how to.

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.
Lecture 5: MIPS Instruction Set
CS/COE0447 Computer Organization & Assembly Language
Statement Format MIPS assembly language statements have the following format label: opcode operand,operand,operand # comment Label identifies the statement.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 5 MIPS ISA & Assembly Language Programming.
ELEN 468 Advanced Logic Design
Chapter 2 Instructions: Language of the Computer
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
MIPS Assembler Programming
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.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
Computer Architecture - The Instruction Set The Course’s Goals  To be interesting and fun. An interested student learns more.  To answer questions that.
VHDL Synthesis of a MIPS-32 Processor Bryan Allen Dave Chandler Nate Ransom.
MIPS Instruction Set Advantages
Linked Lists in MIPS Let’s see how singly linked lists are implemented in MIPS on MP2, we have a special type of doubly linked list Each node consists.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Computer Organization and Design Instruction Sets Montek Singh Wed, Sep 12, 2012 Lecture 5.
CSE378 Instr. encoding.1 Instruction encoding The ISA defines –The format of an instruction (syntax) –The meaning of the instruction (semantics) Format.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
6.S078 - Computer Architecture: A Constructive Approach Introduction to SMIPS Li-Shiuan Peh Computer Science & Artificial Intelligence Lab. Massachusetts.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
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
Small constants are used quite frequently (50% of operands) e.g., A = A + 5; B = B + 1; C = C - 18; Solutions? Why not? put 'typical constants' in memory.
True Assembly Language Part I. The Assembly Process The process of translating a MAL code (an assembly language program) into machine code (a sequence.
 1998 Morgan Kaufmann Publishers MIPS arithmetic All instructions have 3 operands Operand order is fixed (destination first) Example: C code: A = B +
RISC Processor Design RISC Instruction Set Virendra Singh Indian Institute of Science Bangalore Lecture 8 SE-273: Processor Design.
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.
CENG 311 Instruction Representation
MIPS Instructions Instructions: Language of the Machine
MIPS Assembly Language Chapter 13 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
EE 3755 Datapath Presented by Dr. Alexander Skavantzos.
EEL5708/Bölöni Lec 3.1 Fall 2006 Sept 1, 2006 Lotzi Bölöni EEL 5708 High Performance Computer Architecture Lecture 3 Review: Instruction Sets.
MIPS Assembly Language Chapter 15 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
CDA 3101 Spring 2016 Introduction to Computer Organization
The Assembly Process Computer Organization and Assembly Language: Module 10.
Instruction Set Architecture Chapter 3 – P & H. Introduction Instruction set architecture interface between programmer and CPU Good ISA makes program.
Control Structures Computer Organization I 1 October 2009 © McQuain, Feng & Ribbens Conditional Control Structure if ( i < j ) goto A; else.
Instructor: Prof. Hany H Ammar, LCSEE, WVU
Digital Logic Design Alex Bronstein
CSCI206 - Computer Organization & Programming
MIPS Instruction Set Advantages
Computer Organization and Design Instruction Sets - 2
MIPS Coding Continued.
ELEN 468 Advanced Logic Design
Computer Organization and Design Instruction Sets - 2
RISC Concepts, MIPS ISA Logic Design Tutorial 8.
ENGR 3410 – Computer Architecture Mark L. Chang Fall 2006
Computer Architecture (CS 207 D) Instruction Set Architecture ISA
Computer Organization and Design Instruction Sets
ECE/CS 552: Instruction Sets – MIPS
CSCI206 - Computer Organization & Programming
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
Henk Corporaal TUEindhoven 2010
Computer Architecture & Operations I
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
Flow of Control -- Conditional branch instructions
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
MIPS Instruction Set Architecture
Flow of Control -- Conditional branch instructions
MIPS Coding Continued.
CS352H Computer Systems Architecture
9/27: Lecture Topics Memory Data transfer instructions
Conditional Branching (beq)
Presentation transcript:

CS153 Greg Morrisett

Quick overview of the MIPS instruction set.  We're going to be compiling to MIPS assembly language.  So you need to know how to program at the MIPS level.  Helps to have a bit of architecture background to understand why MIPS assembly is the way it is. There's an online manual that describes things in gory detail.

 We write assembly language instructions  e.g., “ addi $r1, $r2, 42 ”  The machine interprets machine code bits  e.g., “ …”  Your first assignment is to build an interpreter for a subset of the MIPS machine code.  The assembler takes care of compiling assembly language to bits for us.  It also provides a few conveniences as we’ll see.

int sum(int n) { sum: ori $2,$0,$0 int s = 0; b test for (; n != 0; n--) loop: add $2,$2,$4 s += n; subi $4,$4,1 } test: bne $4,$0,loop j $31 int main() { main: ori $4,$0,42 return sum(42); move $17,$31 }jal sum jr $17

_sum: pushq%rbp movq%rsp, %rbp movl%edi, -4(%rbp) movl$0, -12(%rbp) jmpLBB1_2 LBB1_1: movl-12(%rbp), %eax movl-4(%rbp), %ecx addl%ecx, %eax movl%eax, -12(%rbp) movl-4(%rbp), %eax subl$1, %eax movl%eax, -4(%rbp) LBB1_2: movl-4(%rbp), %eax cmpl$0, %eax jneLBB1_1 movl-8(%rbp), %eax popq%rbp ret _main: pushq%rbp movq%rsp, %rbp subq$16, %rsp movl$42, %eax movl%eax, %edi callq_sum movl%eax, %ecx movl%ecx, -8(%rbp) movl-8(%rbp), %ecx movl%ecx, -4(%rbp) movl-4(%rbp), %eax addq$16, %rsp popq%rbp ret

_sum: pushq%rbp movq%rsp, %rbp popq%rbp ret _main: pushq%rbp movq%rsp, %rbp popq%rbp ret

 Reduced Instruction Set Computer (RISC)  Load/store architecture  All operands are either registers or constants  All instructions same size (4 bytes) and aligned on 4-byte boundary.  Simple, orthogonal instructions ▪e.g., no subi, ( addi and negate value)  All registers (except $0) can be used in all instructions. ▪Reading $0 always returns the value 0  Easy to make fast: pipeline, superscalar

 Complex Instruction Set Computer (CISC)  Instructions can operate on memory values ▪e.g., add [eax],ebx  Complex, multi-cycle instructions ▪e.g., string-copy, call  Many ways to do the same thing ▪e.g., add eax,1 inc eax, sub eax,-1  Instructions are variable-length (1-10 bytes)  Registers are not orthogonal  Hard to make fast…(but they do anyway)

 x86 (as opposed to MIPS):  Lots of existing software.  Harder to decode (i.e., parse).  Harder to assemble/compile to.  Code can be more compact (3 bytes on avg.)  I-cache is more effective…  Easier to add new instructions.  Todays implementations have the best of both:  Intel & AMD chips suck in x86 instructions and compile them to “micro-ops”, caching the results.  Core execution engine more like MIPS.

 Arithmetic & logical instructions:  add, sub, and, or, sll, srl, sra, …  Register and immediate forms:  add $rd, $rs, $rt  addi $rd, $rs,  Any registers (except $0 returns 0)  Also a distinction between overflow and no- overflow (we’ll ignore for now.)

Op1:6 rs:5 rt:5 rd:5 0:5 Op2:6 Op1:6 rs:5 rt:5 imm:16 add $rd, $rs, $rt addi $rt, $rs,

 Assembler provides pseudo-instructions: move $rd, $rs  or $rd, $rs, $0 li $rd,  lui $rd, ori $rd, $rd,

 Multiply and Divide  Use two special registers mflo, mfhi  i.e., mul $3, $5 produces a 64-bit value which is placed in mfhi and mflo.  Instructions to move values from mflo / hi to the general purpose registers $r and back.  Assembler provides pseudo-instructions:  mult $2, $3, $5 expands into: mul $3,$5 mflo $2

 Load/store  lw $rd, ($rs) ; rd := Mem[rs+imm]  sw $rs, ($rt) ; Mem[rt+imm] := rs  Traps (fails) if rs+imm is not word-aligned.  Other instructions to load bytes and half- words.

 beq $rs,$rt, if $rs == $rt then pc := pc + imm16  bne $rs,$rt,  b == beq $0,$0,  bgez $rs, if $rs >= 0 then pc := pc + imm16  Also bgtz, blez, bltz  Pseudo instructions: b $rs,$rt,

Assembler lets us use symbolic labels instead of having to calculate the offsets. Just as in BASIC, you put a label on an instruction and then can branch to it: LOOP : … bne $3, $2, LOOP Assembler figures out actual offsets.

 slt $rd, $rs, $rt ; rd := (rs < rt)  slt $rd, $rs,  Additionally: sltu, sltiu  Assembler provides pseudo-instructions for seq, sge, sgeu, sgt, sne, …

 j ; pc := (imm26 << 2)  jr $rs ; pc := $rs  jal ; $31 := pc+4 ; pc := (imm26 << 2)  Also, jalr and a few others.  Again, in practice, we use labels: fact : … main : … jal fact

 Floating-point (separate registers $fi)  Traps  OS-trickery

int sum(int n) { sum: ori $2,$0,$0 int s = 0; b test for (; n != 0; n--) loop: add $2,$2,$4 s += n; subi $4,$4,1 } test: bne $4,$0,loop j $31 int main() { main: ori $4,$0,42 return sum(42); move $17,$31 }jal sum jr $17

int sum(int n) { sum: ori $2,$0,$0 int s = 0; b test for (; n != 0; n--) loop: add $2,$2,$4 s += n; subi $4,$4,1 } test: bne $4,$0,loop j $31 int main() { main: ori $4,$0,42 return sum(42); jsum }

We're going to program to the MIPS virtual machine which is provided by the assembler.  lets us use macro instructions, labels, etc.  (but we must leave a scratch register for the assembler to do its work.)  lets us ignore delay slots.  (but then we pay the price of not scheduling those slots.)