EE 109 Unit 10 MIPS Instruction Set

Size: px
Start display at page:

Download "EE 109 Unit 10 MIPS Instruction Set"

Transcription

1 1 EE 109 Unit 10 MIPS Instruction Set

2 MIPS INSTRUCTION OVERVIEW 2

3 3 Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system Instruction set is the vocabulary the HW can understand and the SW is composed with 2 approaches CISC = Complex instruction set computer Large, rich vocabulary More work per instruction but slower HW RISC = Reduced instruction set computer Small, basic, but sufficient vocabulary Less work per instruction but faster HW

4 4 MIPS Processor and Bus Interface The MIPS processor can execute software instructions that will cause it to: Load (Read) and Store (Write) data to and from memory or I/O devices Perform arithmetic and logic operations (add, sub, and, etc.) Make decisions to move around in the code (loops, ifs, call a function, etc.) MIPS Processor out op. ALU ADD, SUB, AND, OR (32-bits ALU) in1 in2 PC $0-$31 (32-bits each) Addr (32-bits) Data (32-bits) Control Memory 0 instruc data

5 5 Which Instructions In this class we'll focus on assembly to do the following tasks (shown with the corresponding MIPS assembly mnemonics) Load variables (data) from memory (or I/O) [LW,LH,LB] Perform arithmetic, logical, and shift instructions in the CPU [ADD,SUB,AND,OR,SLL,SRL,SRA] Store variables (data) back to memory after computation is complete [SW, SH, SB] Compare data [SLT] "Branch" to other code (to implement if and loops) [BEQ,BNE,J] Call subroutines/functions [JAL, JR]

6 6 MIPS ISA RISC-style 32-bit internal / 32-bit external data size Registers and ALU are 32-bits wide Memory bus is logically 32-bits wide (though may be physically wider) Registers 32 General Purpose Registers (GPR s) For integer and address values A few are used for specific tasks/values Fixed size instructions All instructions encoded as a single 32-bit word Three operand instruction format (dest, src1, src2) Load/store architecture (all data operands must be in registers and thus loaded from and stored to memory explicitly)

7 7 MIPS GPR s Assembler Name Reg. Number Description $zero $0 Constant 0 value $at $1 Assembler temporary $v0-$v1 $2-$3 Procedure return values or expression evaluation $a0-$a3 $4-$7 Arguments/parameters $t0-$t7 $8-$15 Temporaries $s0-$s7 $16-$23 Saved Temporaries $t8-$t9 $24-$25 Temporaries $k0-$k1 $26-$27 Reserved for OS kernel $gp $28 Global Pointer (Global and static variables/data) $sp $29 Stack Pointer $fp $30 Frame Pointer $ra $31 Return address for current procedure Avoid using the yellow (highlighted) registers for anything other than its stated use

8 8 MIPS Programmer-Visible Registers General Purpose Registers (GPR s) Hold data operands or addresses (pointers) to data stored in memory Special Purpose Registers PC: Program Counter (32-bits) Holds the address of the next instruction to be fetched from memory & executed HI: Hi-Half Reg. (32-bits) For MUL, holds 32 MSB s of result. For DIV, holds 32-bit remainder LO: Lo-Half Reg. (32-bits) For MUL, holds 32 LSB s of result. For DIV, holds 32-bit quotient PC: GPR s $0 - $31 32-bits Recall multiplying two 32-bit numbers yields a 64-bit result HI: LO: MIPS Core Special Purpose Registers

9 9 R=Register Type: Performing Arithmetic, Logic, and Shift Operations IMPORTANT R-TYPE INSTRUCTIONS

10 10 R-Type Arithmetic/Logic Instructions C operator Assembly Notes + ADD $d, $s, $t d=destination, s = src1, t = src2 - SUB $d, $s, $t Order: $s $t. SUBU for unsigned * MUL $d, $s, $t If multiply won t overflow 32-bit result & AND $d, $s, $t OR $d, $s, $t ^ XO$ $d, $s, $t ~( ) NOR $d, $s, $t Can be used for bitwise-not (~) << SLL $d, $s, shamt SLLV $d, $s, $t >> (signed) SRA $d, $s, shamt SRAV $d, $s, $t >> (unsigned) SRL $d, $s, shamt SRLV $d, $s, $t <, >, <=, >= SLT $d, $s, $t SLTU $d, $s, $t * MULT $s, $t MULTU $s, $t / DIV $s, $t DIVU $s, $t Shifts $s left by shamt (shift amount) or $t bits Shifts $s right by shamt or $t bits replicating sign bit to maintain sign Shifts $s left by shamt or $t bits shifting in 0 s Comparison. Order: $s $t. Sets $d=1 if $s < $t, $d=0 otherwise Result in HI/LO. Use mfhi and mflo instruction to move results $[s] / $[t]. Remainder in HI, quotient in LO

11 11 R-Type Instructions To perform arithmetic or logic operations in many processors (MIPS included) a copy of the operand MUST be loaded into a register first Consider the following operations F = X + Y Z G = F Z Complete the assembly code to perform these operations Remember to load/store your operands to/from registers C Code F = X + Y Z; G = F Z; MIPS Assembly LOAD* $4, X # Get X from mem. LOAD $5, Y # Get Y from mem. LOAD $6, Z # Get Z from mem. ADD $7,$4,$5 # Tmp = X+Y SUB $7,$7,$6 # Tmp = Tmp - Z STORE $7, F # Store to F in mem OR $8,$7,$6 # Tmp2 = F Z STORE $8, G # Store to G in mem * LOAD/STORE are not actual instructions. We will learn the actual syntax soon. out op. ALU ADD, SUB, AND, OR (32-bits ALU) in1 in2 $4 $5 $6 $7 $8 MIPS Processor $0-$31 (32-bits each) PC Addr (32-bits) Data (32-bits) Control Load Load Store X (e.g. 12) Y (e.g. 7) Z (e.g. 3) F G Memory

12 12 R-Type Instructions Format 6-bits 5-bits 5-bits 5-bits 5-bits 6-bits opcode rs (src1) rt (src2) rd (dest) shamt function rs, rt, rd are 5-bit fields for register numbers shamt = shift amount and is used for shift instructions indicating # of places to shift bits opcode and func identify actual operation (e.g. ADD, SUB) Example: ADD $5, $24, $17 opcode rs rt rd shamt func Arith. Inst. $24 $17 $5 unused ADD

13 13 Logical Operations Should already be familiar with (sick of) these! Logic operations are usually performed on a pair of bits X1 X2 AND X1 X2 OR X1 X2 XOR X1 NOT AND Output is true if both inputs are true 0 AND x = 0 1 AND x = x x AND x = x OR Output is true if any input is true 0 OR x = x 1 OR x = 1 x OR x = x XOR Output is true if exactly one input is true 0 XOR x = x 1 XOR x = NOT x x XOR x = 0 NOT Output is inverse of input

14 14 Logical Operations Logic operations on numbers means performing the operation on each pair of bits Initial Conditions: $1 = 0xF0, $2 = 0x3C 1 AND $2,$1,$2 R[2] = 0x30 0xF0 AND 0x3C 0x AND OR $2,$1,$2 R[2] = 0xFC 0xF0 OR 0x3C 0xFC OR XOR $2,$1,$2 R[2] = 0xCC 0xF0 XOR 0x3C 0xCC XOR Tip: Unless you're very good w/ hex, convert to binary then perform these operations!

