CSE A215 Assembly Language Programming for Engineers

Similar documents
CSE A215 Assembly Language Programming for Engineers

CSE A215 Assembly Language Programming for Engineers

ECE 486/586. Computer Architecture. Lecture # 7

CISC 662 Graduate Computer Architecture. Lecture 4 - ISA

Part II Instruction-Set Architecture. Jan Computer Architecture, Instruction-Set Architecture Slide 1

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

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

MIPS Assembly Programming

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

CS/COE1541: Introduction to Computer Architecture

Instruction Set Architecture part 1 (Introduction) Mehran Rezaei

Chapter 2: Instructions:

Math 230 Assembly Programming (AKA Computer Organization) Spring 2008

Math 230 Assembly Programming (AKA Computer Organization) Spring MIPS Intro

Lecture 4: MIPS Instruction Set

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

Reduced Instruction Set Computer (RISC)

ECE331: Hardware Organization and Design

Reduced Instruction Set Computer (RISC)

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

Instructions: Language of the Computer

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

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

Instruction Set Architecture. "Speaking with the computer"

Computer Architecture

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

Computer Organization and Components

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

Instructions: Language of the Computer

EC 413 Computer Organization

ECE331: Hardware Organization and Design

Chapter 2A Instructions: Language of the Computer

Chapter 4. The Processor. Computer Architecture and IC Design Lab

CS3350B Computer Architecture

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

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

CENG 3420 Computer Organization and Design. Lecture 06: MIPS Processor - I. Bei Yu

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

Chapter 3 MIPS Assembly Language. Ó1998 Morgan Kaufmann Publishers 1

CS3350B Computer Architecture MIPS Introduction

Instructions: Language of the Computer

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

Reminder: tutorials start next week!

CS222: Dr. A. Sahu. Indian Institute of Technology Guwahati

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

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

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

Computer Architecture. The Language of the Machine

Instruction Set Architecture

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

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

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

CSCE 5610: Computer Architecture

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

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

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

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

Chapter 4. The Processor

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

CSE 533: Advanced Computer Architectures Instructor: Gürhan Küçük. Instructions. Instructions cont d. Forecast. Basics. Basics

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

Lecture 10: Simple Data Path

Chapter 2. Instruction Set Architecture (ISA)

CS61C L10 MIPS Instruction Representation II, Floating Point I (6)

CENG 3420 Lecture 06: Datapath

CENG3420 Lecture 03 Review

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

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

ECE/CS 552: Introduction To Computer Architecture 1. Instructor:Mikko H. Lipasti. University of Wisconsin-Madison. Basics Registers and ALU ops

Lecture 4: Instruction Set Architecture

Instruction encoding. MIPS Instruction encoding

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

Control Instructions

Concocting an Instruction Set

Computer Architecture. Chapter 3: Arithmetic for Computers

CSEE 3827: Fundamentals of Computer Systems

Computer Organization MIPS ISA

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

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

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

Processor design - MIPS

Instruction-set Design Issues: what is the ML instruction format(s) ML instruction Opcode Dest. Operand Source Operand 1...

CS3350B Computer Architecture MIPS Instruction Representation

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

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

Computer Architecture

Outline. EEL-4713 Computer Architecture Designing a Single Cycle Datapath

Chapter 4. The Processor

COMPSCI 313 S Computer Organization. 7 MIPS Instruction Set

Course Administration

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

Chapter 4. The Processor Designing the datapath

Review (1/2) IEEE 754 Floating Point Standard: Kahan pack as much in as could get away with. CS61C - Machine Structures

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 4. The Processor

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

Chapter 4. The Processor. Instruction count Determined by ISA and compiler. We will examine two MIPS implementations

The Single Cycle Processor

CS222: MIPS Instruction Set

The MIPS Instruction Set Architecture

MIPS%Assembly% E155%

Transcription:

