Statement Format MIPS assembly language statements have the following format label: opcode operand,operand,operand # comment Label identifies the statement.

Slides:



Advertisements
Similar presentations
Goal: Write Programs in Assembly
Advertisements

Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Review of the MIPS Instruction Set Architecture. RISC Instruction Set Basics All operations on data apply to data in registers and typically change the.
Comp Sci Control structures 1 Ch. 5 Control Structures.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 5: Data Transfer Instructions / Control Flow Instructions Partially adapted from Computer.
Fall EE 333 Lillevik 333f06-l4 University of Portland School of Engineering Computer Organization Lecture 4 Assembly language programming ALU and.
1 COMS 361 Computer Organization Title: Instructions Date: 9/28/2004 Lecture Number: 10.
Assembly Process. Machine Code Generation Assembling a program entails translating the assembly language into binary machine code This requires more than.
Chapter 2 Instructions: Language of the Computer Part III.
CS153 Greg Morrisett. Quick overview of the MIPS instruction set.  We're going to be compiling to MIPS assembly language.  So you need to know how to.
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
The Assembly Process Basically how does it all work.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 4: Arithmetic / Data Transfer Instructions Partially adapted from Computer Organization.
MIPS Assembler Programming
1 CS 430 Computer Architecture Clap if you like pizza! Pointless Poll.
Fall 2003SYCS-401 Operating Systems Instruction Set Architecture An overview of MIPS R3000 assembly language.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
Instruction Representation I (1) Fall 2005 Lecture 05: INSTRUCTION REPRESENTATION.
CS 300 – Lecture 6 Intro to Computer Architecture / Assembly Language Instructions.
9/29: Lecture Topics Memory –Addressing (naming) –Address space sizing Data transfer instructions –load/store on arrays on arrays with variable indices.
IT253: Computer Organization Lecture 5: Assembly Language and an Introduction to MIPS Tonga Institute of Higher Education.
Computer Organization and Design Instruction Sets Montek Singh Wed, Sep 12, 2012 Lecture 5.
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.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
True Assembly Language Part I. The Assembly Process The process of translating a MAL code (an assembly language program) into machine code (a sequence.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
CENG 311 Instruction Representation
MIPS Assembly Language Chapter 13 S. Dandamudi To be used with S. Dandamudi, “Introduction to Assembly Language Programming,” Second Edition, Springer,
Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.
The Assembly Process Basically why does it all work.
MIPS Assembly Language Chapter 15 S. Dandamudi To be used with S. Dandamudi, “Fundamentals of Computer Organization and Design,” Springer, 2003.
CDA 3101 Spring 2016 Introduction to Computer Organization
The Assembly Process Computer Organization and Assembly Language: Module 10.
Instructor: Prof. Hany H Ammar, LCSEE, WVU
Integer Multiplication, Division Arithmetic shift
System Calls & Arithmetic
CSCI206 - Computer Organization & Programming
Computer Organization and Design Instruction Sets - 2
MIPS Coding Continued.
Lecture 4: MIPS Instruction Set
Computer Organization and Design Instruction Sets - 2
Conditional Branches What distinguishes a computer from a simple calculator is its ability to make decisions Decisions are made using the if statement,
32-bit MIPS ISA.
CDA 3101 Summer 2007 Introduction to Computer Organization
Computer Organization and Design Instruction Sets
CSCI206 - Computer Organization & Programming
Systems Architecture I
MIPS Instruction Encoding
ECE232: Hardware Organization and Design
MIPS Instruction Encoding
Instruction encoding The ISA defines Format = Encoding
Review.
Instructions and Conditional Execution
Flow of Control -- Conditional branch instructions
MIPS Assembly.
Flow of Control -- Conditional branch instructions
MIPS e pipelining Tecniche di base.
MIPS Coding Continued.
MIPS assembly.
CS352H Computer Systems Architecture
Generalities for Assembly Language
MIPS Arithmetic and Logic Instructions
Pointless Poll Clap if you like pizza!.
9/27: Lecture Topics Memory Data transfer instructions
MIPS Arithmetic and Logic Instructions
7/6/
9/13/
MIPS instructions.
Control Flow and Arrays
Presentation transcript:

Statement Format MIPS assembly language statements have the following format label: opcode operand,operand,operand # comment Label identifies the statement and is optional Opcode is the command There may be 0-3 operands depending on the instruction Comments are optional but helpful Comments can be on a line by themselves

Register Conventions MIPS assembler does not IMPOSE these conventions, however it does support them. This way functions can be easily exchanged and teams can work on a single product More later

Command Formats To make sure you use the proper command, look at the operands and their data type Some commands take 3 registers as operands Some take an actual number (immediate) as one of the operands Some take a label (of a variable or statement) as one of the operands Some take a memory location specified by a base/offset pair (Macro assembler allows labels for the memory location)

Arithmetic Let’s translate: x=y+7-z; Assembler.text lw$t0,y addi $t0,$t0,7 lw$t1,z sub$t0,$t0,$t1 sw $t0,x li$v0,10 syscall.data x:.word0 y:.word0 z:.word0

Multiply Let’s look at Britton’s appendix C about the Multiply instruction It multiplies the contents of two registers (remember the result can be BIG) and stores the lower 32 bits of the result in the LOW register and the upper 32 bits in the HIGH register. How do we work with HIGH and LOW? –Move from High mfhi reg –Move from Low mflo reg

Divide When we divide, there is a quotient and a remainder (we are in the integer world) Again, looking at appendix C, Divide (div) takes 2 registers, divides the first by the second, and places the quotient in LOW and the remainder in HIGH Divide unsigned (divu) treats the values as unsigned (positive) values. There is a multiply unsigned (multu) also.

Another Expression Let’s translate the following: x=y*(x+312)/z k=x mod 5 In assembler lw$t0,x addi$t0,312 lw$t1,y mult$t1,$t0 mflo$t0 #should check for overflow in HIGH lw$t1,z div$t0,$t1 mflo$t0 sw$t0,x li$t1,5 div$t0,$t1 mfhi$t0 sw$t0,k

Basic Branching The branch instructions have the format branchopreg, label The branchops can be: –bgez - branch if greater or equal to 0 –bgtz - branch if greater than 0 –blez – branch if less or equal to 0 –bltz – branch if less than 0

Equality Branch on equality uses opreg, reg, label Ops are –beq –bne

Macro Branches The assembler will generate an equivalent set (1-2) of basic assembler instructions for each of these –beqzreg, label –bgereg,reg,label –bgtreg,reg,label –blereg,reg,label –bltreg,reg,label –bnezreg,label –blabel

Control Structures - If if (a<b) { x=a+1; y=b-a; } a=a+2; lw$t0,a lw$t1,b bge$t0,$t1,pos1 addi$t2,$t0,1 sw$t2,x sub$t2,$t1,$t0 sw$t2,y pos1: addi$t0,$t0,2

If – else if (x<0) { y=y+1; x=-x; } else { z=z+1; y=-x; } x=x/2; lw$t0,x bgez$t0,el lw$t1,y addi$t2,$t1,1 sw$t2,y sub$t0,$0,$t0 sw$t0,x blast el:lw$t3,z addi$t3,$t3,1 sw$t3,z sub$t3,$0,$t0 sw$t3,y last:sra$t0,$t0,1 sw$t0,x

While while (a<b) { a=a+1; b=b-1; } lw$t0,a lw$t1,b rep:bge$t0,$t1,out addi$t0,$t0,1 addi$t1,$t1,-1 brep out:sw$t0,a sw$t1,b

For for (i=0; i<100;i++) { sum=sum+i; even=even+2; } add $t0,$0,$0 #li $t0,0 li$t1,100 lw$t2,sum lw$t3,even loop:add$t2,$t2,$t0 addi$t3,$t3,2 addi$t0,$t0,1 blt$t0,$t1,loop sw……i, sum, even

Macro Instructions Instructions in assembler that generate more than one machine language instruction or a very different machine instruction than what is stated. –Allows for smaller and faster instruction set –Look at Britton, appendix D –Some are just one statement.