15 15 Logical Operations Logic operations on numbers means performing the operation on each pair of bits Initial Conditions: $1= 0xF0, $2 = 0x3C 4 NOR $2,$1,$2 R[2] = 0x03 0xF0 NOR 0x3C 0x NOR Bitwise NOT operation can be performed by NOR ing register with itself NOR $2,$1,$1 R[2] = 0x0F 0xF0 NOR 0xF0 0x0F NOR

16 16 Shift Operations Shifts data bits either left or right Bits shifted out and dropped on one side Usually (but not always) 0 s are shifted in on the other side In addition to just moving bits around, shifting is a fast way to multiply or divide a number by powers of 2 (see next slides) 2 kinds of shifts Logical shifts (used for unsigned numbers) Arithmetic shifts (used for signed numbers) Right Shift by 2 bits: Original Data Left Shift by 2 bits: Original Data 0 s shifted in 0 s shifted in Shifted by 2 bits Shifted by 2 bits

17 17 Logical Shift 0 s shifted in Only use for operations on unsigned data Right shift by n-bits = Dividing by 2 n Left shift by n-bits = Multiplying by 2 n 0 x C = +12 Logical Right Shift by 2 bits: Logical Left Shift by 3 bits: 0 s shifted in 0 s shifted in = = x x

18 18 Arithmetic Shift Use for operations on signed data Arithmetic Right Shift replicate MSB Right shift by n-bits = Dividing by 2 n Arithmetic Left Shift shifts in 0 s Left shift by n-bits = Multiplying by 2 n 0 x F F F F F F F C = -4 Arithmetic Right Shift by 2 bits: MSB replicated and shifted in x F F F F F F F F Notice if we shifted in 0 s (like a logical right shift) our result would be a positive number and the division wouldn t work Arithmetic Left Shift by 2 bits: 0 s shifted in = = x F F F F F F F 0 Notice there is no difference between an arithmetic and logical left shift. We always shift in 0 s.

19 19 Logical Shift vs. Arithmetic Shift Logical Shift Use for unsigned or nonnumeric data Will always shift in 0 s whether it be a left or right shift Arithmetic Shift Use for signed data Left shift will shift in 0 s Right shift will sign extend (replicate the sign bit) rather than shift in 0 s If negative number stays negative by shifting in 1 s If positive stays positive by shifting in 0 s 0 0 Left shift Left shift 0 Right shift Copies of MSB are shifted in Right shift

20 20 MIPS Logical Shift Instructions SRL instruction Shift Right Logical SLL instruction Shift Left Logical Format: SxL rd, rt, shamt (shamt = shift amount and is a constant; e.g. x << 7) SxLV rd, rt, rs (rs is the shift amount and is variable; e.g. x << y) Notes: shamt limited to a 5-bit value (0-31) SxLV shifts data in rt by number of places specified in rs Examples SRL $5, $12, 7 // Shifts data in reg. $12 right by 7 places SLLV $5, $12, $20 // If $20=5, shift data in $12 left by 5 places opcode rs rt rd shamt func Arith. Inst. unused $12 $5 7 SRL Arith. Inst. $20 $12 $5 unused SLLV

21 21 MIPS Arithmetic Shift Instruction SRA instruction Shift Right Arithmetic No arithmetic left shift (use SLL for arithmetic left shift) Format: SRA rd, rt, shamt SRAV rd, rt, rs Notes: shamt limited to a 5-bit value (0-31) SRAV shifts data in rt by number of places specified in rs Examples SRA $5, $12, 7 SRAV $5, $12, $20 opcode rs rt rd shamt func Arith. Inst. unused $12 $5 7 SRA Arith. Inst. $20 $12 $5 unused SRAV

22 22 Immediate Operands Most ALU instructions also have an immediate form to be used when one operand is a constant value Syntax: ADDI Rs, Rt, imm Because immediates are limited to 16-bits, they must be extended to a full 32- bits when used the by the processor Arithmetic instructions always sign-extend to a full 32-bits even for unsigned instructions (addiu) Logical instructions always zero-extend to a full 32-bits Examples: ADDI $4, $5, -1 // R[4] = R[5] + 0xFFFFFFFF ORI $10, $14, -4 // R[10] = R[14] 0x0000FFFC Arithmetic ADDI ADDIU SLTI SLTIU Logical ANDI ORI XORI Note: SUBI is unnecessary since we can use ADDI with a negative immediate value

23 23 Set If Less-Than SLT $rd, $rs, $rt Compares $rs value with $rt value and stores Boolean (1 = true, 0 = false) value into $rd C code equivalent: bool rd = (rs < rt); $rd can only be 0x or 0x after execution Assumes signed integer comparison SLTI $rd, $rs, immediate Same as above but now 2 nd source is a constant SLTU $rd, $rs, $rt Same as SLT but interprets values as unsigned Initial Conditions: $1= 0xffffffff, $2 = 0x $3 = 0x000000ff SLT $4, $1, $2 $4 = 0x SLT $4, $3, $3 $4 = 0x SLT $4, $3, $1 $4 = 0x SLTI $4, $2, 35 $4 = 0x SLTU $4, $1, $2 $4 = 0x

24 24 Loading (Reading) and Storing (Writing) Data From and To Memory DATA TRANSFER AND MEMORY ACCESS INSTRUCTIONS

25 25 Physical Memory Organization Physical view of memory as large 2-D array of bytes (8K rows by 1KB columns) per chip (and several chips) Address is broken into fields of bits that are used to identify where in the array the desired 32-bit word is Processor always accesses memory chunks the size of the data bus, selecting only the desired bytes as specified by the instruction Proc. A D 0x Physical View of Memory 0x x x Assume each unit is a word 0x0404 = Rank/Bank Row Col XX Sample Address Breakdown

26 26 MIPS Supported Data Sizes Integer 3 Sizes Defined Byte (B) 8-bits Halfword (H) 16-bits = 2 bytes Word (W) 32-bits = 4 bytes Floating Point 3 Sizes Defined Single (S) 32-bits = 4 bytes Double (D) 64-bits = 8 bytes (For a 32-bit data bus, a double would be accessed from memory in 2 reads)

27 27 MIPS Memory Organization We can logically picture memory in the units (sizes) that we actually access them Most processors are byteaddressable Every byte (8-bits) has a unique address 32-bit address bus => 4 GB address space However, 32-bit logical data bus allows us to access 4-bytes of data at a time Logical view of memory arranged in rows of 4-bytes Still with separate addresses for each byte int x,y=5;z=8; x = y+z; Proc. A D F8 13 5A Mem. 0x x x Logical Byte-Oriented View of Mem. 8E 7C AD F A 0x x x Logical Word-Oriented View Recall variables live in memory & need to be loaded into the processor to be used

28 28 Memory & Data Size Little-endian memory can be thought of as right justified Always provide the LS-Byte address of the desired data Size is explicitly defined by the instruction used Memory Access Rules Registers: Halfword or Word access must start on an address that is a multiple of that data size (i.e. half = multiple of 2, word = multiple of 4) Byte Half 31 0 Word (Assume start address = N) LB Used to load a 1- byte var. (char) LH LW Used to load a 4- byte variable (int) N+3 N+2 N+1 Byte operations only access the byte at the specified address N+3 N+2 N+1 Halfword operations access the 2-bytes starting at the specified address N+3 N+2 N+1 Memory Word operations access the 4-bytes starting at the specified address N N N

29 29 Memory Read Instructions (Signed) GPR Sign Extend If address = 0x02 Reg. = 0x Byte LB (Load Byte) Provide address of desired byte Memory A 13 F8 7C Sign Extend Half If address = 0x00 Reg. = 0xFFFFF87C LH (Load Half) Provide address of starting byte A 13 F8 7C Word If address = 0x00 Reg. = 0x5A13F87C LW (Load Word) Provide address of starting byte A 13 F8 7C

