Computer Systems and Architecture

Similar documents
SPIM Instruction Set

MIPS Reference Guide

Introduction to MIPS Processor

MIPS Architecture and Assembly Language Overview

Assignment 1: Pipelining Implementation at SPIM Simulator

QtSPIM and MARS : MIPS Simulators

MIPS Assembly Language

COMP2421 COMPUTER ORGANZATION. Lab 3

Course Administration

Computer Architecture. The Language of the Machine

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

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.

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

MIPS Instruction Format

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

SPIM & MIPS Programming

MIPS Instruction Reference

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

MIPS Assembly Language Guide

F. Appendix 6 MIPS Instruction Reference

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

Compiling Techniques

TSK3000A - Generic Instructions

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

CSc 256 Midterm (green) Fall 2018

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

MIPS Instruction Set

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

CA226 Advanced Computer Architecture

M2 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.

MIPS Assembly Language. Today s Lecture

CSc 256 Midterm 2 Fall 2011

CSc 256 Midterm 2 Spring 2012

ECE 250 / CS 250 Computer Architecture. Procedures

The MIPS R2000 Instruction Set

MIPS function continued

CSc 256 Midterm 1 Fall 2011

CS 4200/5200 Computer Architecture I

The MIPS Instruction Set Architecture

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

Reduced Instruction Set Computer (RISC)

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

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

MIPS Assembly Language Programming

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

Reduced Instruction Set Computer (RISC)

The MIPS R2000 Instruction Set

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

MIPS Instructions: 64-bit Core Subset

ICS 233 COMPUTER ARCHITECTURE. MIPS Processor Design Multicycle Implementation

SPIM S20: A MIPS R2000 Simulator

CSc 256 Final Fall 2016

Question 0. Do not turn this page until you have received the signal to start. (Please fill out the identification section above) Good Luck!

Lecture 7: Examples, MARS, Arithmetic

Adventures in Assembly Land

MIPS Functions and the Runtime Stack

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

Computer Organization Lab #3.

instructions aligned is little-endian

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

CSE 2021: Computer Organization

MIPS Processor Overview

Q1: /30 Q2: /25 Q3: /45. Total: /100

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

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

ece4750-parc-isa.txt

ICS 233 Computer Architecture & Assembly Language. ICS 233 Computer Architecture & Assembly Language

Computer Architecture. MIPS Instruction Set Architecture

ECE 30 Introduction to Computer Engineering

Lec 10: Assembler. Announcements

Programming the processor

CS 61c: Great Ideas in Computer Architecture

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

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

ECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total

MIPS%Assembly% E155%

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

EECS 322 The SPIM simulator

MIPS Assembly Programming

Lecture # 1. SPIM & MIPS Programming

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

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

SPIM & MIPS Programming

INSTRUCTION SET COMPARISONS

Lecture 6 Decision + Shift + I/O

CDA3100 Midterm Exam, Summer 2013

Graduate Institute of Electronics Engineering, NTU. SPIM and MIPS Asm. Presenter: 沈文中 (TA) Date: 2004/10/13

ECE 2035 A Programming Hw/Sw Systems Fall problems, 8 pages Final Exam 8 December 2014

ECE 2035 Programming Hw/Sw Systems Fall problems, 10 pages Final Exam 9 December 2013

Exam in Computer Engineering

2.1 DOWNLOAD AND INSTALL MARS

Lecture 5: Procedure Calls

ECE 2035 Programming HW/SW Systems Fall problems, 6 pages Exam Two 23 October Your Name (please print clearly) Signed.

ECE 15B Computer Organization Spring 2010

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

MIPS Assembly (Functions)

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Lecture 7: Procedures

Character Is a byte quantity (00~FF or 0~255) ASCII (American Standard Code for Information Interchange) Page 91, Fig. 2.21

Transcription:

Computer Systems and Architecture Stephen Pauwels MIPS: Introduction Academic Year 2018-2019

Outline MIPS Registers and Memory Language Constructs Exercises

Assembly Language Very closely related to machine language easier to read MIPS MARS: MIPS Assembler and Runtime Simulator

Example: Add # add.asm: A program that computes the sum of 1 and 2 # leaving the result in register $0. # Registers used: # t0 : used to hold the result # t1 : used to hold the constant 1 li $t1, 1 # load value 1 into $t1 addi $t0, $t1, 2 # $t0 = $t1 + 2 # end of add.asm

Labels Symbolic name for an address in memory Jump to a label with the branch instructions # add.asm: A program that computes the sum of 1 and 2 # leaving the result in register $t0. # Registers used: # t0 : used to hold the result # t1 : used to hold the constant 1 main: # start execution at main li $t1, 1 # load value 1 into $t1 j add # jump to label add addi $t0, $t1, 1 # $t0 = $t1 + 1 add: addi $t0, $t1, 2 # $t0 = $t1 + 2 # end of add.asm

