1 / 13

MIPS mul div, and MIPS floating point instructions

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.

luce
Télécharger la présentation

MIPS mul div, and MIPS floating point instructions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MIPS mul div, and MIPS floating point instructions

  2. 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.

  3. 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.’’

  4. 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

  5. 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

  6. 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.

  7. 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

  8. Print and Read • Print: • li $v0, 2 • li $f12, 0.5 • syscall • Read • li $v0, 6 • syscall • (the read will be in $f0)

  9. 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

  10. Data move • mov.s $f0, $f1 copy $f1 to $f0. • mfc1 $t0, $f0 copy $f1 to $t0. • mtc1 $t0, $f0 copy $t0 to $f0.

  11. 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

  12. 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?

  13. 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 x2-n=0.

More Related