CSE A215 Assembly Language Programming for Engineers Lecture 7 MIPS vs. ARM (COD Chapter 2 and Exam #1 Review) October 12, 2012 Sam Siewert

Comparison of MIPS32 and ARM Instruction Formats and Addressing Sam Siewert 2

MIPS Instruction Format Three Simple Formats Register Operation Code, Rt & Rs Source Registers, Rd Destination Register, Function Variation on Opcode (Shift Amount Used to Isolate Bitfields or multiply/divide) Immediate Apply Opcode to Rs with Rt+offset Jump 26 bit address to branch to Addressing Modes Immediate, Register, Base, PCrelative, Pseudoindirect Sam Siewert 3

MIPS Register File 32 32-bit General Purpose Registers with Conventions Summarized on Ref. Card and page 121 in COD Register Fill and Spill As Needed for Execution Context Sam Siewert 4

Use MIPS Reference Card Maps ASM Mnemonic to Instruction Format, Operation Operation defined by opcode, function for R & FR format For ASM Quick Reference and Semantics - See P. 78 Examples of Assembler source and Decode of Opcode, Format with Function in R/FR Many variations of Operations for R/FR instruction format Defined by the additional function bits along with opcode Note Floating Point Has Additional FMT and FT fields as Well RISC Opcode Field Always Same MS bits [CISC often has many variations on Opcode field sizes] Basic Instructions Formats (R, I, J) and Floating Point (FR, FI) For GP Register Names, Provides Numbers and Use Watch out for Sign Extension Where 16-bit Immediate is Assumed to Expand to larger values with same sign as Msbit Does Not Provide Addressing Modes (See P. 132-133) Sam Siewert 5

MIPS Addressing Modes Immediate Dest Register, Src Register and Constant Valued Operand Used for Arithmetic with Small Values E.g. addiu, add immediate unsigned, [I format] addiu $s1, $s2, 0xFFFF Register Two Src Registers and Dest Register Most Often Used for Full-Word Arithmetic and Logical Operations E.g. addu, add unsigned, [R format] addu $s1, $s2, $s3, s.t. $s1 = $s2 + $s3 E.g. jr, jump to addr in register, [R format] jr $ra, jump to return-address Base Two Src Registers and an Offset Often Used for Array Access E.g. lw, load word, [I format] lw $s1, 8($s2), load contents of $s1 at memory address pointed to by $s2+8 E.g. sw, store word, [I format] sw $s1, 8($s2), store contents of $s1at memory address pointed to by $s2+8 PC Relative Two Src Registers and PC offset Most Often Used for Loop Conditions and If-then-else E.g. beq, branch if equal, [I format] beq $s1, $s2, 0xFF Loop test, if($s1 == $s2) go to PC+4+0xFF Sam Siewert 6

ARM Instruction Format Much More Complex Sam Siewert 7

ARM Register File ARM 30 32-bit GP Registers Banked by Processor Mode System & User normal mode FIQ fast interrupt and exception handling IRQ normal interrupt handling Sam Siewert 8

MIPS vs. ARM Assembly Similar for Load/Store and Basic Arithmetic Sam Siewert 9

MIPS Instruction Formats Arithmetic I or R format, Immediate and Register Addressing I format for smaller numbers, uses one less register (available for other uses) R format for 32-bit full size words Data Transfer (Load/Store) I format, Base Addressing Very Convenient for Loading and Storing Array Elements Common Case in C Code Logical - I or R format, Register Addressing I format for Zero Extended Immediates ori, addi with $zero often used to transfer contents from one register to another Conditional Branch I or R format, Register or PC-Relative Addressing Jump J or R format, Immediate or Register Addressing Function calls with Jump and Link Switch Jump Tables and Return from Function with Jump Register Sam Siewert 10

MIPS Arithmetic Examples MIPS ASM code: Assmue g, h, f are global data in.myvars C code: #include <stdlib.h> int g, h, f;.text.global _start _start: lw $t2,.myvars /* load address of g in $t2 */ lw $t3,.myvars+4 /* load 5679=0xDDDD in $t3 */ sw $t3, 0($t2) /* store 0xDDDD in $t2->g */ lw $t2,.myvars+8 /* load address of h in $t2 */ lw $t3,.myvars+12 /* load 4369=0x1111 in $t3 */ sw $t3, 0($t2) /* store 0x1111 in $t2->h */ lw $t3,.myvars /* load address of g in $t3 */ lw $t2, 0($t3) /* load contents of g in $t2 */ lw $t3,.myvars+8 /* load address of h in $t3 */ lw $t3, 0($t3) /* load contents of h in $t3 */ add $t2, $t2, $t3 /* $t2 = g + h */ lw $t3,.myvars+16 /* load address of f in $t3 */ sw $t2, 0($t3) /* store (g + h) in $t2 in f */ int main(void) { g=0x0000dddd; h=0x00001111; f = g + h; Assume exit(1) is called with ASM } exit(1); Sam Siewert 11

ARM Arithmetic Example (Beagle xm) ARM ASM code:.myvars:.word g /*.myvars + 0 */.word 5679 /*.myvars + 4 */.word h /*.myvars + 8 */.word 4369 /*.myvars + 12 */.word f /*.myvars + 16 */.comm g,4,4 /* storage for g, 4 bytes aligned */.comm h,4,4 /* storage for h, 4 bytes aligned */.comm f,4,4 /* storage for f, 4 bytes aligned */.text.global _start _start: ldr r2,.myvars /* load address of g into r2 */ ldr r3,.myvars+4 /* load 5679=0xDDDD into r3 */ str r3, [r2, #0] /* store 0xDDDD in r2->g */ ldr r2,.myvars+8 /* load address of h into r2 */ ldr r3,.myvars+12 /* load 4369=0x1111 into r3 */ str r3, [r2, #0] /* store 0x1111 in r2->h */ ldr r3,.myvars /* load address of g into r3 */ ldr r2, [r3, #0] /* load contents of g into r2 */ ldr r3,.myvars+8 /* load address of h into r3 */ ldr r3, [r3, #0] /* load contents of h into r3 */ add r2, r2, r3 /* r2 = g + h */ ldr r3,.myvars+16 /* load address of f into r3 */ str r2, [r3, #0] /* store (g + h) in r2 into f */ mov r0, $0 /* exit() call */ mov r7, $1 swi $0 C code: #include <stdlib.h> int g, h, f; int main(void) { g=0x0000dddd; h=0x00001111; f = g + h; exit(1); Sam Siewert 12 }

Exam # 1 - Outline Where to Focus Sam Siewert 13

Exam Format 1 or 2 Questions from COD Ch. 1 2+ Questions from Appendix C and Logic Design for ALU 2+ Questions for COD Ch. 2 2+ Questions for COD Ch. 3 8 Questions Total Some True/False (1 or 2) Some Multiple Choice (1 or 2) Some Short Answer, Pseudo-Code (C or MIPS ASM), Diagram, Logic Table (no more than 4) Full Class Period to Complete Can Use MIPS Ref Card, Copy of COD P. 78, and COD Pages 132-133, as well as Calculator/Smart-Phone for Checking Hex/Decimal Math Closed Book Sam Siewert 14

COD Chapter 1 Basic Computer Organization Processor with Internal Control/Data Paths Interface to Memory on Local Bus Separate I/O Bus Interface Application Software System Software Hardware Tools for Generating Machine Code HW / Operating_System / Application Stack and HW to SW Interface C code compile ASM asseble machine code ASM is 1:1 ASM instruction to machine instruction C code is 1:n, where one C statement becomes 1 or more ASM instructions (a block of ASM) Basic Computer Efficiency (Throughput) Measure of CPI (Clocks Per Intsruction) or IPC (Instructions Per Clock) Sam Siewert 15

Appendix C Logic Design How to Construct an ALU Arithmetic Logic Unit Control Signals Register Selection, Execution Unit Selection, Clocking (State Machine), and Overall Pipeline Synchronization Data Path Register File and Latches R-S Flip Flops D Flip Flops JK Flip Flops Combinational Logic Design Truth Tables Logic Schematics Decoders Multiplexors Layers of Logic (2 Layer PLA) DeMorgan s Laws PLAs and Product of Sums Form Clocked State Machines Input, Output, State Transitions ALU as a State Machine Sam Siewert 16

COD Chapter 2 Basic Instruction Formats (See Ref Card) I Immediate R Register J Jump FR Floating Point Register FI Floating Point Immediate MIPS Register File (Compare to ARM Register File) MIPS Use and Optimization for Function Calls (Save, Temp, Arguments, Return Values, Return Address, Stack and Frame Pointers) ARM Use and Optimization for Execution Contexts (Banking) MIPS ASM (See P. 78) Basic Blocks - Arithmetic, Load/Store, Logical If-then-else and Looping Conditional Branch Jumping Switch Statements, Function Call Return, Goto MIPS Addressing Modes (See P. 132-133) Immediate Jump Register and 16-bit Arithmetic and Logic Applied to Registers Register Primarily Used for Arithmetic and Logic from Load/Store Data Base Primarily Used for Array Access PC-Relative Primarily Used for Branching in Loops (Psuedoindirect Ingore for now) Sam Siewert 17

Chapter 3 COD Addition and Subtraction (Carry and Overflow) Multiplication (Overflow, Slow and Fast Method) Division (Hard to Speed up Either Slow or Variable Clocks for SRT Guessing Look-up Optimization) Floating Point Format and Revisit to Addition/Subtraction Sign Bit Biased Exponent (Why Biased?) Fraction (a.k.a Mantissa) Float = (-1) S x F x 2 E Addition/Subtraction: Must Be Scaled as Needed with Matching Exponents, Add the Significands, Normalize, Check for Over/Underflow, Round, Normalize Floating Point Multiplication/Division Multiplication: Add Exponents, Subtract Bias, Multiply Mantissas, Normalize Division: Subtract Exponents, Subtract Bias, Divide Mantissas, Normalize Sam Siewert 18

MIPS vs ARM Comparison of Register Files Comparison of Pipelines (5 Stage) ARM Fetch, Decode, Execute, Data Access, Write-Back MIPS Fetch, Decode, Execute, Memory Access, Write-Back Analysis of ASM Code from Either for Load/Store and Basic Arithmetic/Logic Operations ARM has No Division Operation! Why? Sam Siewert 19