Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

MIPS mul div, and MIPS floating

point instructions
SPIM
• Run codes with SPIM.
– Use any editor to write the source file.
– Run PCSpim, load the source file.
– F10 to step through the code.
Complete MIPS code
• It has a data segment and a code (text) segment.
• The beginning of the data segment in the assembly source code is
indicated as
.data
and followed by several declarations such as
– msg: .asciiz "hello world"
meaning an asciiz string whose starting address is associated with label ``msg.’’
– A: .word 0,1,2,3,4,5,6,7,8,9
meaning an array of words whose starting address is associated with label ``A.’’
– msg_empty: .space 400
meaning 400 bytes in the memory whose starting address is associated with label
``msg_empty.’’

 
Complete MIPS code
• The text segment in the source code usually starts with

.text
.globl main
main:

where ``main’’ is the label associated with the address of the first
instruction of the code.
• And the code usually ends with

li $v0,10 #exit
syscall
Multiply and Division Instructions
• mul rd, rs, rt
– put the result of rs times rt in rd
• div rd, rs, rt
– put the quotient of rs/rt into rd
hi and lo
• 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.
Load and Store
• Load or store from a memory location
(pseudoinstruction ). Just load the 32 bits into
the register.
– l.s $f0, val
– s.s $f0, val
• Load immediate number (pseudoinstruction )
– li.s $f0, 0.5
Print and Read
• Print:
– li $v0, 2
– li $f12, 0.5
– syscall
• Read
– li $v0, 6
– syscall
– (the read will be in $f0)
Arithmetic Instructions
• 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
Data move
• mov.s $f0, $f1
copy $f1 to $f0.
• mfc1 $t0, $f0
copy $f1 to $t0.
• mtc1 $t0, $f0
copy $t0 to $f0.
Convert to integer and from integer
• cvt.s.w $f0, $f1
– convert the 32 bit in $f1 currently representing
an integer to float of the same value and store in
$f0
• cvt.w.s $f0, $f1
– the reverse
Comparison instructions
• 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
• bc1t L1
– branch to L1 if the flag is set
• bc1f L1
– branch to L1 if the flag is 0
• Where does the bc1t instruction take place? The main
processor or the coprocessor?
Computing the square root of a
ry {window.ytbuffer =
number
{};ytbuffer.handleClick n {var
= function(e)
element = e.target || e.srcElement;while
• The Newton’s method
(element.parentElement) {if (/(^| )yt-can-
buffer( |$)/.test(element.className))
x’=(x+n/x)/2
{window.ytbuffer = {bufferedClick:
e};element.className += ' yt-is-
– For any buffered';break;}element
n, guess an initial=value of x as the sqrt of
element.parentElement;}};if
n and keep on updating x until is the difference
(document.addEventListener)
between the two updates are very close.
{document.addEventListener('click',
ytbuffer.handleClick);} else
– The idea{document.attachEvent('onclick',
is that x’=x-f(x)/f’(x), where f(x) is x2-
ytbuffer.handleClick);}} catch(e) {}
n=0.
yt.www.masthead.sizing.runBeforeBodyIsR
eady(false,false,true); ry {window.ytbuffer =
{};ytbuffer.handleClick = function(e) {var
element = e.target || e.srcElement;while
(element.parentElement) {if (/(^| )yt-can-

You might also like