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

Similar documents
Chapter 2A Instructions: Language of the Computer

Lecture 4: MIPS Instruction Set

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

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

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

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

MIPS%Assembly% E155%

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

ECE232: Hardware Organization and Design

Lecture 5: Procedure Calls

Computer Architecture

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

Computer Organization MIPS ISA

Course Administration

MIPS Datapath. MIPS Registers (and the conventions associated with them) MIPS Instruction Types

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

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

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

ECE 331 Hardware Organization and Design. Professor Jay Taneja UMass ECE - Discussion 3 2/8/2018

Instructions: Assembly Language

CENG3420 Lecture 03 Review

Unsigned Binary Integers

Unsigned Binary Integers

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

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

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

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Computer Organization MIPS Architecture. Department of Computer Science Missouri University of Science & Technology

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

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

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

CSEE 3827: Fundamentals of Computer Systems

Instructions: Language of the Computer

CS3350B Computer Architecture MIPS Instruction Representation

Computer Architecture

CS/COE1541: Introduction to Computer Architecture

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

Topic Notes: MIPS Instruction Set Architecture

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

Control Instructions

COMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture

Computer Architecture. The Language of the Machine

Instruction Set Architecture

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

Lectures 3-4: MIPS instructions

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Computer Architecture. MIPS Instruction Set Architecture

Course Administration

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

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

Levels of Programming. Registers

Chapter 2. Instructions: Language of the Computer

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

MIPS Instruction Set

Assembler. Lecture 8 CS301

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

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

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

COMPUTER ORGANIZATION AND DESIGN

ECE 486/586. Computer Architecture. Lecture # 7

Grading: 3 pts each part. If answer is correct but uses more instructions, 1 pt off. Wrong answer 3pts off.

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

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

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

Instructions: Language of the Computer

I-Format Instructions (3/4) Define fields of the following number of bits each: = 32 bits

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

MIPS Instruction Set Architecture (2)

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

Five classic components

Instruction Set Architecture. "Speaking with the computer"

Reduced Instruction Set Computer (RISC)

EEC 581 Computer Architecture Lecture 1 Review MIPS

CS3350B Computer Architecture MIPS Introduction

Architecture I. Computer Systems Laboratory Sungkyunkwan University

CSCI 402: Computer Architectures

Reduced Instruction Set Computer (RISC)

CS222: MIPS Instruction Set

CS31001 COMPUTER ORGANIZATION AND ARCHITECTURE. Debdeep Mukhopadhyay, CSE, IIT Kharagpur. Instructions and Addressing

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

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

CS 61C: Great Ideas in Computer Architecture. MIPS Instruction Formats

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

Computer Hardware Engineering

CS 61c: Great Ideas in Computer Architecture

Thomas Polzer Institut für Technische Informatik

ECE 154A Introduction to. Fall 2012

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

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

MODULE 4 INSTRUCTIONS: LANGUAGE OF THE MACHINE

CSE 141 Computer Architecture Spring Lecture 3 Instruction Set Architecute. Course Schedule. Announcements

EE 361 University of Hawaii Fall

ECE260: Fundamentals of Computer Engineering

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

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

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

MIPS PROJECT INSTRUCTION SET and FORMAT

Computer Organization and Components

Memory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention

Transcription:

Instructions: ti Language of the Computer Rui Wang, Assistant professor Dept. of Information and Communication Tongji University it Email: ruiwang@tongji.edu.cn

Computer Hierarchy Levels Language understood by the computer s hardware: machine language(0101..) Usually discussed in terms of assembly language 2

3

Some concepts Instruction set: collection of instructions that a processor can execute A compiler translates a high level language, which is architecture independent, into assembly language, which is architecture dependent. An assembler translates assembly language programs into executable binary codes.. 4

MIPS assembly language MIPS is a reduced instruction set computer (RISC) instruction set architecture (ISA) developed by MIPS Technologies The early MIPS architectures were 32-bit, and later versions were 64-bit Used areas: embedded system, supercomputer Portable Game Device with Two MIPS Chips 5

2.2 Operations of the computer hardware 6

7

8

9

10

2.3 Operands of the computer hardware Operands must be from a limited number of Registers; ; Register: a special location built directly in hardware. With a size of 32 bits = length of a word Byte = 8 bits MIPS has 32 registers 11

12

