MISP Assembly.

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

Lecture 5: MIPS Instruction Set
MIPS assembly. Review  Lat lecture, we learnt  addi,  and, andi, or, ori, xor, xori, nor,  beq, j, bne  An array is stored sequentially in the memory.
Chapter 2 Instructions: Language of the Computer
Chapter 2.
Computer Structure - Computer Arithmetic Goal: Representing Numbers in Binary  Base 10 (decimal) - Numbers are represented using 10 numerals: 0, 1, 2,
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Computer Architecture CPSC 321 E. J. Kim. Overview Logical Instructions Shifts.
1 Lecture 2: MIPS Instruction Set Today’s topic:  MIPS instructions Reminder: sign up for the mailing list cs3810 Reminder: set up your CADE accounts.
Logical & shift ops (1) Fall 2007 Lecture 05: Logical Operations.
Lecture 5 Sept 14 Goals: Chapter 2 continued MIPS assembly language instruction formats translating c into MIPS - examples.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
Arithmetic for Computers
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
CSE378 Instr. encoding.1 Instruction encoding The ISA defines –The format of an instruction (syntax) –The meaning of the instruction (semantics) Format.
Registers and MAL Lecture 12. The MAL Architecture MAL is a load/store architecture. MAL supports only those addressing modes supported by the MIPS RISC.
1. 2 Instructions: Words of the language understood by CPU Instruction set: CPU’s vocabulary Instruction Set Architecture (ISA): CPU’s vocabulary together.
CSCI 136 Lab 1: 135 Review.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
MIPS Logic & Shift. Bitwise Logic Bitwise operations : logical operations applied to each bit Bitwise OR:
IFT 201: Unit 1 Lecture 1.3: Processor Architecture-3
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /08/2013 Lecture 10: MIPS Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE CENTRAL STATE.
MIPS coding. Review Shifting – Shift Left Logical (sll) – Shift Right Logical (srl) – Moves all of the bits to the left/right and fills in gap with 0’s.
Computer Organization Instructions Language of The Computer (MIPS) 2.
Computer Organization CS224 Fall 2012 Lessons 7 and 8.
EET 4250 Instruction Representation & Formats Acknowledgements: Some slides and lecture notes for this course adapted from Prof. Mary Jane Penn.
Addition, Subtraction, Logic Operations and ALU Design
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 9 Binary Representation and Logical Operations.
1 Signed Arithmetic Logical Operations Ellen Spertus MCS 111 October 1, 2002.
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
COM181 Computer Hardware Lecture 6: The MIPs CPU.
Csci136 Computer Architecture II Lab#5 Arithmetic Review ALU Design Ripple Carry Adder & Carry lookahead HW #4: Due on Feb 22, before class Feb.16, 2005.
Pirouz Bazargan SabetDecember 2003 Effective Implementation of a 32-bit RISC Processor Pirouz Bazargan Sabet University of Paris 6 - LIP6 - ASIM
MIPS Arithmetic and Logic Instructions
CS Computer Organization Numbers and Instructions Dr. Stephen P. Carl.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Yaohang Li.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
COMPUTER ARCHITECTURE & OPERATIONS I
Morgan Kaufmann Publishers
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Organization and Design Instruction Sets - 2
The University of Adelaide, School of Computer Science
Instructions for Making Decisions
Team Brian Leslie Stephen Brenner Brian Leslie Ben Whitcher
Lecture 4: MIPS Instruction Set
Computer Architecture & Operations I
ECE232: Hardware Organization and Design
The University of Adelaide, School of Computer Science
Chapter 2 Instructions: Language of the Computer
Instruction encoding The ISA defines Format = Encoding
Review.
The University of Adelaide, School of Computer Science
MIPS Assembly.
Computer Architecture
3.
Instruction encoding The ISA defines Format = Encoding
UCSD ECE 111 Prof. Farinaz Koushanfar Fall 2018
Team Stephen Brenner Brian Leslie Ben Whitcher
Instruction encoding The ISA defines Format = Encoding
Logical instructions And rd rs rt Nor rd rs rt Or rd rs rt
MIPS Assembly.
Instruction encoding The ISA defines Format = Encoding
MIPS assembly.
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
Logical Instructions And rd rs rt Nor rd rs rt Or rd rs rt
MIPS Arithmetic and Logic Instructions
MIPS Arithmetic and Logic Instructions
7/6/
MIPS instructions.
Presentation transcript:

MISP Assembly

Constant or Immediate Operands 11/21/2018 Constant or Immediate Operands Many times we use a constant in an operation For example, i++, i--, i += 4, and so on Since constant operands occur frequently, we should include constants inside arithmetic operations so that they are much faster MIPS has an add instruction that allows one operand to be a constant The constant must be in 16 bits, as a signed integer in 2’s complement format addi $s1, $s2, 100 # $s1 = $s2 + 100 11/21/2018 CDA3100 CDA3100

