Course Administration

Similar documents
MIPS (SPIM) Assembler Syntax

Course Administration

CS3350B Computer Architecture MIPS Introduction

CS3350B Computer Architecture

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

QtSPIM and MARS : MIPS Simulators

COMP2421 COMPUTER ORGANZATION. Lab 3

MIPS Processor Overview

Computer Architecture

SPIM Instruction Set

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

ECE 30 Introduction to Computer Engineering

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

CS3350B Computer Architecture MIPS Instruction Representation

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

Computer Systems and Architecture

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Computer Organization MIPS ISA

MIPS Architecture and Assembly Language Overview

Reduced Instruction Set Computer (RISC)

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

Chapter 2: Instructions:

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

CPSC 330 Computer Organization

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

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

Chapter 2. Instruction Set Architecture (ISA)

Reduced Instruction Set Computer (RISC)

Lecture 7: Examples, MARS, Arithmetic

CS/COE1541: Introduction to Computer Architecture

Field 6-Bit Op Code rs Field rt Field 16-bit Immediate field

Lecture 5: Procedure Calls

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

ECE 30 Introduction to Computer Engineering

Instructions: MIPS arithmetic. MIPS arithmetic. Chapter 3 : MIPS Downloaded from:

Branch Addressing. Jump Addressing. Target Addressing Example. The University of Adelaide, School of Computer Science 28 September 2015

instructions aligned is little-endian

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

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

Computer Science and Engineering 331. Midterm Examination #1. Fall Name: Solutions S.S.#:

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

MIPS Assembly Language. Today s Lecture

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

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 Reference Guide

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Chapter 2A Instructions: Language of the Computer

Compiling Techniques

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

Computer Architecture. Chapter 2-2. Instructions: Language of the Computer

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

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

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

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

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

SPIM & MIPS Programming

Systems Architecture I

CENG3420 Lecture 03 Review

EE 361 University of Hawaii Fall

Chapter 2. lw $s1,100($s2) $s1 = Memory[$s2+100] sw $s1,100($s2) Memory[$s2+100] = $s1

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

MIPS Assembly Language

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

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

