syscall takes a service ID (number) in $v0 Read integer $v0=5, after syscall, $v0 holds the integer read from keyboard

Similar documents
Five classic components

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

Five classic components

CS/COE0447: Computer Organization

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

CS222: MIPS Instruction Set

ECE 154A Introduction to. Fall 2012

Memory. CS 447, Spring /25/16. Memory. Processor (CPU) transfer

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

Lecture 7: Examples, MARS, Arithmetic

ECE369. Chapter 2 ECE369

MIPS%Assembly% E155%

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

EEC 581 Computer Architecture Lecture 1 Review MIPS

MIPS Functions and the Runtime Stack

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

CSCI 402: Computer Architectures

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

CS/COE1541: Introduction to Computer Architecture

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Reduced Instruction Set Computer (RISC)

Operations, Operands, and Instructions

CS3350B Computer Architecture MIPS Instruction Representation

ECE260: Fundamentals of Computer Engineering

MIPS Reference Guide

Chapter 2A Instructions: Language of the Computer

ECE260: Fundamentals of Computer Engineering

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

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

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

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

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

MIPS Coding Continued

MIPS ISA and MIPS Assembly. CS301 Prof. Szajda

Reduced Instruction Set Computer (RISC)

MIPS Assembly Language Programming

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

Computer Architecture

Announcements HW1 is due on this Friday (Sept 12th) Appendix A is very helpful to HW1. Check out system calls

CSSE 232 Computer Architecture I. I/O and Addressing

MIPS Assembly Language Programming

CSEE 3827: Fundamentals of Computer Systems

COMPUTER ORGANIZATION AND DESIGN

ECE260: Fundamentals of Computer Engineering

Assembler. Lecture 8 CS301

Computer Architecture

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

Computer Architecture. MIPS Instruction Set Architecture

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

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer

Computer Organization and Components

Sheet For the following C code: a = b + c; b = a + c; d = a b; Write an equivalent assembly MIPS program. Solution:

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:

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

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

CS 61c: Great Ideas in Computer Architecture

EC 413 Computer Organization

ECE 30 Introduction to Computer Engineering

Lecture 7: MIPS Functions Part 2. Nested Function Calls. Lecture 7: Character and String Operations. SPIM Syscalls. Recursive Functions

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

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

COMP MIPS instructions 2 Feb. 8, f = g + h i;

Chapter 2. Computer Abstractions and Technology. Lesson 4: MIPS (cont )

Course Administration

Unsigned Binary Integers

Unsigned Binary Integers

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

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

Lecture 5: Procedure Calls

All instructions have 3 operands Operand order is fixed (destination first)

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

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

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

ECE260: Fundamentals of Computer Engineering

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

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

CSSE232 Computer Architecture. Logic and Decision Opera:ons

Instruction Set Architectures Part I: From C to MIPS. Readings:

Instructions: Language of the Computer

MIPS Assembly: More about MIPS Instructions Using Functions in MIPS CS 64: Computer Organization and Design Logic Lecture #8

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

Computer Organization MIPS ISA

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3

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

CENG3420 Lecture 03 Review

Architecture I. Computer Systems Laboratory Sungkyunkwan University

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Lecture 4: MIPS Instruction Set

Levels of Programming. Registers

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

Chapter 2. Instruction Set Architecture (ISA)

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

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

Instruction encoding. MIPS Instruction encoding

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

A crash course in MIPS assembly programming

Lectures 3-4: MIPS instructions

Transcription:

Interacting with the OS We need the OS s help!!! How to print a number? (output) How to read a number? (input) How to terminate (halt) a program? How to open, close, read, write a file? These are operating system services Special instruction: A software interrupt to invoke OS for an action (to do a service) Need to indicate the service to perform (e.g., print vs. terminate) May also need to pass an argument value (e.g., number to print) A few useful s takes a service ID (number) in $v Print integer $v=, $a=integer to print Read integer $v=, after, $v holds the integer read from keyboard Print string $v=, $a=memory address of string to print (null terminated) Exit (halt) $v=, no argument See MARS docs for more!!! Also, attend recitation. 6