30 30 Memory Read Instructions (Unsigned) GPR Zero Extend If address = 0x01 Reg. = 0x000000F8 Byte LBU (Load Byte) Provide address of desired byte Memory A 13 F8 7C Zero Extend Half If address = 0x00 Reg. = 0x0000F87C LHU (Load Half) Provide address of starting byte A 13 F8 7C Word If address = 0x00 Reg. = 0x5A13F87C LW (Load Word) Provide address of starting byte A 13 F8 7C

31 31 Memory Write Instructions GPR Byte Reg. = 0x SB (Store Byte) Provide address of desired byte Memory A 78 F8 7C if address = 0x Half Reg. = 0x SH (Store Half) Provide address of starting byte F8 7C if address = 0x Word Reg. = 0x SW (Store Word) Provide address of starting byte if address = 0x00

32 32 MIPS Memory Alignment Limitations Bytes can start at any address Halfwords must start on an even address Words must start on an address that is a multiple of 4 Examples: A18C good (multiple of 4) FFE6 good (even) A18E invalid (non-multiple of 4) FFE5 invalid (odd) Addr Data Control Addr Data Control EA 7C EA 52 7C C1 29 4B F8 13 5A Valid Accesses C1 29 4B BD CF 49 F8 13 5A Invalid Accesses 00FFE4 00A18C 00FFE4 00A18C

33 33 Load Format (LW,LH,LB) Syntax: LW $rt, offset($rs) $rt = Destination register offset($rs) = Address of desired data Operation: $rt = Mem[ offset + $rs ] offset limited to 16-bit signed number Examples LW $2, 0x40($3) // $2 = 0x5A12C5B7 LBU $2, -1($4) // $2 = 0x000000F8 LH $2, 0xFFFC($4) // $2 = 0xFFFF97CD $2 old val. F8BE97CD 0x $ FE 0x $ C Registers 5A12C5B7 Memory 0x Address

34 34 More LOAD Examples Examples LB $2,0x45($3) // $2 = 0xFFFFFF82 LH $2,-6($4) // $2 = 0x LHU $2, -2($4) // $2 = 0x0000F8BE $2 old val. F8BE97CD 0x $ FE 0x $ C Registers 5A12C5B7 Memory 0x Address

35 35 Store Format (SW,SH,SB) SW $rt, offset($rs) $rt = Source register offset($rs) = Address to store data Operation: Mem[ offset + $rs ] = $rt offset limited to 16-bit signed number Examples SW $2, 0x40($3) SB $2, -5($4) SH $2, 0xFFFE($4) $ AB 89AB97CD 0x $ AB4982FE 0x $ C Registers AB Memory 0x Address

36 36 Loading an Immediate If immediate (constant) 16-bits or less Use ORI or ADDI instruction with $0 register Examples ADDI $2, $0, 1 // $2 = = 1 ORI $2, $0, 0xF110 // $2 = 0 0xF110 = 0xF110 If immediate more than 16-bits Immediates limited to 16-bits so we must load constant with a 2 instruction sequence using the special LUI (Load Upper Immediate) instruction To load $2 with 0x LUI ORI $2,0x1234 $2,$2,0x5678 $2 $ OR LUI ORI

37 37 I-Type Instructions I-Type (Immediate) Format 6-bits 5-bits 5-bits 16-bits opcode rs (src1) rt (src/dst) immediate rs, rt are 5-bit fields for register numbers I = Immediate is a 16-bit constant opcode identifies actual operation Example: ADDI $5, $24, 1 LW $5, -8($3) LW is explained in the next section but is an example of an instruction using the I-type format opcode rs rt ADDI $24 $ LW $3 $5 immediate

38 38 Translating To Machine Code 32-bit Fixed Size Instructions broken into 3 types (R-, I-, and J-) based on opcode R-Type Arithmetic/Logic instructions 3 register operands or shift amount I-Type Use for data transfer, branches, etc. 2 registers + 16-bit const. J-Type 26-bit jump address We'll cover this later R-Type I-Type J-Type 6-bits opcode 6-bits opcode 6-bits opcode 5-bits rs (src1) 5-bits rs (src1) 5-bits rt (src2) 5-bits rt (src/dst) 5-bits rd (dest) 26-bits Jump address 5-bits shamt 16-bits immediate 6-bits function add $5,$7,$ lw $18, -4($3) j 0x Each type uses portions of the instruction to "code" certain aspects of the instruction. But they all start with an opcode that helps determine which type will be used.

39 39 "Be the Compiler" COMPILING HIGH-LEVEL CODE

40 40 Tips for Translating to Assembly We will now translate C code to assembly A few things to remember: Data variables live in memory Data must be brought into registers before being processed You must have an address/pointer in a register to load/store data to/from memory Generally, you will need 4 steps to translate C to assembly: Setup a pointer in a register (LUI + ORI) Load data from memory to a register (LW, LH, LB) Process data (ADD, SUB, AND, OR, etc.) Store data back to memory (SW, SH, SB)

41 41 Translating HLL to Assembly HLL variables are simply locations in memory A variable name really translates to an address in C assembly operator Assembly Notes int x,y,z; x = y + z; LUI $8, 0x1000 ORI $8, $8, 0x0004 LW $9, 4($8) LW $10, 8($8) ADD $9,$9,$10 SW $9, 0($8) Assume 0x & 0x & 0x C char a[100]; a[1]--; LUI $8, 0x1000 ORI $8, $8, 0x000C LB $9, 1($8) ADDI $9,$9,-1 SB $9,1($8) Assume array a 0x C

42 42 Translating HLL to Assembly C operator Assembly Notes int dat[4],x; x = dat[0]; x += dat[1]; LUI $8, 0x1000 ORI $8, $8, 0x0010 LW $9, 0($8) LW $10, 4($8) ADD $9,$9,$10 SW $9, 16($8) Assume 0x & 0x unsigned int y; short z; y = y / 4; z = z << 3; LUI $8, 0x1000 ORI $8, $8, 0x0010 LW $9, 0($8) SRL $9, $9, 2 SW $9, 0($8) LH $9, 4($8) SLL $9, $9, 3 SH $9, 4($8) Assume 0x & 0x

43 43 Directives Pseudo-instructions ASSEMBLERS

44 44 Writing Assembly Code written at the assembly level needs some additional help for specifying certain things Global variables Where code and data should be placed in memory Easy ways to reference memory locations To help us do this assemblers provide some additional statements that we can use

45 45 Our Simulator - MARS Download at:

46 46 Assembler Syntax In MARS and most assemblers each line of the assembly program may be one of three possible options Comment Instruction / Pseudo-instruction Assembler Directive