Do-While Example. In C++ In assembly language. do { z--; while (a == b); z = b; loop: addi $s2, $s2, -1 beq $s0, $s1, loop or $s2, $s1, $zero

Machine Instructions - II. Hwansoo Han

CSSE 232 Computer Architecture I. I/O and Addressing

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

Assignment 1: Pipelining Implementation at SPIM Simulator

Thomas Polzer Institut für Technische Informatik

Control Instructions. Computer Organization Architectures for Embedded Computing. Thursday, 26 September Summary

Control Instructions

Course Administration

Communicating with People (2.8)

MIPS Assembly Language Programming

Lecture 6: Assembly Programs

COMPUTER ORGANIZATION AND DESIGN

MIPS Assembly Language Programming

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

CS3350B Computer Architecture MIPS Procedures and Compilation

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

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

MIPS Assembly Language Guide

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

Architecture II. Computer Systems Laboratory Sungkyunkwan University

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

CENG3420 Lab 1-1: MIPS assembly language programing

M2 Instruction Set Architecture

Lecture 4: MIPS Instruction Set

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.

comp 180 Lecture 10 Outline of Lecture Procedure calls Saving and restoring registers Summary of MIPS instructions

MIPS function continued

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

CSE 2021: Computer Organization

Introduction to MIPS Processor

MIPS%Assembly% E155%

CS222: MIPS Instruction Set

Instructions: Language of the Computer

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

Lecture 5: Procedure Calls

Transcription:

Fall 2017 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture Introduction 3/4 Avinash Kodi Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701 E-mail: avinashk@eecs.ohio.edu Website: http://oucsace.cs.ohiou.edu/~avinashk/classes/ee461a/ee461a.htm Course Administration SPIM (or Qt-SPIM) tutorial today in-class 1

MIPS ISA So Far Category Instr Op Code Example Meaning Arithmetic (R & I format) Data Transfer (I format) Cond. Branch (I & R format) Uncond. Jump (J & R format) add 0 and 32 add $s1, $s2, $s3 $s1 = $s2 + $s3 subtract 0 and 34 sub $s1, $s2, $s3 $s1 = $s2 - $s3 add immediate 8 addi $s1, $s2, 6 $s1 = $s2 + 6 or immediate 13 ori $s1, $s2, 6 $s1 = $s2 v 6 load word 35 lw $s1, 24($s2) $s1 = Memory($s2+24) store word 43 sw $s1, 24($s2) Memory($s2+24) = $s1 load byte 32 lb $s1, 25($s2) $s1 = Memory($s2+25) store byte 40 sb $s1, 25($s2) Memory($s2+25) = $s1 load upper imm 15 lui $s1, 6 $s1 = 6 * 2 16 br on equal 4 beq $s1, $s2, L if ($s1==$s2) go to L br on not equal 5 bne $s1, $s2, L if ($s1!=$s2) go to L set on less than 0 and 42 slt $s1, $s2, $s3 if ($s2<$s3) $s1=1 else $s1=0 set on less than immediate 10 slti $s1, $s2, 6 if ($s2<6) $s1=1 else $s1=0 jump 2 j 2500 go to 10000 jump register 0 and 8 jr $t1 go to $t1 jump and link 3 jal 2500 go to 10000; $ra=pc+4 See handout Other Instructions 2

Register Organization Name Register Number Usage Preserved on Call $zero 0 Constant Value of 0 n.a. $v0-$v1 2-3 Values for results and expressions $a0-$a3 4-7 Arguments No $t0-$t7 8-15 Temporaries No $s0-$s7 16-23 Saved Yes $t8-$t9 24-25 More Temporaries No $gp 28 Global Pointer Yes $sp 29 Stack Pointer Yes $fp 30 Frame Pointer Yes $ra 31 Return Address Yes No What about Register 1? Example - 1 Write a MIPS code to move 100 signed 16-bits signed from memory location A (0x00001000) to memory location B (0x00002000) addi $s1, $zero, 4096 \\ load the address A into $s1 addi $s2, $zero, 8192 \\ load the address B into $s2 addi $t0, $zero, 100 \\ load the counter into $t0 LOOP: lh $s3, 0($s1) \\ load halfword into $s3 sh $s3, 0($s2) \\ store halfword from $s3 addi $s1, $s1, 2 \\ adjust the address for A addi $s2, $s2, 2 \\ adjust the address for B subi $t0, $t0, 1 \\ reduce the counter bneq $t0, $zero, LOOP \\ test the loop: $t0 - $zero =? 3

Example - 2 Write a MIPS code to move 100, 4-byte numbers from memory location A (0x00001000) to memory location B (0x00002000) if the number is positive; else to memory location C (0x00003000) addi $s1, $0, 4096 \\ load the address A into $s1 addi $s2, $0, 8192 \\ load the address B into $s2 addi $s3, $0, 12288 \\ load the address C into $s3 addi $t0, $0, 100 \\ load the counter into $t0 LOOP: lw $s4, 0($s1) \\ load word into $s3 addi $s1, $s1, 4 \\ loop adjust for address A stl $t1, $s4, $0 \\ $t1 = 1 if $s3 < $0 beq $t1, $0, POSITIVE \\ Comparing $t1 = $zero? sw $s4, 0($s3) \\ NEGATIVE, so load into C addi $s3, $s3, 4 \\ loop adjust for address C j LOOPADJUST POSITIVE: sw $s4, 0($s2) \\ POSITIVE, so load into B addi $s2, $s2, 4 \\ loop adjust for address B LOOPADJUST: subi $t0, $t0, 1 bneq $t0, $zero, LOOP \\ test the loop: $t0 - $zero =? Assembly Language Programming Source Assembler Object Source Assembler Object Linker Executable Source Assembler Object Program Library 4

Unix Object Format Header (contains sizes of other parts) Text (machine code) Data (global and static data) Symbol table (associates addresses with external labels, lists unresolved references) Relocation Table (identifies instructions and data words that rely on absolute addresses) Debug (information contains a precise description of the way the program was compiled) Header Text Data Symbol Table Relocation Table (maps symbols to instructions) Debug Information MIPS Layout CPU Registers ($0 - $31) ALU Unit Multiply/Divide Lo and Hi Registers (to store totally 64 bits) Coprocessor 1 (Floating Point Unit) Registers ($0 - $31) ALU Coprocessor 0 (Traps and Memory) BadVAddr, Status, Cause, EPC 0x7FFF FFFC 0x10000000 PC = 0x00400000 Stack Heap Data Static Data Text Reserved 5

System Calls System calls provide a way to communicate (input/output) Certain system calls use specific data during the execution of the (primarily $v0 and $a0) Service System Call Code Arguments print_int 1 $a0 = integer print_float 2 $f12 = float print_double 3 $f12 = double print_string 4 $a0 = string Result read_int 5 integer (in $v0) read_string 8 $a0 = buffer, $a1 = length exit 10 print_char 11 $a0 = char read_char 12 char (in $v0) Examples of System Calls Assembly Code # Get an integer from user li $v0, 5 Explanation # Load immediate system code 5 into $v0 # System call command get integer from # user returned in $v0 # Print out the Result li $v0, 1 move $a0, $t0 # code for print_int # put result in $a0 # print out the result 6

Directives Directives Explanation.align n Align the next datum on a 2 n boundary (Example.align 2 aligns the next value on a word boundary).ascii str.asciiz str.data <addr>.byte b1,. bn.globl sym.space n.text <addr>.word w1, wn Store the string str in memory, but do not null terminate it Store the string str in memory and null terminate it Subsequent items are stored in the data segment. If optional argument addr is present, subsequent items are stored starting at addr Store the n values in successive memory locations Declare the label sym is global and can be referenced from other files Allocate n bytes of space in the current segment Subsequent items are put in the user text segment (instructions) Store the n 32-bit quantities in successive memory words Labels Labels notify the program to attach a name to a data declaration or a text (program) line Each data entry must be labeled a unique name or label The specific name main MUST be the first line of text Labels are always followed by semicolon Examples string: prompt:.asciiz Hello World\n.asciiz Enter your name\n 7

Hello World Program # This is a simple program to print hello world # a comment starts with a # till the end of the line.data # start putting stuff in the data segment greet:.asciiz "Hello world\n # declare greet to be the string.text #start putting stuff in the text segment main: # main is a label here. Names a function li $v0, 4 # system call code for print_str(sect1.5) la $a0, greet # address of string to print # print the string Example 2 Ask the user for his name and display it back to him! Should look like: Please Enter Your Name xxxxxx Your Name is xxxxxx 8

Solution.data yourname:.asciiz "Please Enter Your Name\n" name:.space 16 nameprint:.asciiz "Your name is\n" main:.globl main.text li $v0,4 la $a0,yourname li $v0,8 la $a0,name li $a1,16 li $v0,4 la $a0,nameprint li $v0,4 la $a0,name Example 3-4 From previous example, enter a number after name, add 100 to it and display the number back to the user! Sum all numbers from 1 to 10 and display the result 9