2.3 Operands of the computer hardware Memory operands Only a small amount of data is kept in registers Large data structures (like array) are kept in the memory Data transfer function: A command that t moves data between memory and register 13

2.3 Operands of the computer hardware To access a word in memory, the instruction must supply the memory address Address: a value used to denote the location of a specific data elements in a memory array. 14

Load a word 15

8 is a offset $s3 is a base register 16

Alignment restriction: in MIPS, words must start at addresses that are multiples of 4. 17

Big-Endian and Little-Endian Formats In a byte-addressable machine, two choices for the order in which the bytes are stored in memory: most significant byte at lowest address, referred to as big-endian, or least significant byte stored at lowest address, referred to as little-endian 18

The "most significant" byte is the one for the largest powers of two: 2 31,..., 2 24. The "least significant" byte is the one for the smallest powers of two: 2 7,..., 2 0. 32-bit pattern 0x12345678 is at address 0x00400000. The most significant byte is 0x12; the least significant ifi is 0x78. 19

Store a word 20

21

Constant or Immediate operands Add instruction with only one operand is called add immediate or addi. 22

Constant or Immediate operands 23

2.4 Representing instruction in the computer Decimal number: base 10 number Binary number: base 2 number Hexadecimal number: base 16 number 24

25

2.4 Representing instruction in the computer In MIPS assembly language Register $s0 - $s7 = Register 16 23 Register $t0 - $t7 = Register 8 15 26

Field: each of these segment 0 and 32 (two fields in combination) tell the computer perform addition 17 = $s1, 18 = $s2, 8 = $t0 The fifth field is unused 27

MIPS instruction is 32 bit long Equal to the length of word 28

29

I-type or I-format: used for data transfer 30

31

32

2.5 Logic operations Sll: shift left logical, l Srl: shift right logical l Shift: move all the bits in a word to left or right, filling the emptied bits with 0s. Shifting left by i bits gives the same result as multiplying by 2^i 33

Machine language version Shamt = 4: stand for the shift amount 0 in both op and funct fileds rd = $t2 rt = $s0 rs = 0 is unused 34

AND: bit-by-bit operation that leaves 1 in the result if both bits of the operands are 1. = 35

or: bit-by-bit operation that leaves 1 in the result if either operand is 1. = 36

NOT: a logic bit-by-bit b operation with one operand that inverts the bits, i.e., it replace every 1 with 0, and every 0 with 1; NOR: A logic bit-by-bit operation with two operands that calculates the NOT of the OR of the two operands. 37

38

2.6 Instruction for making decisions i Go to statement label L1 if the value in register 1 equals the value in register 2; Go to statement label L if the value in register 1 does not equal the value in register 2; Two instructions are called conditional branches 39

40

41

Loops 42

43

44

Register $t0 is set to 1 if the value in $s3 is less than the value in $s4 $t0 =1 if the value in $2 is less than 10 45

Unconditional jump instructions j jr Unconditionally jumps to the instruction at the specified address j exit # jump to the statement t t labeled l exit Jumps to the address contained in the specified register jr $s # goto address $s 46

47

2.7 Supporting Procedures in computer hardware Procedure/function: re/f a stored subroutine that performs a specific task based on the parameters with which it is provided Jal (jump-and-link instruction) : An instruction that jumps to an address and simultaneously saves the address of the following instruction in a register ($ra in MIPS) 48

2.7 Supporting Procedures in computer hardware Caller: the program that instigates a procedure and provides necessary parameter values Callee: a procedure that executes a series of stored instructions ti based on parameters provided by the caller and then returns control to the caller 49

Stack: a data structure for spilling registers organized as a last-in-first-out queue Stack pointer: a value denoting the most recently allocated address in a stack that shows where registers should be spilled or where old register values can be found 50

Using more registers $a0-$a3: 4 registers to pass parameters $v0-$v1: $v1: 2 registers for return values $ra: 1 return address register to return to the point of origin i $pc (program counter): hold the address of current instruction $sp: stack pointer $gp (global pointer): point to static data 51

Stack Stack-like behavior is sometimes called "LIFO" for Last In First Out. The top item of the stack is 81. The bottom of the stack contains the integer -92 $sp always points to the top of the stack. 52

To push an item onto the stack, first subtract 4 from the stack pointer, then store the item at the address in the stack pointer # Push the item in $t0 Addi $sp, $sp, -4 # point to the place for the new item sw $t0, 0($sp) # store the contents of $t0 as the new top 53

