MIPS Hello World. MIPS Assembly 1. # PROGRAM: Hello, World! # Data declaration section. out_string:.asciiz "\nhello, World!\n"

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

Computer Organization Lab #3.

Chapter 2. Instructions:

MIPS Instruction Set

ENCM 369 Winter 2013: Reference Material for Midterm #2 page 1 of 5

Chapter 3. Instructions:

Instructions: Language of the Computer

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

MIPS%Assembly% E155%

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA

MIPS Reference Guide

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2)

Computer Architecture

CPS311 - COMPUTER ORGANIZATION. A bit of history

Computer Systems and Architecture

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011

CS3350B Computer Architecture MIPS Instruction Representation

SPIM Instruction Set

Sparse Notes on an MIPS Processor s Architecture and its Assembly Language

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers

MIPS Coding Snippets. Prof. James L. Frankel Harvard University. Version of 9:32 PM 14-Feb-2016 Copyright 2016 James L. Frankel. All rights reserved.

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1

ECE232: Hardware Organization and Design. Computer Organization - Previously covered

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

ECE 154A Introduction to. Fall 2012

ECE Exam I February 19 th, :00 pm 4:25pm

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers

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

Introduction to MIPS Processor

EN164: Design of Computing Systems Lecture 09: Processor / ISA 2

Topic Notes: MIPS Instruction Set Architecture

Computer Architecture

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations

MIPS Instruction Format

MACHINE LANGUAGE. To work with the machine, we need a translator.

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Chapter 2: Instructions:

Chapter 2A Instructions: Language of the Computer

Reduced Instruction Set Computer (RISC)

Instructions: Assembly Language

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

Architecture I. Computer Systems Laboratory Sungkyunkwan University

Assembly Language Programming

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

EEC 581 Computer Architecture Lecture 1 Review MIPS

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

MIPS Assembly Language. Today s Lecture

ECE260: Fundamentals of Computer Engineering

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats

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

Shift and Rotate Instructions

MIPS History. ISA MIPS Registers

Kernel Registers 0 1. Global Data Pointer. Stack Pointer. Frame Pointer. Return Address.

ECE260: Fundamentals of Computer Engineering

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013

Reduced Instruction Set Computer (RISC)

Lecture 6 Decision + Shift + I/O

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College

ECE 30 Introduction to Computer Engineering

Lecture 4: MIPS Instruction Set

Instruction encoding. MIPS Instruction encoding

ECE 15B Computer Organization Spring 2010

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

MIPS (SPIM) Assembler Syntax

COMPUTER ORGANIZATION AND DESIGN

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

Programming the processor

Chapter 2. Instructions: Language of the Computer

CS 351 Exam 2 Mon. 11/2/2015

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: MIPS Instruction Set Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization

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

Computer Architecture. The Language of the Machine

Compiling Techniques

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

2.1 DOWNLOAD AND INSTALL MARS

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design

Chapter Two MIPS Arithmetic

Computer Architecture. MIPS Instruction Set Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

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

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

The MIPS Instruction Set Architecture

MIPS Assembly Language

Unsigned Binary Integers

Unsigned Binary Integers

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

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

CSc 256 Midterm 2 Fall 2011

MIPS function continued

Concocting an Instruction Set

Lecture 5: Procedure Calls

CS 61c: Great Ideas in Computer Architecture

CS61C : Machine Structures

Transcription:

MIPS Hello World MIPS Assembly 1 # PROGRAM: Hello, World!.data # Data declaration section out_string:.asciiz "\nhello, World!\n".text # Assembly language instructions main: # Start of code section li $v0, 4 # system call code for printing string = 4 la $a0, out_string # load address of string to be printed into $a0 syscall # call operating system to perform operation in $v0 # syscall takes its arguments from $a0, $a1,... This illustrates the basic structure of an assembly language program. - data segment and text segment - use of label for data object (which is a zero-terminated ASCII string) - use of registers - invocation of a system call

MIPS Register Names MIPS Assembly 2 MIPS assemblers support standard symbolic names for the general-purpose registers: $zero $at $v0-1 $a0-3 $t0-9 $s0-7 $k0-1 $gp $sp $fp $ra stores value 0; cannot be modified reserved for use by the assembler used for system calls and procedure return values used for passing arguments to procedures used for local storage; caller saves used for local storage; procedure saves reserved for use by OS kernel pointer to area storing global data (data segment) stack pointer frame pointer; primarily used during stack manipulations used to store return address in procedure call

