MIPS mul div, and MIPS floating point instructions.

Slides:



Advertisements
Similar presentations
5Z032 Processor Design SPIM, a MIPS simulator Henk Corporaal
Advertisements

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.
Assembly Language Working with the CPU.
Lecture 16: Computer Arithmetic Today’s topic –Floating point numbers –IEEE 754 representations –FP arithmetic Reminder –HW 4 due Monday 1.
CMPT 334 Computer Organization Chapter 3 Arithmetic for Computers [Adapted from Computer Organization and Design 5 th Edition, Patterson & Hennessy, ©
Comp Sci instruction encoding 1 Instruction Encoding MIPS machine language Binary encoding of instructions MIPS instruction = 32 bits Three instruction.
1 Lecture 9: Floating Point Today’s topics:  Division  IEEE 754 representations  FP arithmetic Reminder: assignment 4 will be posted later today.
1 Ó1998 Morgan Kaufmann Publishers Chapter 4 計算機算數.
CS 61C L16 : Floating Point II (1) Kusalo, Spring 2005 © UCB Lecturer NSOE Steven Kusalo inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture.
CS 61C L16 : Floating Point II (1) Garcia, Spring 2004 © UCB Lecturer PSOE Dan Garcia inst.eecs.berkeley.edu/~cs61c CS61C.
COMPUTER ARCHITECTURE & OPERATIONS I Instructor: Hao Ji.
Systems Architecture Lecture 14: Floating Point Arithmetic
COSC 2021: Computer Organization Instructor: Dr. Amir Asif Department of Computer Science York University Handout # 5 Unsigned integer and floating point.
CPS3340 COMPUTER ARCHITECTURE Fall Semester, /14/2013 Lecture 16: Floating Point Instructor: Ashraf Yaseen DEPARTMENT OF MATH & COMPUTER SCIENCE.
CSF 2009 Arithmetic for Computers Chapter 3. Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing.
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.
Lecture 9: Floating Point
Floating Point Representation for non-integral numbers – Including very small and very large numbers Like scientific notation – –2.34 × –
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:
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
1 Lecture 10: Floating Point, Digital Design Today’s topics:  FP arithmetic  Intro to Boolean functions.
Rounding Modes 3 Rounding: the process to obtain the best possible floating-point representation for a given real value. ANSI/IEEE standard:
C OMPUTER O RGANIZATION AND D ESIGN The Hardware/Software Interface 5 th Edition Chapter 3 Arithmetic for Computers.
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.
Morgan Kaufmann Publishers Dr. Zhao Zhang Iowa State University
Floating Point Processor Condition Bit The MIPS Floating Point Accelerator (FPA) chip (now, usually part of the processor chip) has a condition bit that.
10/7/2004Comp 120 Fall October 7 Read 5.1 through 5.3 Register! Questions? Chapter 4 – Floating Point.
King Fahd University of Petroleum and Minerals King Fahd University of Petroleum and Minerals Computer Engineering Department Computer Engineering Department.
COMPUTER ORGANIZATION ARITHMETIC YASSER MOHAMMAD.
Review. Interger Number Representations To convert an unsigned decimal number to binary: you divide the number N by 2, let the remainder be the first.
Computer Organization CS345 David Monismith Based upon notes by Dr. Bill Siever and notes from the Patternson and Hennessy Text.
MIPS Programming.
/ Computer Architecture and Design
System Calls & Arithmetic
CSCI206 - Computer Organization & Programming
Morgan Kaufmann Publishers Arithmetic for Computers
Morgan Kaufmann Publishers Arithmetic for Computers
Computer Architecture & Operations I
Arithmetic for Computers
MIPS floating point instructions
Chapter Three : Arithmetic for Computers
Morgan Kaufmann Publishers Arithmetic for Computers
/ Computer Architecture and Design
Pseudo instructions.
Floating Point Arithmetics
CSCI206 - Computer Organization & Programming
Floating Point ICS 233 Computer Architecture & Assembly Language
Final Review.
SPIM Syscalls.
Computer Architecture Computer Science & Engineering
Review.
Floating Point Arithmetic
Computer Arithmetic Multiplication, Floating Point
Pseudo instructions.
Review.
Review.
October 17 Chapter 4 – Floating Point Read 5.1 through 5.3 1/16/2019
cnn.com/2004/ALLPOLITICS/10/05/debate.main/
Floating Point Arithmetic
Floating Point Arithmetic
Morgan Kaufmann Publishers Arithmetic for Computers
Flow of Control -- Conditional branch instructions
Floating Point Arithmetic
Floating Point Faculty of Information Technology University of Petra
Inst.eecs.berkeley.edu/~cs61c/su05 CS61C : Machine Structures Lecture #11: FP II & Pseudo Instructions Andy Carle Greet class.
Number Representation
Presentation transcript:

MIPS mul div, and MIPS floating point instructions

Multiply and Division Instructions mul rd, rs, rt – puts the result of rs times rt in rd div rd, rs, rt – A pseudo instruction – puts the quotient of rs/rt into rd

hi and lo Special ‘addressable’ registers – you can not use these directly, you have to use special move instructions mult rs,rt – put the high word in hi and low word in lo. div rs, rt – put the remainder in hi and quotient in lo. mfhi rd – copies the value from hi and stores it in rd mflo rd – copies the value from lo and stores it in rd

Floating Point Floating point registers and the instructions that operate on them are on a separate chip referred to as coprocessor 1 As a result floating point instructions typically can not use regular registers directly, you need to move the values into floating point registers Uses special registers $f0-$f31 (32 just like the number of main registers) Each register can store a single precision floating point number Pairs of registers can store a double precision floating point number – Ex. Storing a double precision number into $f0 uses both $f0 and $f1 – Because of this, can only store to even numbered f registers When using functions, treat f registers like s registers – That is store them onto the stack if you need to use them within a function

Load and Store (single precision) Load or store from a memory location. Just load the 32 bits into the register. – lwc1 $f0, 0($t0) l.s $f0, 0($t0) – swc1 $f0, 0($t0) s.s $f0, 0($t0)

Load and Store (double precision) Load or store from a memory location. Just load the 64 bits into the register. – ldc1 $f0, 0($t0) l.d $f0, 0($t0) – sdc1 $f0, 0($t0) s.d $f0, 0($t0)

Load and Store (immediate) Load immediate number (pseudoinstruction ) – li.s $f0, 0.5 – li.d $f0, 0.5

Print and Read (single precision) Print: – li $v0, 2 – li.s $f12, 0.5 – syscall Read – li $v0, 6 – syscall – (the read will be in $f0 )

Print and Read (double precision) Print: – li $v0, 3 – li.d $f12, 0.5 – syscall Read – li $v0, 7 – syscall – (the read will be in $f0 )

Arithmetic Instructions Single Precision abs.s $f0, $f1 add.s $f0, $f1, $f2 sub.s $f0, $f1, $f2 mul.s $f0, $f1, $f2 div.s $f0, $f1, $f2 neg.s $f0, $f1 Double Precision abs.d $f0, $f2 add.d $f0, $f2, $f4 sub.d $f0, $f2, $f4 mul.d $f0, $f2, $f4 div.d $f0, $f2, $f4 neg.d $f0, $f2

Data move mov.s $f0, $f1 copy $f1 to $f0. mov.d $f0, $f2 copy $f2 to $f0. mfc1 $t0, $f0 copy $f0 to $t0. Note the ordering mtc1 $t0, $f0 copy $t0 to $f0. Note the ordering

Convert to integer and from integer cvt.s.w $f0, $f1 – convert the 32 bits in $f1 currently representing an integer to float of the same value and store in $f0 cvt.w.s $f0, $f1 – the reverse cvt.d.w $f0, $f2 – convert the 64 bits in $f2 currently representing an integer to float of the same value and store in $f0 cvt.w.d $f0, $f2 – the reverse

Branch instructions bc1t L1 – branch to L1 if the flag is set bc1f L1 – branch to L1 if the flag is not set

Comparison instructions (single precision) c.lt.s $f0,$f1 – set a flag in coprocessor 1if $f0 < $f1, else clear it. The flag will stay until set or cleared next time c.le.s $f0,$f1 – set flag if $f0 <= $f1, else clear it c.gt.s $f0,$f1 – set flag if $f0 > $f1, else clear it c.ge.s $f0,$f1 – set flag if $f0 >= $f1, else clear it c.eq.s $f0,$f1 – set flag if $f0 == $f1, else clear it c.ne.s $f0,$f1 – set flag if $f0 != $f1, else clear it

Comparison instructions (double precision) c.lt.d $f0,$f2 – set a flag in coprocessor 1if $f0 < $f2, else clear it. The flag will stay until set or cleared next time c.le.d $f0,$f2 – set flag if $f0 <= $f2, else clear it c.gt.d $f0,$f2 – set flag if $f0 > $f2, else clear it c.ge.d $f0,$f2 – set flag if $f0 >= $f2, else clear it c.eq.d $f0,$f2 – set flag if $f0 == $f2, else clear it c.ne.d $f0,$f2 – set flag if $f0 != $f2, else clear it

Computing the square root of a number n The Newton’s method x’=(x+n/x)/2 – For any n, guess an initial value of x as the sqrt of n and keep on updating x until is the difference between the two updates are very close. – The idea is that x’=x-f(x)/f’(x), where f(x) is x 2 - n=0.

. data #val1:.float 0.6.text.globl main main: li.s $f0, mfc1 $a0, $f0 jal calsqrt done: mtc1 $v0, $f12 li $v0,2 syscall exit: li $v0,10 syscall # calsqrt: # calculating the square root of n # using the formula x'=(x+n/x)/2 # loop until |x'-x| < calsqrt: addi $sp, $sp, -24 # store f swc1 $f0, 20($sp) # registers swc1 $f1, 16($sp) # onto stack swc1 $f2, 12($sp) swc1 $f3, 8($sp) swc1 $f20, 4($sp) swc1 $f21, 0($sp) mtc1 $a0, $f0 # $f0 gets n li.s $f20, 2.0 # $f20 = 2 for dividing li.s $f21, # $f21 = for comparison div.s $f1, $f0, $f20 # $f1 = x = n/2 calsqrtloop: div.s $f2, $f0, $f1 # $f2 = n/x add.s $f2, $f2, $f1 # $f2 = n/x + x div.s $f2, $f2, $f20 # $f2 = x’ = (n/x + x)/2 sub.s $f3, $f2, $f1 # $f3 = x'-x abs.s $f3, $f3 # $f3 = |x'-x| c.lt.s $f3, $f21 # set flag if |x'-x| < bc1t calsqrtdone mov.s $f1, $f2 j calsqrtloop calsqrtdone: mfc1 $v0, $f2 lwc1 $f0, 20($sp) # restore f lwc1 $f1, 16($sp) # registers lwc1 $f2, 12($sp) # from stack lwc1 $f3, 8($sp) lwc1 $f20, 4($sp) lwc1 $f21, 0($sp) addi $sp, $sp, 24 jr $ra