Instructor: Dr. Mike Turi Department of Computer Science and Computer Engineering Pacific Lutheran University Lecture slides adapted from Part 4, EE 334.

Slides:



Advertisements
Similar presentations
CENG 311 Decisions in C/Assembly Language
Advertisements

Lecture 13: 10/8/2002CS170 Fall CS170 Computer Organization and Architecture I Ayman Abdel-Hamid Department of Computer Science Old Dominion University.
4.
Instruction Set-Intro
Chapter 2.
Instruction Set Architecture Classification According to the type of internal storage in a processor the basic types are Stack Accumulator General Purpose.
The University of Adelaide, School of Computer Science
CS 61C L07 MIPS Intro (1) A Carle, Summer 2006 © UCB inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Intro to MIPS
CS61C L05 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Fall 2011 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
COMP3221 lec08-arith.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 8: C/Assembler Data Processing
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
CS 61C L06 MIPS Intro (1) A Carle, Summer 2005 © UCB inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #6: Intro to MIPS
CS61C L08 Introduction to MIPS Assembly Language: Arithmetic (1) Garcia © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS61C L6 Intro MIPS ; Load & Store (1) Garcia, Fall 2005 © UCB Hate EMACS? Love EMACS? Richard M. Stallman, a famous proponent of open- source software,
Normal C Memory Management °A program’s address space contains 4 regions: stack: local variables, grows downward heap: space requested for pointers via.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 4: Arithmetic / Data Transfer Instructions Partially adapted from Computer Organization.
CIS 314: Introduction to MIPS Assembly Language: Arithmetic Fall 2005 I´ve been getting this a lot lately So, what are you teaching this term? Computer.
CS61C L08 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Spring 2008 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 3: Arithmetic Instructions Partially adapted from Computer Organization and Design, 4.
CS1104 Assembly Language: Part 1
CS 61C L08 Introduction to MIPS Assembly Language: Arithmetic (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
CS61C L06 More Memory Management, Intro to MIPS (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures.
From C to Assembly Language Jen-Chang Liu, Spring 2006 Adapted from
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
CS61C L09 Introduction to MIPS : Data Transfer and Decisions (1) Garcia, Spring 2007 © UCB Lecturer SOE Dan Garcia inst.eecs.berkeley.edu/~cs61c.
On Textbook CD: SPIM Jen-Chang Liu, Simulation of a virtual machine Virtual machine (simulator) Differences between SPIM and real MIPS? No delayed.
CS 61C L2.1.2 MM and MIPS (1) K. Meinz, Summer 2004 © UCB CS61C : Machine Structures Lecture Garbage Collection & Intro to MIPS Kurt Meinz.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Reformatting a Machine 125 Million Miles Away! Mars rover “Opportunity” got its flash drive reformatted 9/8/14, reason: rover keeps rebooting. Happy news:
Lecture 4: MIPS Instruction Set Reminders: –Homework #1 posted: due next Wed. –Midterm #1 scheduled Friday September 26 th, 2014 Location: TODD 430 –Midterm.
Chapter 2 Instructions: Language of the Computer Part I.
CWRU EECS 3221 Language of the Machine EECS 322 Computer Architecture Instructor: Francis G. Wolff Case Western Reserve University.
CS2100 Computer Organisation MIPS Part I: Introduction (AY2015/6) Semester 1.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 7, 8 Instruction Set Architecture.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
CS61C L05 Introduction to MIPS Assembly Language : Arithmetic (1) Garcia, Spring 2014 © UCB TA/Guest Lecturer: Shreyas Chand inst.eecs.berkeley.edu/~cs61c.
Assembly Language Basic job of a CPU: execute lots of instructions. Instructions are the primitive operations that the CPU may execute. Different CPUs.
Instructor: Dr. Mike Turi Department of Computer Science and Computer Engineering Pacific Lutheran University Lecture slides adapted from Part 8, EE 334.
CS2100 Computer Organisation
Computers’ Basic Organization
Computer Architecture & Operations I
Computer Architecture & Operations I
MIPS Assembly.
IT 251 Computer Organization and Architecture
Lecturer PSOE Dan Garcia
Instructor Paul Pearce
Instruction Set Architecture
Morgan Kaufmann Publishers
Lecture 4: MIPS Instruction Set
IT 251 Computer Organization and Architecture
MIPS Assembly.
Instructions - Type and Format
Lecture 4: MIPS Instruction Set
The University of Adelaide, School of Computer Science
ECE232: Hardware Organization and Design
C second, objective-c, Go up!
Topic 6: Bitwise Instructions
Hello to Jessy VanDivner listening from Ohio!
Lecturer SOE Dan Garcia
Computer Architecture
3.
COMS 361 Computer Organization
Instructions in Machine Language
COMS 361 Computer Organization
March 2006 Saeid Nooshabadi
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
Reverse Assembly Typical problem:
CPU Structure CPU must:
Presentation transcript:

Instructor: Dr. Mike Turi Department of Computer Science and Computer Engineering Pacific Lutheran University Lecture slides adapted from Part 4, EE 334 Dr. Valeriu Beiu (Washington State University) Spring 2005

 Java/C operators, operands  Variables in Assembly (registers)  Addition and Subtraction in Assembly

 Operators: +, -, *, /, % (mod);  7/4 == 1, 7%4 == 3  Operands:  Variables: fahr, celsius  Constants: 0, 1000, -17, 15.4  Assignment Statement: variable = expression  celsius = 5*(fahr-32)/9;  a = b + c + d - e;

 Assembly language is essentially directly supported in hardware, therefore...  It is kept very simple!  Limit on the type of operands  Limit on the set operations that can be done to absolute minimum ▪ If an operation can be decomposed into a simpler operation … don’t include it!

 Unlike HLL, assembly cannot use variables  Why not?  Assembly Operands are registers  Limited number of special locations built directly into the hardware  Operations can only be performed on these!  Benefit: Since registers are directly in hardware, they are very fast!

 Drawback:  Since registers are in hardware, there are a predetermined number of them  Therefore, MIPS code must be carefully put together to efficiently use registers  32 registers in MIPS  Why only 32?  Each MIPS register is 32 bits wide  Groups of 32 bits called a word in MIPS

 Registers are numbered from 0 to 31  Number references: $0, $1, $2, … $30, $31  By convention, each register also has a name to make it easier to code:  $16 - $22  $s0 - $s7 (correspond to Java/C variables)  $8 - $15  $t0 - $t7 (correspond to temporary variables)  In general, use register names (to make your code more readable)

 Another way to make your code more readable: Comments!  Hash (#) is used for MIPS comments  Anything from hash mark to end of line is a comment and will be ignored  Similar to // comment from Java/C  Note: no support for /* comment */ format

 In assembly language, each statement (called an instruction), executes exactly one of a short list of simple commands  Unlike Java/C (and most other HLLs), where each line could represent multiple operations

 Syntax of Instructions: 12, 3, 4 where: 1) operation by name 2) operand getting result (destination) 3) 1 st operand for operation (source 1) 4) 2 nd operand for operation (source 2) OperationDestination, Source 1, Source 2  Syntax is Rigid: 1 operator, 3 operands, why?

 Addition  Example: add $s0, $s1, $s2 (in MIPS) Equivalent to: a = b + c (in Java/C) where registers$s0, $s1, $s2are associated with variablesa, b, c  Subtraction  Example: sub $s3, $s4, $s5 (in MIPS) Equivalent to: d = e – f (in Java/C) where registers $s3, $s4, $s5are associated with variables d, e, f

 What is the assembly for this Java/C statement? Try it a = b + c + d - e;  Break into multiple instructions add $s0, $s1, $s2# a = b + c add $s0, $s0, $s3# a = a + d sub $s0, $s0, $s4# a = a - e  Remark 1: A single line of Java/C may break up into several lines of MIPS  Remark 2: Everything after the hash mark on each line is ignored (comments)

 How do we do this? Try it f = (g + h) - (i + j);  Use an intermediate temporary register add $s0, $s1, $s2# f = g + h add $t0, $s3, $s4# t0 = i + j # need to save i+j, but can’t use # f, so use t0 sub $s0, $s0, $t0# f=(g+h)-(i+j)

 Immediates are numerical constants  They appear often in code, so there are special instructions for them  Add Immediate: addi $s0, $s1, 10(in MIPS) f = g + 10(in Java/C) Where: $s0  fand$s1  g  Syntax similar to “add” instruction, except last argument is a number instead of a register

 One particular immediate, the number zero (0), appears very often in code  Register zero ($0 or $zero) is defined to always have the value 0  Use this register, it’s very handy! add $s1, $zero, $s0# copy $s0 to $s1  $zero is defined in hardware, so below does nothing! addi $zero, $zero, 5

 In MIPS Assembly Language  Registers replace Java/C variables  One instruction (simple operation) per line  Simpler is Better  Smaller is Faster

 New instructions:  add  addi  sub  New registers:  Java/C variables:$s0 - $s7  Temporary variables:$t0 - $t9  Zero:$zero