47 47 Comments In MARS an entire line can be marked as a comment by starting it with a pound (#) character: Example: # This line will be ignored by the assembler LW $2,8($3) ADDI $2,$2,1...

48 48 Instructions In MARS each instruction is written on a separate line and has the following syntax: (Label:) Instruc. Op. Operands Comment Example: START: ADD $2,$3,$4 # R[2]=R[3] + R[4] Notes: Label is optional and is a text identifier for the address where the instruction is placed in memory. (These are normally used to identify the target of a branch or jump instruction.) In MARS, a comment can be inserted after an instruction by using a # sign A label can be on a line by itself in which case it refers to the address of the first instruction listed after it

49 49 Labels and Instructions The optional label in front of an instruction evaluates to the address where the instruction or data starts in memory and can be used in other instructions.text START: LW $4,8($10) L1: ADDI $4,$4,-1 BNE $4,$0,L1 J START Assembly Source File LW ADDI BNE J 0x = START 0x = L1 0x x40000C Note: The BNE instruc. causes the program to branch (jump) to the instruction at the specified address if the two operands are Not Equal. The J(ump) instruction causes program execution to jump to the specified label (address). Assembler finds what address each instruction starts at.text LW $4,8($10) ADDI $4,$4,-1 BNE $4,$0,0x J 0x and replaces the labels with their corresponding address

50 50 Assembler Directives Similar to pre-processor statements (#include, #define, etc.) and global variable declarations in C/C++ Text and data segments Reserving & initializing global variables and constants Compiler and linker status Direct the assembler in how to assemble the actual instructions and how to initialize memory when the program is loaded

51 51 An Example This is output from an actual MIPS gcc/g++ compiler Actual instructions are at the bottom (addiu, srl, etc.) Directives are the things starting with. Labels are names ending with : Let's learn about some of the directives x:.word 5.globl nums.section.bss.align 2.type nums, 40 nums:.space 40.text.align 2.globl _Z6calleei $LFB2:.ent _Z6calleei _Z6calleei:.frame $sp,0,$31.mask 0x ,0.fmask 0x ,0 addiu $2,$4,3 srl $3,$2,31 addu $2,$2,$3

52 52 Text and Static Data Segments.text directive indicates the following instructions should be placed in the program area of memory.data directive indicates the following data declarations will be placed in the data memory segment I/O Space Stack Dynamic Data Segment Static Data Segment Text Segment Unused 0xFFFF_FFFC 0x8000_0000 0x7FFF_FFFC 0x1000_8000 0x1000_0000 0x0040_0000 0x0000_0000

53 53 Static Data Directives Fills memory with specified data when program is loaded Format: (Label:).type_id val_0,val_1,,val_n type_id = {.byte,.half,.word,.float,.double} Each value in the comma separated list will be stored using the indicated size Example: myval:.word 1, 2, 0x0003 Each value 1, 2, 3 is stored as a word (i.e. 32-bits) Label myval evaluates to the start address of the first word (i.e. of the value 1)

54 54 More Static Data Directives Can be used to initialize ASCII strings Format: (Label:).ascii string (Label:).asciiz string.asciiz adds a null-termination character (0) at the end of the string while.ascii does not Example: myval:.asciiz Hello world\n C-strings are just character arrays terminated with a null character ('\0' ASCII = 00 decimal) Each character stored as a byte (including '\n' = Line Feed) Label myval evaluates to the start address of the first byte of the string

55 55 Reserving Memory Reserves space in memory but leaves the contents unchanged Format: (Label:).space num_bytes.data dat1:.word 0x array:.space 4 dat2:.word 0xFEDCBA98 Skipped x C FE DC BA x = dat2 0x = array x = dat1

56 56 Alignment Directive Used to skip to the next, correctly-aligned address for the given data size Format:.align 0,1,2, or 3 0 = byte-, 1 = half-, 2 = word-, 3 = double-alignment.data dat1:.byte 1, 2, 3.align 1 dat2:.half 0x4567.align 2 dat3:.word 0x89ABCDEF Note: The number after.align is not how many bytes to skip, it indicates what type of data will come next and thus the size to be aligned Skipped Skipped x C 89 AB CD EF x = dat3 0x = dat x = dat1

57 57.data example Examples.data C1:.byte 0xFE,0x05 MSG:.asciiz SC\n DAT:.half 1,2.align 2 VAR:.word 0x Skipped because a word must begin on a 4-byte boundary A FE 0x C 0x x x C1 evaluates to 0x MSG evaluates to 0x (Note: \n = Line Feed char. = 0x0A) DAT evaluates to 0x VAR evaluates to 0x C

58 58 C/C++ and Directives Directives are used to initialize or reserve space for global variables in C short int count = 7; char message[16]; int table[8] = {0,1,2,3,4,5,6,7}; void main() {... }.data count:.half 7 message:.space 16.align 2 table:.word 0,1,2,3,4,5,6,7.text.globl main main:... C/C++ style global declarations Assembly equivalent

59 59 Summary & Notes Assembler Directives: Tell the assembler how to build the program memory image Where instructions and data should be placed in memory when the program is loaded How to initialize certain global variables Recall, a compiler/assembler simply outputs a memory IMAGE of the program. It must then be loaded into memory by the OS to be executed. Key: Directives are NOT instructions! They are used by the assembler to create the memory image and then removed The MIPS processor never sees these directives!

60 60 Directives in the Software Flow High Level Language Description int n = 0xC259; void main(){ if (x > 0) x = x + y - z; a = b*x; Compiler.data MOVE.W X,D0 n:.word CMPI.W 0xC259 #0,D0.text BLE SKIP SLT ADD $4,$2,$0 Y,D0 BNE SUB SKIP Z,D0 SKIP MUL SKIP: MUL Assembler Directives are used to create the object code (executable) image Assembler PC Program Executing SLT.c/.cpp files the processor NEVER sees/executes these directives Loader / OS Assembly (.asm/.s files) Object/Machine Code (.o files) Linker BNE Executable Binary Image

61 61 Pseudo-instructions Macros translated by the assembler to instructions actually supported by the HW Simplifies writing code in assembly Example LI (Load-immediate) pseudoinstruction translated by assembler to 2 instruction sequence (LUI & ORI)... li... $2, 0x lui $2, 0x1234 ori $2, $2, 0x With pseudo-instruction After assembler

62 62 Pseudo-instructions Pseudo-instruction NOT Rd,Rs NEG Rd,Rs Actual Assembly NOR Rd,Rs,$0 SUB Rd,$0,Rs LI Rt, immed. # Load Immediate LUI Rt, {immediate[31:16], 16 b0} ORI Rt, {16 b0, immediate[15:0]} LA Rt, label # Load Address LUI Rt, {immediate[31:16], 16 b0} ORI Rt, {16 b0, immediate[15:0]} BLT Rs,Rt,Label SLT $1,Rs,Rt BNE $1,$0,Label Note: Pseudoinstructions are assembler-dependent. See MARS Help for more details.

63 63 Support for Pseudo-instructions Pseudo-instructions often expand to several instructions and there is a need for usage of a temporary register Assembler reserves register $1 In the assembler, $1 = $at (assembler temp.) You can use $1 but it will be overwritten when you use certain pseudo-instructions

64 64 Coding Exercise with MARS int x = 7, y = 5, z = 3; z = x * z + (x y++) # #DEFINE MASK 0xe0; # PORTD &= ~(MASK) # PORTD = ((x << 5) & MASK);

65 65 What are the common features of all processor instruction sets? INSTRUCTION SET ARCHITECTURE

66 66 Components of an ISA 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support SUBtract instruc. vs. NEGate + ADD instrucs. 3. Length and format of instructions How is the operation and operands represented with 1 s and 0 s 4. Registers accessible to the instructions Faster than accessing data from memory 5. Addressing Modes How instructions can specify location of data operands

67 67 Historic Progression of Data Size & Registers Processor Year Trans. Count Data Size GPRs K K /486 85/ K/1.1 8M 32 8 Pentium M 32 >8 Pentium M 32 >= 128 Core 2 Duo M 64 >= core Core i B 64 >= 128 MIPS 1999 var

68 68 General Instruction Format Issues Instructions must specify three things: Operation (OpCode) Source operands Usually 2 source operands (e.g. X+Y) Destination Location Example: ADD $8, $9, $10 ($8 = $9 + $10 where $ = Register) Binary (machine-code) representation broken into fields of bits for each part OpCode Src. 1 Src. 2 Dest. Shift Amount Function Arith. $9 $10 $8 Unused Add

69 69 Historical Instruction Formats Different instruction sets specify these differently 3 operand instruction set (MIPS, PPC, ARM) Similar to example on previous page Format: ADD DST, SRC1, SRC2 (DST = SRC1 + SRC2) 2 operand instructions (Intel / Motorola 68K) Second operand doubles as source and destination Format: ADD SRC1, S2/D (S2/D = SRC1 + S2/D) 1 operand instructions (Old Intel FP, Low-End Embedded) Implicit operand to every instruction usually known as the Accumulator (or ACC) register Format: ADD SRC1 (ACC = ACC + SRC1)

70 70 Historical Instruction Format Examples Consider the pros and cons of each format when performing the set of operations F = X + Y Z G = A + B Simple embedded computers often use single operand format Smaller data size (8-bit or 16-bit machines) means limited instruc. size Modern, high performance processors use 2- and 3-operand formats Single-Operand Two-Operand Three-Operand LOAD X MOVE F,X ADD F,X,Y ADD Y ADD F,Y SUB F,F,Z SUB Z SUB F,Z ADD G,A,B STORE F MOVE G,A LOAD A ADD G,B ADD B STORE G (+) Smaller size to encode each instruction (-) Higher instruction count to load and store ACC value Compromise of two extremes (+) More natural program style (+) Smaller instruction count (-) Larger size to encode each instruction

71 71 MIPS Instruction Format 3 Register operand format Most ALU instructions use 3 registers as their operands All operations are performed on entire 32- bits (no size distinction) Example: ADD $t0, $t1, $t2 Load/Store architecture Load (read) data values from memory into a register Perform operations on registers Store (write) data values back to memory Different load/store instructions for different operand sizes (i.e. byte, half, word) Load/Store Architecture Proc. Mem. 1.) Load operands to proc. registers Proc. Mem. 2.) Proc. Performs operation using register values Proc. Mem. 3.) Store results back to memory

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA

Mark Redekopp, All rights reserved. EE 352 Unit 3 MIPS ISA EE 352 Unit 3 MIPS ISA Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system Instruction set is the vocabulary the HW can understand and the SW is composed

More information

EE 109 Unit 8 MIPS Instruction Set

EE 109 Unit 8 MIPS Instruction Set 1 EE 109 Unit 8 MIPS Instruction Set 2 Architecting a vocabulary for the HW INSTRUCTION SET OVERVIEW 3 Instruction Set Architecture (ISA) Defines the software interface of the processor and memory system

More information

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW

EE 109 Unit 13 MIPS Instruction Set. Instruction Set Architecture (ISA) Components of an ISA INSTRUCTION SET OVERVIEW 1 2 EE 109 Unit 13 MIPS Instruction Set Architecting a vocabulary for the HW INSTRUCTION SET OVERVIEW 3 4 Instruction Set Architecture (ISA) Defines the of the processor and memory system Instruction set

More information

EE 109 Unit 10 MIPS Instruction Set. MIPS Processor and Bus Interface. Instruction Set Architecture (ISA) MIPS INSTRUCTION OVERVIEW

EE 109 Unit 10 MIPS Instruction Set. MIPS Processor and Bus Interface. Instruction Set Architecture (ISA) MIPS INSTRUCTION OVERVIEW 10.1 10.2 EE 109 Unit 10 MIPS Instruction Set MIPS INSTRUCTION OVERVIEW 10.3 10.4 Instruction Set Architecture (ISA) Defines the of the processor and memory system Instruction set is the the HW can understand

More information

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

Mark Redekopp, All rights reserved. EE 357 Unit 11 MIPS ISA EE 357 Unit 11 MIPS ISA Components of an ISA 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support SUBtract instruc. vs. NEGate + ADD instrucs. 3. Registers accessible

More information

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

MIPS ISA. 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support Components of an ISA EE 357 Unit 11 MIPS ISA 1. Data and Address Size 8-, 16-, 32-, 64-bit 2. Which instructions does the processor support SUBtract instruc. vs. NEGate + ADD instrucs. 3. Registers accessible

More information

EE 109 Unit 10 Assembler Directives and Control Flow

EE 109 Unit 10 Assembler Directives and Control Flow 1 EE 109 Unit 10 Assembler Directives and Control Flow 2 Directives Pseudo-instructions ASSEMBLERS 3 Writing Assembly Code written at the assembly level needs some additional help for specifying certain

More information

Mark Redekopp, All rights reserved. EE 352 Unit 4. Assembly and the MARS Simulator Control Flow (Branch Instructions)

Mark Redekopp, All rights reserved. EE 352 Unit 4. Assembly and the MARS Simulator Control Flow (Branch Instructions) EE 352 Unit 4 Assembly and the MARS Simulator Control Flow (Branch Instructions) Directives Pseudo-instructions ASSEMBLERS Assembler Syntax In MARS and most assemblers each line of the assembly program

More information

The MIPS Instruction Set Architecture

The MIPS Instruction Set Architecture The MIPS Set Architecture CPS 14 Lecture 5 Today s Lecture Admin HW #1 is due HW #2 assigned Outline Review A specific ISA, we ll use it throughout semester, very similar to the NiosII ISA (we will use

More information

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

EEM 486: Computer Architecture. Lecture 2. MIPS Instruction Set Architecture EEM 486: Computer Architecture Lecture 2 MIPS Instruction Set Architecture EEM 486 Overview Instruction Representation Big idea: stored program consequences of stored program Instructions as numbers Instruction

More information

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the machine. Reduced number of cycles needed per instruction.

More information

Reduced Instruction Set Computer (RISC)

Reduced Instruction Set Computer (RISC) Reduced Instruction Set Computer (RISC) Focuses on reducing the number and complexity of instructions of the ISA. RISC Goals RISC: Simplify ISA Simplify CPU Design Better CPU Performance Motivated by simplifying

More information

CPS311 - COMPUTER ORGANIZATION. A bit of history

CPS311 - COMPUTER ORGANIZATION. A bit of history CPS311 - COMPUTER ORGANIZATION A Brief Introduction to the MIPS Architecture A bit of history The MIPS architecture grows out of an early 1980's research project at Stanford University. In 1984, MIPS computer

More information

MIPS Reference Guide

MIPS Reference Guide MIPS Reference Guide Free at PushingButtons.net 2 Table of Contents I. Data Registers 3 II. Instruction Register Formats 4 III. MIPS Instruction Set 5 IV. MIPS Instruction Set (Extended) 6 V. SPIM Programming

More information

Computer Architecture. The Language of the Machine

Computer Architecture. The Language of the Machine Computer Architecture The Language of the Machine Instruction Sets Basic ISA Classes, Addressing, Format Administrative Matters Operations, Branching, Calling conventions Break Organization All computers

More information

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

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA MIPS ISA. In a CPU. (vonneumann) Processor Organization CISC 662 Graduate Computer Architecture Lecture 4 - ISA MIPS ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,

More information

Computer Architecture. MIPS Instruction Set Architecture

Computer Architecture. MIPS Instruction Set Architecture Computer Architecture MIPS Instruction Set Architecture Instruction Set Architecture An Abstract Data Type Objects Registers & Memory Operations Instructions Goal of Instruction Set Architecture Design

More information

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

Overview. Introduction to the MIPS ISA. MIPS ISA Overview. Overview (2) Introduction to the MIPS ISA Overview Remember that the machine only understands very basic instructions (machine instructions) It is the compiler s job to translate your high-level (e.g. C program) into

