Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.

Slides:



Advertisements
Similar presentations
4.
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.
Branches Two branch instructions:
Machine Instructions Operations 1 ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson Slides4-1.ppt Modification date: March 18, 2015.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /15/2013 Lecture 11: MIPS-Conditional Instructions Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER.
Comp Sci Floating Point Arithmetic 1 Ch. 10 Floating Point Unit.
Computer Organization CS224 Fall 2012 Lesson 19. Floating-Point Example  What number is represented by the single-precision float …00 
05/03/2009CA&O Lecture 8,9,10 By Engr. Umbreen sabir1 Computer Arithmetic Computer Engineering Department.
Arithmetic in Computers Chapter 4 Arithmetic in Computers2 Outline Data representation integers Unsigned integers Signed integers Floating-points.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Assembly Language Working with the CPU.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Feb 18, 2009 Lecture 4-2 instruction set architecture (Part II of [Parhami]) MIPS encoding of instructions Spim simulator more examples of MIPS programming.
Fall 2003SYCS-401 Operating Systems Instruction Set Architecture An overview of MIPS R3000 assembly language.
MIPS Instruction Set Advantages
Computer Organization - Syscalls David Monismith Jan. 28, 2015 Based on notes from Patterson and Hennessy Text and from Dr. Bill Siever.
Ellen Spertus MCS 111 October 11, 2001 Floating Point Arithmetic.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 5 Unsigned integer and floating point.
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.
MIPS I/O and Interrupt. .data val1:.float 0.6 val2:.float 0.8 msg_done:.asciiz "done\n".text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt.
In Class Execise. .data A:.word 0,1,2,3,4,5,6,7,8,9.text.globl main main: la $a0,A li $a1,6 li $a2,5 jal onUpStream done: li $v0, 10# exit syscall onUpStream:
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Computer Organization – Memory Access David Monismith Jan. 30, 2015 Based upon notes by Dr. Bill Siever and the Patterson and Hennessy Text.
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 CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
MIPS I/O and Interrupt.
Chapter 2 Decision-Making Instructions (Instructions: Language of the Computer Part V)
MIPS mul div, and MIPS floating point instructions.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
MIPS coding. slt, slti slt $t3, $t1, $t2 – set $t3 to be 1 if $t1 < $t2 ; else clear $t3 to be 0. – “Set Less Than.” slti $t3, $t1, 100 – set $t3 to be.
Pseudo instructions. MIPS supports pseudo instructions. We have seen some like – li $t0, 4 which set $t0 to 4. – la $t0, A which puts the address of label.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
DR. SIMING LIU SPRING 2016 COMPUTER SCIENCE AND ENGINEERING UNIVERSITY OF NEVADA, RENO Session 11 Conditional Operations.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patterson and Hennessy Text.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
Intro Assembly Computer Organization I 1 June 2010 © McQuain, Feng & Ribbens MIPS Hello World # Program: Hello, World!.data # data declaration.
CS 312 Computer Architecture & Organization
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
MIPS Instruction Set Advantages
MIPS floating point instructions
Lecture 4: MIPS Instruction Set
Decision Making.
Pseudo instructions.
Lecture 10: Floating Point, Digital Design
The University of Adelaide, School of Computer Science
Floating Point ICS 233 Computer Architecture & Assembly Language
MIPS I/O and Interrupt.
SPIM Syscalls.
Lecture 4: MIPS Instruction Set
MIPS coding.
Pseudo instructions.
MIPS coding.
Review.
MIPS Coding.
The University of Adelaide, School of Computer Science
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
MIPS function continued
COMS 361 Computer Organization
MIPS I/O and Interrupt.
Floating Point Faculty of Information Technology University of Petra
9/27: Lecture Topics Memory Data transfer instructions
CS 286 Computer Architecture & Organization
Conditional Branching (beq)
Presentation transcript:

Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text

Program Review Review of floating point mathematics for the next project using FPMath.asm

Review Contd. Double values to be stored in memory are declared and initialized in the.data section. x:.double 18.2 y:.double 34.6 small:.double Single precision values may be declared and initialized in the same manner. z:.float -2.3

Load Instructions Double and single precision values may be loaded into memory using the l.d and l.s instructions, respectively. l.d $f2, x l.d $f4, y l.d $f18, small l.s $f17, z Floating point mathematics operations are carried out using the same instruction name except with a.d or.s at the end.

Floating Point Instructions Examples of double mathematics instructions follow below. add.d $f6, $f2, $f4 sub.d $f8, $f2, $f4 div.d $f10, $f2, $f4 mul.d $f14, $f2, $f4 Examples of single precision mathematics operations follow below. add.s $f16, $f17, $f21 sub.s $f16, $f17, $f21 div.s $f16, $f17, $f21 mul.s $f16, $f17, $f21