MIPS Arithmetic Instructions MIPS Assembly 3 All arithmetic and logical instructions have 3 operands Operand order is fixed (destination first): Example: <opcode> <dest>, <leftop>, <rightop> C code: a = b + c; MIPS code : add a, b, c (we ll talk about register syntax in a bit) The natural number of operands for an operation like addition is three requiring every instruction to have exactly three operands, no more and no less, conforms to the philosophy of keeping the hardware simple

Basic MIPS Arithmetic Instructions MIPS Assembly 4 Here are the most basic arithmetic instructions: add $rd,$rs,$rt Addition with overflow GPR[rd] <-- GPR[rs] + GPR[rt] div $rs,$rt Division with overflow $lo <-- GPR[rs]/GPR[rt] $hi <-- GPR[rs]%GPR[rt] mul $rd,$rs,$rt Multiplication without overflow GPR[rd] <-- (GPR[rs]*GPR[rt])[31:0] sub $rd,$rs,$rt Subtraction with overflow GPR[rd] <-- GPR[rs] - GPR[rt] Instructions "with overflow" will generate an runtime exception if the computed result is too large to be stored correctly in 32 bits. There are also versions of some of these that essentially ignore overflow, like addu.

Limitations and Trade-offs MIPS Assembly 5 Design Principle: simplicity favors regularity. Of course this complicates some things... C code: a = b + c + d; MIPS pseudo-code: add a, b, c add a, a, d Operands must be registers (or immediates), only 32 registers are provided Each register contains 32 bits Design Principle: smaller is faster. Why?

Immediates MIPS Assembly 6 In MIPS assembly, immediates are literal constants. Many instructions allow immediates to be used as parameters. addi li $t0, $t1, 42 # note the opcode $t0, 42 # actually a pseudo-instruction Note that immediates cannot be used with all MIPS assembly instructions; refer to your MIPS reference card. Immediates may also be expressed in hexadecimal: 0xFFFFFFFF

MIPS Logical Instructions MIPS Assembly 7 Logical instructions also have 3 operands: <opcode> <dest>, <leftop>, <rightop> Examples: and $s0, $s1, $s2 # bitwise AND andi $s0, $s1, 42 or $s0, $s1, $s2 # bitwise OR ori $s0, $s1, 42 nor $s0, $s1, $s2 # bitwise NOR (i.e., NOT OR) sll $s0, $s1, 10 # logical shift left srl $s0, $s1, 10 # logical shift right QTP: MIPS assembly doesn t include the logical operation not. Why? How would you achieve the effect of a logical not operation in MIPS assembly?

MIPS Load and Store Instructions MIPS Assembly 8 Transfer data between memory and registers Example: C code: A[12] = h + A[8]; MIPS code: lw $t0, 32($s3) # load word add $t0, $s2, $t0 sw $t0, 48($s3) # store word Can refer to registers by name (e.g., $s2, $t2) instead of number Load command specifies destination first: Store command specifies destination last: opcode <dest>, <address> opcode <dest>, <address> Remember arithmetic operands are registers or immediates, not memory! Can t write: add 48($s3), $s2, 32($s3)

Additional Load and Store Instructions MIPS Assembly 9 There are also load and store instructions that act on data objects smaller than a word: lw load word from specified address lh load half-word from specified address lb load byte from specified address sw store word to specified address sh store half-word to specified address sb store byte to specified address There are restrictions: For word-oriented operations, the address must be word-aligned (i.e., a multiple of 4). For half-word-oriented operations, the address must be half-word-aligned (i.e., a multiple of 2). Violating the restrictions causes a runtime exception. (See unaligned variants.)

Common Pitfall MIPS Assembly 10 Remember: - load instructions transfer data FROM memory TO a register - store instructions transfer data TO memory FROM a register

Addressing Modes MIPS Assembly 11 In register mode the address is simply the value in a register: lw $t0, ($s3) In immediate mode the address is simply an immediate value in the instruction: lw $t0, 0 # almost always a bad idea In base + register mode the address is the sum of an immediate and the value in a register: lw $t0, 100($s3) There are also various label modes: lw $t0, absval lw $t0, absval + 100 lw $t0, absval + 100($s3)

So far we ve learned MIPS Assembly 12 MIPS - loading words but addressing bytes - arithmetic on registers only # Instruction # Meaning add $s1, $s2, $s3 # $s1 = $s2 + $s3 sub $s1, $s2, $s3 # $s1 = $s2 $s3 lw $s1, 100($s2) # $s1 = Memory[$s2+100] sw $s1, 100($s2) # Memory[$s2+100] = $s1