More information

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA CISC 662 Graduate Computer Architecture Lecture 4 - ISA Michela Taufer http://www.cis.udel.edu/~taufer/courses Powerpoint Lecture Notes from John Hennessy and David Patterson s: Computer Architecture,

More information

MIPS Assembly Language. Today s Lecture

MIPS Assembly Language. Today s Lecture MIPS Assembly Language Computer Science 104 Lecture 6 Homework #2 Midterm I Feb 22 (in class closed book) Outline Assembly Programming Reading Chapter 2, Appendix B Today s Lecture 2 Review: A Program

More information

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

101 Assembly. ENGR 3410 Computer Architecture Mark L. Chang Fall 2009 101 Assembly ENGR 3410 Computer Architecture Mark L. Chang Fall 2009 What is assembly? 79 Why are we learning assembly now? 80 Assembly Language Readings: Chapter 2 (2.1-2.6, 2.8, 2.9, 2.13, 2.15), Appendix

More information

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

ECE232: Hardware Organization and Design. Computer Organization - Previously covered ECE232: Hardware Organization and Design Part 6: MIPS Instructions II http://www.ecs.umass.edu/ece/ece232/ Adapted from Computer Organization and Design, Patterson & Hennessy, UCB Computer Organization

More information

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

Today s Lecture. MIPS Assembly Language. Review: What Must be Specified? Review: A Program. Review: MIPS Instruction Formats Today s Lecture Homework #2 Midterm I Feb 22 (in class closed book) MIPS Assembly Language Computer Science 14 Lecture 6 Outline Assembly Programming Reading Chapter 2, Appendix B 2 Review: A Program Review:

More information

MIPS Instruction Set

MIPS Instruction Set MIPS Instruction Set Prof. James L. Frankel Harvard University Version of 7:12 PM 3-Apr-2018 Copyright 2018, 2017, 2016, 201 James L. Frankel. All rights reserved. CPU Overview CPU is an acronym for Central

More information

MIPS Instruction Format

MIPS Instruction Format MIPS Instruction Format MIPS uses a 32-bit fixed-length instruction format. only three different instruction word formats: There are Register format Op-code Rs Rt Rd Function code 000000 sssss ttttt ddddd

More information

Computer Architecture