To pop the top item from a stack, copy the item pointed at by the stack pointer, then add 4 to the stack pointer. # Pop the item into $t0 lw $t0, 0($sp) # copy the top item to $t0 Addi $sp, $sp, 4 # point to the new place 54

Procedure example ghij g,h,i,j $a0-$a3$a3 f $s0 55

Jal: jump-and-link Jumps to an address and simultaneously saves the address of the following instruction in register $ra Saves PC+4 in register $ra to link to the following instruction to set up the procedure return 56

Read and write byte and halfword 57

For C language, a string is terminated with a byte whose value is 0 58

Assume that base addresses for arrays x and y are found in $a0 and $a1, while i is in $s0 59

60

61

Nested procedure Leaf procedures: procedures that do not call others Nested procedure: e.g. procedure A calls procedure B 62

63

Preserved registers across a call 64

Allocating Space for New Data on the Stack Stack can be used to store local arrays or structures local to the procedure Procedure frame / activation record: the segment of the stack containing a procedure s saved registers and local variables Some MIPS software uses a frame pointer $fp to point to the first word of the frame lw $t0,8($fp) # get b lw $t1,4($fp) # get i lw $t2,0($fp) # get j addu $t3,$t0,$t1 # b + i addu $t3,$t3,$t2 # b + i + j sw $t3,12($fp) # a =b+i+j 65

Allocating Space for New Data on the Heap Space for static variables and dynamic data structure is needed The portion of memory above the data segment that has been allocated to data structures is called the heap 66

$sp is initialized to 0x7ffffffc Program code starts at 0x00400000 (PC) $gp (global pointer, access to static data )initialized to 0x10008000 $gp can access the data range: 0x1000000-0x1000ffff 67

Instruction Processing Fetch instruction ti from memory Decode instruction ti Evaluate address Fetch operands from memory Execute operation Store result 68

Instruction The instruction is the fundamental unit of work. Specifies two things: opcode: operation to be performed operands: data/locations ti to be used for operation An instruction is encoded as a sequence of bits. (Just like data!) Often, but not always, instructions have a fixed length, such as 32 or 64 bits. Control unit interprets instruction: generates sequence of control signals to carry out operation. Operation is either executed completely, or not at all. A computer s instructions and their formats is known as its Instruction ti Set Architecture t (ISA). 69

Instruction Processing: FETCH Load next instruction (at address stored in PC) from memory into Instruction Register (IR). Then increment PC, so that it points to the next instruction in sequence. PC becomes PC+1. F D EA OP EX S 70

Instruction Processing: FETCH OPERANDS Obtain source operands needed to perform operation. Examples: load data from memory read data from register file F D EA OP EX S 71

Instruction Processing: DECODE First identify the opcode. Depending on opcode, identify other operands from the remaining bits. F D EA OP EX S 72

Instruction Processing: EVALUATE ADDRESS For instructions that require memory Access, compute address used for access. F D EA OP EX S 73

Instruction Processing: EXECUTE Perform the operation, using the source operands. F D EA OP EX S 74

Instruction Processing: STORE Write results to destination. (register or memory) F D EA OP EX S 75

Instruction Processing Summary Instructions look just like data -- it s all interpretation. Three basic kinds of instructions: computational instructions (like +,-) data movement instructions (like a=b) control instructions (like if then) Six basic phases of instruction processing: F D EA OP EX S not all phases are needed by every instruction phases may take variable number of machine cycles 76

MIPS addressing modes Mode 4: Add a 16-bit address shifted left 2 bits to the PC Mode 5: Concatenate a 26-bit address shifted left 2 with the 4 upper bits of the PC 77

Addressing examples 78

Addressing examples 79

Addressing examples 80

Addressing examples 81

Addressing examples lui: set the upper 16 bits of a constant in a register, allowing a subsequent instruction to specify the lower 16 bits of the constant 82

83

CSortExample assign v and k t0 $a0 and $a1, respectively 84

assign v and n t0 $a0 and $a1, respectively assign I and j t0 $s0 and $s1, respectively 85

86

Arrays versus pointers Clear a sequence of words in memory using arrays and pointers Arrays must have the multiply and add inside the loop because i is incremented and each address must be recalculated from the new index; Pointer increments the pointer p directly. The pointer version reduces the instructions executed per iteration from 7 to 4 87

Thank you! 88