1 / 9

MIPS Assembly

MIPS Assembly. Saleh Dindar CDA3101 Fall 2014. mul $t0, $a0, $a1 add $v0, $t0, $a2. Problem 1: Linear function. x → $a0 a → $a1 b → $a2 y → $v0. lw $t0, 0($a0) lw $t1, 0($a1) sw $t1, 0 ($a0 ) sw $t0, 0 ($a1 ). Problem 2: Swap numbers.

heidi-dixon
Download Presentation

MIPS Assembly

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 Assembly Saleh Dindar CDA3101 Fall 2014

  2. mul$t0, $a0, $a1 add $v0, $t0, $a2 Problem 1: Linear function x→ $a0 a →$a1 b → $a2 y→ $v0

  3. lw$t0, 0($a0) lw$t1, 0($a1) sw$t1, 0($a0) sw$t0, 0($a1) Problem 2: Swap numbers Assume a and b hold addresses to 32-bit integers in memory. Swap the numbers. a → $a0 b → $a1

  4. slt $t0, $a0, $zero bne$t0, $zero, elsepart move $v0, $a0 j endif elsepart: sub $v0, $zero, $a0 endif: Problem 3: Absolute value x → $a0 y→ $v0

  5. li $v0, 1 loop: beq $a0, $zero, endloop mul $v0, $a0, $v0 addi $a0, $a0, -1 j loop endloop: Problem 4: Factorial n→ $a0 y→ $v0

  6. move $v0, $zero move $t0, $zero loop: beq $t0, $a0, endloop lw $t1, 0($a1) add $v0, $v0, $t1 addi $t0, $t0, 1 addi $a1, $a1, 4 j loop endloop: Problem 5: Sum of array n → $a0 A→ $a1 y→ $v0 k → $t0

  7. move $t0, $zero li $t1, 1 li $t2, 1 loop: beq $t0, $a0, endloop add $t3, $t1, $t2 move $t1, $t2 move $t2, $t3 addi $t0, $t0, 1 j loop endloop: move $v0, $t1 Problem 6: Fibonacci numbers n → $a0 y→ $v0

  8. SPIM Simulator • Download from http://sourceforge.net/projects/spimsimulator/files/ • QtSpim_9.1.12_Windows.exe • QtSpim_9.1.13.mac.mpkg.zip • Read appendix A of the textbook

  9. .text 0x400000 mul$t0, $a0, $a1 add $v0, $t0, $a2 .word 0,0,0,0,0,0 Problem 1 in SPIM .text : Address in memory to load the program .word Put values in memory

More Related