11/21/2018 Logical Operations Often we need to operate on bit fields within a word. Which allow us to pack and unpack bits into words and perform logical operations such as logical and, logical or, and logical negation 11/21/2018 CDA3100 CDA3100

Logical operations And: Or: Xor: 0 and 0 = 0, 0 and 1 = 0, 1 and 0 = 0, 1 and 1 = 1 Or: 0 or 0 = 0, 0 or 1 = 1, 1 or 0 = 1, 1 or 1 = 1 Xor: 0 xor 0 = 0, 0 xor 1 = 1, 1 xor 0 = 1, 1 xor 1 = 0

Bit-wise AND Apply AND bit by bit 11/21/2018 Bit-wise AND Apply AND bit by bit The resulting bit is 1 if both of the input bits are 1 and zero otherwise and $t2, $t0, $t1 There is also a version of AND with an immediate andi $t2, $t1, 12 The immediate is treated as an unsigned 16-bit number 11/21/2018 CDA3100 CDA3100

Bit-wise OR Apply OR bit by bit 11/21/2018 Bit-wise OR Apply OR bit by bit The resulting bit is 1 if at least one of the input bits is 1 and zero otherwise or $t2, $t0, $t1 There is also a version of OR with an immediate ori $t2, $t1, 12 The immediate is treated as an unsigned 16-bit number 11/21/2018 CDA3100 CDA3100

Bit-wise XOR Apply XOR bit by bit 11/21/2018 Bit-wise XOR Apply XOR bit by bit The resulting bit is 1 if two bits are different xor $t2, $t0, $t1 There is also a version of OR with an immediate xori $t2, $t1, 12 The immediate is treated as an unsigned 16-bit number 11/21/2018 CDA3100 CDA3100

11/21/2018 NOR Since NOT takes one operand and results in one operand, it is not included in MIPS as an instruction Because in MIPS each arithmetic operation takes exactly three operands Instead, NOR is included The resulting bit is 0 if at least one of the input bits is 1 nor $t2, $t0, $t1 How to implement NOT using NOR? Using $zero as one of the input operands It is included in MIPS as a pseudoinstruction 11/21/2018 CDA3100 CDA3100

Questions With these instructions, how can we load an integer value (like 100) into a register ($t0)? addi $t0, $zero, 100 ori $t0, $zero, 80

Questions How to tell if $t0 is equal to $t1? Suppose you need to set $s0 to be 0 if they are equal and any non-zero value otherwise Xor, sub, both will work

Questions How to tell if $t0 is an odd number? Suppose you need to set $t1 to be 1 if so and 0 otherwise andi $t1, $t0, 1

11/21/2018 Shifts Shift instructions move all the bits in a word to the left or to the right Shift left logical (sll) move all the bits to the left by the specified number of bits sll $t2, $t0, 2 Shift right logical (srl) move all the bits to the right srl $t2, $t0, 2 Filling the emptied bits with 0’s 11/21/2018 CDA3100 CDA3100

Example Suppose register $s0 ($16) is 9ten 11/21/2018 Example Suppose register $s0 ($16) is 9ten What do we have in $t2 ($10) after 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 11/21/2018 CDA3100 CDA3100

Example Suppose register $s0 ($16) is 9ten We have in $t2 ($10) after 11/21/2018 Example Suppose register $s0 ($16) is 9ten We have in $t2 ($10) after The value is 144ten = 9ten  24 In general, shifting left by i bits gives the same result as multiplying by 2i 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 11/21/2018 CDA3100 CDA3100

Example Suppose register $s0 ($16) is 9ten We have in $t2 ($10) after 11/21/2018 Example Suppose register $s0 ($16) is 9ten We have in $t2 ($10) after The value is NOT 9ten  228 noting that the number is a signed number. Overflow happens this time 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 11/21/2018 CDA3100 CDA3100

Questions Suppose $t0 is storing 30, $t1 is storing 20. After the following instructions, what will be the value in $t2? sub $t2, $t0, $t1 srl $t2, $t2, 2 ori $t2, $t2, 10   (a) 8 (b)10 (c)18 (d) None of the above. 30-20=10=1010. srl =10, or with 10 becomes 10. So. (b)

Questions Suppose word array A stores 0,1,2,3,4,5,6,7,8,9, in this order. Assume the starting address of A is in $s0. After the following instructions, what will be the value in $t0? addi $s0, $s0, 32 lw $t0, 4($s0) andi $t0, $t0, 1   (a) 0 (b) 8 (c) 9 (d) None of the above. (d) 1

Questions Assume A is an integer array with 10 elements storing 0,1,2,3,4,5,6,7,8,9. Assume the starting address of A is in $s0 and $t0 is holding 3. After the running the following code, what will be the content of $t0? sll $t0, $t0, 3 add $t0, $s0, $t0 lw $t0, 0($t0) srl $t0, $t0, 1   (a) 3 (b) 1 (c) 0 (d) None of the above. Answer: a.