Computer Architecture CS3350B Computer Architecture Winter 2015 Lecture 4.2: MIPS ISA -- Instruction Representation Marc Moreno Maza www.csd.uwo.ca/courses/cs3350b [Adapted from lectures on Computer Organization and Design,

More information

Instructions: Language of the Computer

Instructions: Language of the Computer Instructions: Language of the Computer Tuesday 22 September 15 Many slides adapted from: and Design, Patterson & Hennessy 5th Edition, 2014, MK and from Prof. Mary Jane Irwin, PSU Summary Previous Class

More information

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

Lecture 2. Instructions: Language of the Computer (Chapter 2 of the textbook) Lecture 2 Instructions: Language of the Computer (Chapter 2 of the textbook) Instructions: tell computers what to do Chapter 2 Instructions: Language of the Computer 2 Introduction Chapter 2.1 Chapter

More information

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

Introduction to the MIPS. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Introduction to the MIPS Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University Introduction to the MIPS The Microprocessor without Interlocked Pipeline Stages

More information

Chapter 2A Instructions: Language of the Computer

Chapter 2A Instructions: Language of the Computer Chapter 2A Instructions: Language of the Computer Copyright 2009 Elsevier, Inc. All rights reserved. Instruction Set The repertoire of instructions of a computer Different computers have different instruction

More information

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

5/17/2012. Recap from Last Time. CSE 2021: Computer Organization. The RISC Philosophy. Levels of Programming. Stored Program Computers CSE 2021: Computer Organization Recap from Last Time load from disk High-Level Program Lecture-2 Code Translation-1 Registers, Arithmetic, logical, jump, and branch instructions MIPS to machine language

More information

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

Recap from Last Time. CSE 2021: Computer Organization. Levels of Programming. The RISC Philosophy 5/19/2011 CSE 2021: Computer Organization Recap from Last Time load from disk High-Level Program Lecture-3 Code Translation-1 Registers, Arithmetic, logical, jump, and branch instructions MIPS to machine language

More information

ECE260: Fundamentals of Computer Engineering

ECE260: Fundamentals of Computer Engineering MIPS Instruction Set James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy MIPS Registers MIPS

More information

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

Chapter 2. Instructions: Language of the Computer. HW#1: 1.3 all, 1.4 all, 1.6.1, , , , , and Due date: one week. Chapter 2 Instructions: Language of the Computer HW#1: 1.3 all, 1.4 all, 1.6.1, 1.14.4, 1.14.5, 1.14.6, 1.15.1, and 1.15.4 Due date: one week. Practice: 1.5 all, 1.6 all, 1.10 all, 1.11 all, 1.14 all,

More information

M2 Instruction Set Architecture

M2 Instruction Set Architecture M2 Instruction Set Architecture Module Outline Addressing modes. Instruction classes. MIPS-I ISA. High level languages, Assembly languages and object code. Translating and starting a program. Subroutine

More information

CS3350B Computer Architecture MIPS Instruction Representation

CS3350B Computer Architecture MIPS Instruction Representation CS3350B Computer Architecture MIPS Instruction Representation Marc Moreno Maza http://www.csd.uwo.ca/~moreno/cs3350_moreno/index.html Department of Computer Science University of Western Ontario, Canada

More information

Instructions: Language of the Computer

Instructions: Language of the Computer CS359: Computer Architecture Instructions: Language of the Computer Yanyan Shen Department of Computer Science and Engineering 1 The Language a Computer Understands Word a computer understands: instruction

More information

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

MACHINE LANGUAGE. To work with the machine, we need a translator. LECTURE 2 Assembly MACHINE LANGUAGE As humans, communicating with a machine is a tedious task. We can t, for example, just say add this number and that number and store the result here. Computers have

More information

Assembly Programming

Assembly Programming Designing Computer Systems Assembly Programming 08:34:48 PM 23 August 2016 AP-1 Scott & Linda Wills Designing Computer Systems Assembly Programming In the early days of computers, assembly programming

More information

MIPS Instruction Reference

MIPS Instruction Reference Page 1 of 9 MIPS Instruction Reference This is a description of the MIPS instruction set, their meanings, syntax, semantics, and bit encodings. The syntax given for each instruction refers to the assembly

More information

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

Chapter 2. Instructions: Language of the Computer. Adapted by Paulo Lopes Chapter 2 Instructions: Language of the Computer Adapted by Paulo Lopes Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects

More information

Concocting an Instruction Set

Concocting an Instruction Set Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Read: Chapter 2.1-2.7 L03 Instruction Set 1 A General-Purpose Computer The von

More information

ECE260: Fundamentals of Computer Engineering

ECE260: Fundamentals of Computer Engineering MIPS Instruction Set James Moscola Dept. of Engineering & Computer Science York College of Pennsylvania Based on Computer Organization and Design, 5th Edition by Patterson & Hennessy MIPS Registers MIPS

More information

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

Instruction Set Architecture of. MIPS Processor. MIPS Processor. MIPS Registers (continued) MIPS Registers CSE 675.02: Introduction to Computer Architecture MIPS Processor Memory Instruction Set Architecture of MIPS Processor CPU Arithmetic Logic unit Registers $0 $31 Multiply divide Coprocessor 1 (FPU) Registers

More information

TSK3000A - Generic Instructions

TSK3000A - Generic Instructions TSK3000A - Generic Instructions Frozen Content Modified by Admin on Sep 13, 2017 Using the core set of assembly language instructions for the TSK3000A as building blocks, a number of generic instructions

More information

MIPS%Assembly% E155%

MIPS%Assembly% E155% MIPS%Assembly% E155% Outline MIPS Architecture ISA Instruction types Machine codes Procedure call Stack 2 The MIPS Register Set Name Register Number Usage $0 0 the constant value 0 $at 1 assembler temporary

More information

Examples of branch instructions

Examples of branch instructions Examples of branch instructions Beq rs,rt,target #go to target if rs = rt Beqz rs, target #go to target if rs = 0 Bne rs,rt,target #go to target if rs!= rt Bltz rs, target #go to target if rs < 0 etc.

More information

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei Instruction Set Architecture part 1 (Introduction) Mehran Rezaei Overview Last Lecture s Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a

More information

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

A Processor. Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University. See: P&H Chapter , 4.1-3 A Processor Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University See: P&H Chapter 2.16-20, 4.1-3 Let s build a MIPS CPU but using Harvard architecture Basic Computer System Registers ALU

More information

Computer Organization MIPS ISA

Computer Organization MIPS ISA CPE 335 Computer Organization MIPS ISA Dr. Iyad Jafar Adapted from Dr. Gheith Abandah Slides http://www.abandah.com/gheith/courses/cpe335_s08/index.html CPE 232 MIPS ISA 1 (vonneumann) Processor Organization

More information

Flow of Control -- Conditional branch instructions

Flow of Control -- Conditional branch instructions Flow of Control -- Conditional branch instructions You can compare directly Equality or inequality of two registers One register with 0 (>,

More information

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4

Processor. Han Wang CS3410, Spring 2012 Computer Science Cornell University. See P&H Chapter , 4.1 4 Processor Han Wang CS3410, Spring 2012 Computer Science Cornell University See P&H Chapter 2.16 20, 4.1 4 Announcements Project 1 Available Design Document due in one week. Final Design due in three weeks.

More information

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

Instructions: MIPS ISA. Chapter 2 Instructions: Language of the Computer 1 Instructions: MIPS ISA Chapter 2 Instructions: Language of the Computer 1 PH Chapter 2 Pt A Instructions: MIPS ISA Based on Text: Patterson Henessey Publisher: Morgan Kaufmann Edited by Y.K. Malaiya for

More information

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

Computer Organization and Structure. Bing-Yu Chen National Taiwan University Computer Organization and Structure Bing-Yu Chen National Taiwan University Instructions: Language of the Computer Operations and Operands of the Computer Hardware Signed and Unsigned Numbers Representing

More information

F. Appendix 6 MIPS Instruction Reference

F. Appendix 6 MIPS Instruction Reference F. Appendix 6 MIPS Instruction Reference Note: ALL immediate values should be sign extended. Exception: For logical operations immediate values should be zero extended. After extensions, you treat them

More information

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

MIPS R-format Instructions. Representing Instructions. Hexadecimal. R-format Example. MIPS I-format Example. MIPS I-format Instructions Representing Instructions Instructions are encoded in binary Called machine code MIPS instructions Encoded as 32-bit instruction words Small number of formats encoding operation code (opcode), register

More information

Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , , Appendix B

Anne Bracy CS 3410 Computer Science Cornell University. See P&H Chapter: , , Appendix B Anne Bracy CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, and Sirer. See P&H Chapter: 2.16-2.20, 4.1-4.4,

More information

INSTRUCTION SET COMPARISONS

INSTRUCTION SET COMPARISONS INSTRUCTION SET COMPARISONS MIPS SPARC MOTOROLA REGISTERS: INTEGER 32 FIXED WINDOWS 32 FIXED FP SEPARATE SEPARATE SHARED BRANCHES: CONDITION CODES NO YES NO COMPARE & BR. YES NO YES A=B COMP. & BR. YES

More information

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction

A General-Purpose Computer The von Neumann Model. Concocting an Instruction Set. Meaning of an Instruction. Anatomy of an Instruction page 1 Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... A General-Purpose Computer The von Neumann Model Many architectural approaches

More information

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich. Sep 2006

Assembly Language. Prof. Dr. Antônio Augusto Fröhlich.   Sep 2006 Sep 2006 Prof. Antônio Augusto Fröhlich (http://www.lisha.ufsc.br) 33 Assembly Language Prof. Dr. Antônio Augusto Fröhlich guto@lisha.ufsc.br http://www.lisha.ufsc.br/~guto Sep 2006 Sep 2006 Prof. Antônio

More information

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

ECE 2035 Programming HW/SW Systems Fall problems, 7 pages Exam Two 23 October 2013 Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate

More information

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

Today s topics. MIPS operations and operands. MIPS arithmetic. CS/COE1541: Introduction to Computer Architecture. A Review of MIPS ISA. Today s topics CS/COE1541: Introduction to Computer Architecture MIPS operations and operands MIPS registers Memory view Instruction encoding A Review of MIPS ISA Sangyeun Cho Arithmetic operations Logic

More information

ECE 15B Computer Organization Spring 2010

ECE 15B Computer Organization Spring 2010 ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 7: Procedures I Partially adapted from Computer Organization and Design, 4 th edition, Patterson and Hennessy, and classes taught by and

More information

CS 61c: Great Ideas in Computer Architecture

CS 61c: Great Ideas in Computer Architecture MIPS Functions July 1, 2014 Review I RISC Design Principles Smaller is faster: 32 registers, fewer instructions Keep it simple: rigid syntax, fixed instruction length MIPS Registers: $s0-$s7,$t0-$t9, $0

More information

CENG3420 Lecture 03 Review

CENG3420 Lecture 03 Review CENG3420 Lecture 03 Review Bei Yu byu@cse.cuhk.edu.hk 2017 Spring 1 / 38 CISC vs. RISC Complex Instruction Set Computer (CISC) Lots of instructions of variable size, very memory optimal, typically less

More information

Arithmetic for Computers

Arithmetic for Computers MIPS Arithmetic Instructions Cptr280 Dr Curtis Nelson Arithmetic for Computers Operations on integers Addition and subtraction; Multiplication and division; Dealing with overflow; Signed vs. unsigned numbers.

More information

Review: MIPS Organization

Review: MIPS Organization 1 MIPS Arithmetic Review: MIPS Organization Processor Memory src1 addr 5 src2 addr 5 dst addr 5 write data Register File registers ($zero - $ra) bits src1 data src2 data read/write addr 1 1100 2 30 words

More information

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

Computer Organization and Structure. Bing-Yu Chen National Taiwan University Computer Organization and Structure Bing-Yu Chen National Taiwan University Instructions: Language of the Computer Operations and Operands of the Computer Hardware Signed and Unsigned Numbers Representing

More information

Concocting an Instruction Set

Concocting an Instruction Set Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Read: Chapter 2.1-2.6 L04 Instruction Set 1 A General-Purpose Computer The von

More information

Course Administration

Course Administration Fall 2017 EE 3613: Computer Organization Chapter 2: Instruction Set Architecture 2/4 Avinash Kodi Department of Electrical Engineering & Computer Science Ohio University, Athens, Ohio 45701 E-mail: kodi@ohio.edu

More information

ISA and RISCV. CASS 2018 Lavanya Ramapantulu

ISA and RISCV. CASS 2018 Lavanya Ramapantulu ISA and RISCV CASS 2018 Lavanya Ramapantulu Program Program =?? Algorithm + Data Structures Niklaus Wirth Program (Abstraction) of processor/hardware that executes 3-Jul-18 CASS18 - ISA and RISCV 2 Program

More information

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei

Computer Architecture Instruction Set Architecture part 2. Mehran Rezaei Computer Architecture Instruction Set Architecture part 2 Mehran Rezaei Review Execution Cycle Levels of Computer Languages Stored Program Computer/Instruction Execution Cycle SPIM, a MIPS Interpreter

More information

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

ECE Exam I February 19 th, :00 pm 4:25pm ECE 3056 Exam I February 19 th, 2015 3:00 pm 4:25pm 1. The exam is closed, notes, closed text, and no calculators. 2. The Georgia Tech Honor Code governs this examination. 3. There are 4 questions and

More information

SPIM Instruction Set

SPIM Instruction Set SPIM Instruction Set This document gives an overview of the more common instructions used in the SPIM simulator. Overview The SPIM simulator implements the full MIPS instruction set, as well as a large

More information

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

Anne Bracy CS 3410 Computer Science Cornell University. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon] Anne Bracy CS 3410 Computer Science Cornell University [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon] Understanding the basics of a processor We now have the technology to build a CPU! Putting it all

More information

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

Review. Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I Logical Operators (1/3) Bitwise Operations CS6C L9 MIPS Logical & Shift Ops, and Instruction Representation I () inst.eecs.berkeley.edu/~cs6c CS6C : Machine Structures Lecture #9 MIPS Logical & Shift Ops, and Instruction Representation I 25-9-28

More information

COMPUTER ORGANIZATION AND DESIGN

COMPUTER ORGANIZATION AND DESIGN COMPUTER ORGANIZATION AND DESIGN 5 th The Hardware/Software Interface Edition Chapter 2 Instructions: Language of the Computer 2.1 Introduction Instruction Set The repertoire of instructions of a computer

More information

MIPS Instruction Set Architecture (2)

MIPS Instruction Set Architecture (2) MIPS Instruction Set Architecture (2) Jinkyu Jeong (jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu

More information

MIPS Assembly Language

MIPS Assembly Language MIPS Assembly Language Chapter 15 S. Dandamudi Outline MIPS architecture Registers Addressing modes MIPS instruction set Instruction format Data transfer instructions Arithmetic instructions Logical/shift/rotate/compare

More information

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set COMPSCI 313 S2 2018 Computer Organization 7 MIPS Instruction Set Agenda & Reading MIPS instruction set MIPS I-format instructions MIPS R-format instructions 2 7.1 MIPS Instruction Set MIPS Instruction

More information

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 Math 230 Assembly Programming (AKA Computer Organization) Spring 2008 MIPS Intro II Lect 10 Feb 15, 2008 Adapted from slides developed for: Mary J. Irwin PSU CSE331 Dave Patterson s UCB CS152 M230 L10.1

More information

ECE 154A Introduction to. Fall 2012

ECE 154A Introduction to. Fall 2012 ECE 154A Introduction to Computer Architecture Fall 2012 Dmitri Strukov Lecture 4: Arithmetic and Data Transfer Instructions Agenda Review of last lecture Logic and shift instructions Load/store instructionsi

More information

Number Systems and Their Representations

Number Systems and Their Representations Number Representations Cptr280 Dr Curtis Nelson Number Systems and Their Representations In this presentation you will learn about: Representation of numbers in computers; Signed vs. unsigned numbers;

More information

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

We will study the MIPS assembly language as an exemplar of the concept. MIPS Assembly Language 1 We will study the MIPS assembly language as an exemplar of the concept. MIPS assembly instructions each consist of a single token specifying the command to be carried out, and

More information

Unsigned Binary Integers

Unsigned Binary Integers Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0

More information

Unsigned Binary Integers

Unsigned Binary Integers Unsigned Binary Integers Given an n-bit number x x n 1 n 2 1 0 n 12 xn 22 x12 x02 Range: 0 to +2 n 1 Example 2.4 Signed and Unsigned Numbers 0000 0000 0000 0000 0000 0000 0000 1011 2 = 0 + + 1 2 3 + 0

More information

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

ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design ENGN1640: Design of Computing Systems Topic 03: Instruction Set Architecture Design Professor Sherief Reda http://scale.engin.brown.edu School of Engineering Brown University Spring 2014 Sources: Computer

More information

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

ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE. Midterm Exam. First Semester (141) Time: 1:00-3:30 PM. Student Name : _KEY Page 1 of 14 Nov. 22, 2014 ICS DEPARTMENT ICS 233 COMPUTER ARCHITECTURE & ASSEMBLY LANGUAGE Midterm Exam First Semester (141) Time: 1:00-3:30 PM Student Name : _KEY Student ID. : Question Max Points Score

More information

Concocting an Instruction Set

Concocting an Instruction Set Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Lab is posted. Do your prelab! Stay tuned for the first problem set. L04 Instruction

More information

CSCI 402: Computer Architectures

CSCI 402: Computer Architectures CSCI 402: Computer Architectures Instructions: Language of the Computer (2) Fengguang Song Department of Computer & Information Science IUPUI Memory Operands Two tribes: Big Endian: Most-significant byte

More information

Chapter 2. Instructions: Language of the Computer

Chapter 2. Instructions: Language of the Computer Chapter 2 Instructions: Language of the Computer Instruction Set The repertoire of instructions of a computer Different computers have different instruction sets But with many aspects in common Early computers

More information

EE108B Lecture 3. MIPS Assembly Language II

EE108B Lecture 3. MIPS Assembly Language II EE108B Lecture 3 MIPS Assembly Language II Christos Kozyrakis Stanford University http://eeclass.stanford.edu/ee108b 1 Announcements Urgent: sign up at EEclass and say if you are taking 3 or 4 units Homework

More information

ece4750-parc-isa.txt

ece4750-parc-isa.txt ========================================================================== PARC Instruction Set Architecture ========================================================================== # Author : Christopher

More information

CMPE324 Computer Architecture Lecture 2

CMPE324 Computer Architecture Lecture 2 CMPE324 Computer Architecture Lecture 2.1 What is Computer Architecture? Software Hardware Application (Netscape) Operating System Compiler (Unix; Assembler Windows 9x) Processor Memory Datapath & Control

More information

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

Procedure Calling. Procedure Calling. Register Usage. 25 September CSE2021 Computer Organization CSE2021 Computer Organization Chapter 2: Part 2 Procedure Calling Procedure (function) performs a specific task and return results to caller. Supporting Procedures Procedure Calling Calling program place

More information

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

CSCI 402: Computer Architectures. Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI. CSCI 402: Computer Architectures Instructions: Language of the Computer (3) Fengguang Song Department of Computer & Information Science IUPUI Recall Big endian, little endian Memory alignment Unsigned

More information

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions Outline EEL-4713 Computer Architecture Multipliers and shifters Multiplication and shift registers Chapter 3, section 3.4 Next lecture Division, floating-point 3.5 3.6 EEL-4713 Ann Gordon-Ross.1 EEL-4713

More information

Concocting an Instruction Set

Concocting an Instruction Set Concocting an Instruction Set Nerd Chef at work. move flour,bowl add milk,bowl add egg,bowl move bowl,mixer rotate mixer... Read: Chapter 2.1-2.7 L04 Instruction Set 1 A General-Purpose Computer The von

More information

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

Assembly Language Programming. CPSC 252 Computer Organization Ellen Walker, Hiram College Assembly Language Programming CPSC 252 Computer Organization Ellen Walker, Hiram College Instruction Set Design Complex and powerful enough to enable any computation Simplicity of equipment MIPS Microprocessor

More information

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

Forecast. Instructions (354 Review) Basics. Basics. Instruction set architecture (ISA) is its vocabulary. Instructions are the words of a computer Instructions (354 Review) Forecast Instructions are the words of a computer Instruction set architecture (ISA) is its vocabulary With a few other things, this defines the interface of computers But implementations

More information