Registers 32 normal registers 32 floating point registers (single precision) Register usage guidelines: Symbolic Name Number Usage zero 0 Constant 0 at 1 Reserved for assembler v0 v1 2 3 Result registers a0 a3 4 7 Argument registers t0 t9 8 15, 24 25 Temporary registers s0 s7 16 23 Saved registers k0 k1 26 27 Kernel registers gp 28 Global data pointer sp 29 Stack pointer fp 30 Frame pointer ra 31 Return address f0 f31 Floating point registers

Syscalls Suspends the execution of your program and transfers control to the operating system Register $v0 contains operation code. Service Code Arguments Result print_int 1 $a0 none print_float 2 $f12 none print_double 3 $f12 none print_string 4 $a0 none read_int 5 none $v0 read_float 6 none $f0 read_double 7 none $f0 read_string 8 $a0 (address), $a1 (length) none sbrk 9 $a0 (length) $v0 exit 10 none none

Syscall: example # add.asm: A program that computes the sum of 1 and 2 # Printing the result # Registers used: # t0 : used to hold the result # t1 : used to hold the constant 1 main: li $t1, 1 # load 1 into $t1 addi $t0, $t1, 2 # $t0 = $t1 + 2 move $a0, $t0 # set result to $a0 li $v0, 1 # load code for print_int syscall exit: li $v0, 10 # load code for exit syscall # end of add.asm

Memory Allocate space for variables and data in memory Assembler directives.text and.data Data directives:.ascii string.asciiz string (null-terminated).byte 8-bit integers.half 16-bit integers.space n bytes of space.word 32-bit integers Load and store data to and from memory with lw and sw (load and store words)

Memory: example (1) # helloworld.asm: A Hello World program. # Registers used: # $v0 : syscall parameter and return value # $a0 : syscall parameter: the string to print.data hello_msg:.asciiz Hello World!\n main: exit:.text la $a0, hello_msg # load the addr of hello_msg in $a0 li $v0, 4 # load code for print_string syscall li $v0, 10 # load code for exit syscall

Memory: example (2) # loadandstore.asm: Demonstrate load and store instructions # by implementing c = a + b.data var_a:.word 5 # variable a var_b:.word 8 # variable b var_c:.word 0 # variable c main:.text lw $t1, var_a # load a in $t1 lw $t2, var_b # load b in $t2 add $t0, $t1, $t2 # add a and b sw $t0, var_c # store sum into c exit: li $v0, 10 syscall # load code for exit

Conditional statements # conditional.asm # c = max(a, b).data var_a:.word 8 # variable a var_b:.word 14 # variable b var_c:.word 0 # variable c main:.text lw $t1, var_a # load a in $t1 lw $t2, var_b # load b in $t2 #conditional: if a > b bgt $t1, $t2, t1_greater # branch if $t1 > $t2 sw $t2, var_c # store b into c j endif # jump to endif t1_greater: sw $t1, var_c # store a into c endif: li $v0, 10 # load code for exit syscall

Loops # loop.asm # c = a x b.data var_a:.word 8 # variable a var_b:.word 5 # variable b var_c:.word 0 # variable c main:.text lw $t1, var_a # load a in $t1 lw $t2, var_b # load b in $t2 #loop: add a to result, do this b times li $t0, 0 # loop register li $t3, 0 # result register loop: bge $t0, $t2, endloop # end loop if loop register >= b add $t3, $t3, $t1 # add a to result addi $t0, $t0, 1 # increase loop register j loop # jump to loop endloop: sw $t3, var_c # store result into c

Exercises Blackboard Course webpage http://msdl.cs.mcgill.ca/people/hv/teaching/computersystemsarchitecture/#cs6

Overview of arithmetic instructions ADD ADDI ADDIU ADDU SUB, SUBI, SUBIU, SUBU MUL, MULU DIV, DIVU ADD.S ADD.D SUB.S, SUB.D MUL.S, MUL.D DIV.S, DIV.D Addition (with overflow) Addition immediate (with overflow) Addition immediate unsigned (no overflow) Addition unsigned (no overflow) Identical to ADD but with subtraction Identical to ADD but with multiplication Identical to ADD but with division Addition (single precision) Addition (double precision) Subtraction (single or double precision) Multiplication (single or double precision) Division (single or double precision)

Overview of logical instructions AND ANDI OR ORI XOR XORI Bitwise and Bitwise and immediate Bitwise or Bitwise or immediate Bitwise exclusive or Bitwise exclusive or immediate

Overview of branching instructions BEQ(Z) BGE(Z) BGT(Z) BLE(Z) BLT(Z) BNE(Z) J JAL JR Branch on equal than (zero) Branch on greater than or equal to (zero) Branch on greater than (zero) Branch on less than or equal to (zero) Branch on less than (zero) Branch on not equal to (zero) Jump Jump and link Jump register

Overview of store/load instructions LB LH LW LA Load byte Load half-word Load word Load address SB SH SW Store byte Store half-word Store word