Example: Print an integer # example as C program code # int a; # a = + 8; # print( %d, a); # code below carries out the above li $t, # $t is a, $t= addi $t,$t,8 # $t=+8 li $v, # print service add $a,$t,$ # pass value in $t to service # invoke OS to do service li $v, # terminate program service # invoke OS to do service Let s try it in MARS!!!! (mips.asm) 7 Example: More useful output li $t, # put into a addi $t,$t,8 # do the add with 8 li $v, # print string service la $a,msg # load string li $v, # print integer ervice add $a,$t,$ li $v, # terminate program # message to print before the number.data msg:.asciiz Sum of + 8 is\n Let s try it in MARS!!!! (mips.asm) 8

Example: Add + x? li $v, # print prompt la $a,x_msg li $v, # read integer service move $t,$v # number read in $v addi $t,$t, # add number with li $v, # print result prompt la $a,msg li $v, # print the sum move $a,$t li $v, # terminate program.data x_msg:.asciiz Number x to add?\n msg:.asciiz Sum of + x is\n Let s try it in MARS!!!! (mips.asm) 9 Memory transfer instructions Also called memory access instructions Only two types of instructions Load: move data from memory to register e.g., lw$s, ($t6) # $s memory[$t6 + ] Store: move data from register to memory e.g., sw $s7, 6($t) # memory[$t+6] $s7 In MIPS (-bit architecture) there are memory transfer instructions for -bit word: int type in C 6-bit half-word: short type in C 8-bit byte: char type in C

Memory view Memory is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array BYTE # BYTE # BYTE # BYTE # BYTE # BYTE # address gets this byte loads and stores give the index (address) to access 6 BYTE #6 7 BYTE #7 8 BYTE #8 Memory view Memory is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array BYTE # BYTE # BYTE # BYTE # BYTE # BYTE # address gets this halfword loads and stores give the index (address) to access 6 BYTE #6 7 BYTE #7 8 BYTE #8

Memory view Memory is a large, single-dimension 8-bit (byte) array with an address to each 8-bit item ( byte address ) A memory address is just an index into the array BYTE # BYTE # BYTE # BYTE # BYTE # BYTE # address gets this word loads and stores give the index (address) to access 6 BYTE #6 7 BYTE #7 8 BYTE #8 Address calculation Memory address is specified with (register, constant) pair Register to keep the base address Constant field to keep the offsetfrom the base address Address is, then (contents of register + offset) The offset can be positive or negative Suppose base register $t=6, then: lw $t, ($t) address = 6 + = 76 lw $t, -($t) address = 6 - = MIPS uses this simple address calculation method; other architectures such as PowerPC and x86 support different methods

Machine code example void swap(int v[], int k) { int temp; temp = v[k]; v[k] = v[k+]; v[k+] = temp; } swap: sll $t, $a, add $t, $a, $t lw $t, ($t) lw $t, ($t) sw $t, ($t) sw $t, ($t) jr $ra Let s try it in MARS!!!! (mips.asm) Memory organization -bit byte address bytes with byte addresses from to words with byte addresses,, 8,, Words are aligned least significant bits (LSBs) of an address are s Half words are aligned LSB of an address is 8 6 Addressing within a word Which byte appears first and which byte the last? Big-endian vs. little-endian Little end (LSB) comes first (at low address) Big end (MSB) comes first (at low address) Low address High address Little Big 6 6

More on alignment A misaligned access lw$s, ($t) How do we define a word at address? Data in byte,,, If you meant this, use the address, not Data in byte,,, 6 If you meant this, it is indeed misaligned! Certain hardware implementation may support this; usually not If you still want to obtain a word starting from the address get a byte from address, a word from address and manipulate the two data to get what you want Alignment issue does not exist for byte access 6 7 8 9 Let s try it in MARS!!!! (mips.asm) 8 7 Shift instructions Name Fields Comments R-format op NOT USED rt rd shamt funct shamt is shift amount Bits change their positions inside a word <op> <r target > <r source > <shift_amount> Examples sll$s, $s, # $s $s << srl$s6, $s, 6 # $s6 $s >> 6 Shift amount can be in a register ( shamt is not used) Shirt right arithmetic (sra) keeps the sign of a number sra$s7, $s, Let s try it in MARS!!!! (mips6.asm) 8 7