1 / 8

CDA 3100

CDA 3100. Recitation Week 5. Write a MIPS Program to do the Following:. Count the number of times a value v appears in an array A of n elements. Use the following: A = [12, 34, 67, 1, 45, 90, 11, 33, 67, 19] n = 10 v = 67. Answer: SPIM Setup. .text . globl main main:

matsu
Télécharger la présentation

CDA 3100

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. CDA 3100 Recitation Week 5

  2. Write a MIPS Program to do the Following: • Count the number of times a value v appears in an array A of n elements. • Use the following: • A = [12, 34, 67, 1, 45, 90, 11, 33, 67, 19] • n = 10 • v = 67

  3. Answer: SPIM Setup .text .globl main main: done: li $v0, 10 syscall

  4. Answer: Array Data .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: done: li $v0, 10 syscall

  5. Answer: Init Variables .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s0, A # base address of A li $s1, 10 # n li $s2, 67 # v ori $s3, $zero, 0 # accumulator ori $t0, $zero, 0 # index in A done: li $v0, 10 syscall

  6. Answer: Setup Loop .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s0, A #base address of A li $s1, 10 #n li $s2, 67 #v ori $s3, $zero, 0 # accumulator ori $t0, $zero, 0 # index in A loop: addi $t0, $t0, 1 beq $t0, $s1, done j loop done: li $v0, 10 syscall

  7. Answer: Load Values From Array .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s0, A #base address of A li $s1, 10 #n li $s2, 67 #v ori $s3, $zero, 0 # accumulator ori $t0, $zero, 0 # index in A loop: sll $t1, $t0, 2 add $t1, $s0, $t1 lw $t2, 0($t1) addi $t0, $t0, 1 beq $t0, $s1, done j loop done: li $v0, 10 syscall

  8. Answer: Increment Accumulator .data A: .word 12, 34, 67, 1, 45, 90, 11, 33, 67, 19 .text .globl main main: la $s0, A #base address of A li $s1, 10 #n li $s2, 67 #v ori $s3, $zero, 0 # accumulator ori $t0, $zero, 0 # index in A loop: sll $t1, $t0, 2 add $t1, $s0, $t1 lw $t2, 0($t1) bne $t2, $s2, noinc addi $s3, $s3, 1 noinc: addi $t0, $t0, 1 beq $t0, $s1, done j loop done: li $v0, 10 syscall

More Related