Floating Point Instructions Additionally, it is possible to move floating point values from one register to another using the mov.d or mov.s instructions. The destination is specified first, and the source is specified last. mov.d $f12, $f14 mov.s $f0, $f1

Floating Instructions There are also system call codes to read and write double and single precision values to and from the console. li $v0, 3 # print a double value stored in $f12 syscall li $v0, 2 # print a float value stored in $f12 syscall li $v0, 7 # read a double into $f0 syscall li $v0, 6 # read a float into $f0 syscall

Floating Pt. Registers It is possible to move values back and forth between floating point registers and integer registers. mfc1 $t1, $f1 #move value from $f1 in co-proc. 1 to $t1 #in co-proc. 0 mtc1 $f1, $t1 #move value from $t1 in co-proc. 0 to $f1 #in co-proc. 1 It is also possible to convert to and from double, single, and word formats using the cvt.x.y instruction where x and y are replaced with s, d, or w for float, double, or integer respectively. cvt.d.w $f16, $f1 #convert from word to double cvt.s.w $f16, $f1 #convert from word to float cvt.w.d $f1, $f2 #convert from double to word cvt.w.s $f1, $f2 #convert from float to word

Floating Point Instructions Comparing double or float values requires the use of the less than or greater than operator and the absolute value (abs.d) operator as we can't use an equals operator to compare double values. #print the truth results of x == y #need abs(x - y) < abs.d $f16, $f8 # $f8 contains x - y c.lt.d $f8, $f18 #set condition flag zero if abs(x - y) < small value Comparison results are stored in the coprocessor 1 condition flag. We can branch if the condition flag is true by using bc1t. We can branch if the condition flag is false using bc1f. These instructions use the following format: bc1f label bc1t label

Example Program An example of the use of the bc1f instruction follows below. bc1f else if: #if abs(x-y) < li $v0, 4 la $a0, xLTy syscall #beq $zero, $zero, endif works as well b endif else: li $v0, 4 la $a0, xGTEy syscall endif: li $v0, 10 #end program syscall

Example.data newLine:.asciiz "\n".text main: #initialization values go here do: #do loop operations addi $t1, $t1, 1 li $v0, 1 #print i or $t1 move $a0, $t1 #copy contents of $t1 into $a0 syscall li $v0, 4 #print a newline character la $a0, newLine syscall slt $t3, $t1, $t2 bne $t3, $zero, do

Iteration Recap Notice that if x < y or $t1 < $t2, $t3 is true or not equal to zero. We return to the beginning of the loop as long as $t3 is not equal to zero. Otherwise, we drop past the end of the loop and continue processing from that point. What if we want a while loop instead of a do-while? Notice that a while loop is simply a do-while where we check the condition first. So, we can modify our code to create the following while loop by checking our condition before entering the loop:

Example while(i < n) { //do loop operations i++; System.out.println(i); }

Assembly code.data newLine:.asciiz "\n".text main:#initialization values go here slt $t3, $t1, $t2 beq $t3, $zero, endwhile do: #do loop operations addi $t1, $t1, 1 li $v0, 1 #print i or $t1 move $a0, $t1 #copy contents of $t1 into $a0 syscall li $v0, 4 #print a newline character la $a0, newLine syscall slt $t3, $t1, $t2 bne $t3, $zero, do endwhile:#continue processing after the loop

Logical Operations Notice that we check if the condition i < n is false first. If so, we bypass theloop. We'll look at how to simplify this code in a later lecture. More logical operations – We've seen how to do comparisons and branching, but what if we want to evaluatethe truth value of multiple comparisons in the same if or while statement? – We need the logical operators && (and) and || (or) from Java/C. – MIPS implements these operations using the instructions "and" and "or".

Logical Operations Both of these are R-format instructions. That is, we represent "and" and "or“ with the following format: and $t1, $t2, $t3 or $t4, $t2, $t3 The result is the truth values of "$t2 && $t3" and "$t2 || $t3" are stored in $t1and $t4, respectively. We can make comparisons such as x < y || y < z easily by using multipleinstructions.

Logical Operations For example, assume x is $t1, y is $t2, and z is $t3. We can obtain the truthvalues of our comparisons x < y and y < z as follows: –slt $t4, $t1, $t2 # x < y –slt $t5, $t2, $t3 # y < z Now we can compute the truth value of x < y || y < z by finding the "or" result of$t4 and $t5. –or $t6, $t4, $t5 Similarly, if we wanted the result of x < y && y < z we could use the "and"instruction. –and $t6, $t4, $t5 Next time we will look at more examples of comparisons and logical operations, and we will look at floating point operations.