Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MIPS Debugging Help! Sum should return correct value. 1+1 = 2 output should read sum=2 .data str1: .asciiz sum = 1 + 1 str2: .word

MIPS Debugging Help!

Sum should return correct value. 1+1 = 2

output should read sum=2

.data

str1: .asciiz "sum = 1 + 1"

str2: .word 0

str3: .word 0

str4: .word 0

str5: .word 0

str6: .word 0

newline: .asciiz " "

finalString: .asciiz " End"

finalAnswer: .word 0

int1: .word 0

int2: .word 0

.text

main:

la $t0, str1 # la means load address (so we load the address of str into $t0)

li $t1, 0 # $t1 is the counter. set it to 0

li $s0, 0 # set index for str to 0

li $s1, 0 # special index for str3

li $s2, 0 # special index for str4

li $s3, 0 # special index for str5

li $s4, 0 # special index for str6

lb $t2, str1($s0) # Load the first byte from str1

j word1

word1:

beq $t2, 32, word2

addi $t1, $t1, 1 # increment the counter

sb $t2, str2($s0) # store current character in the str2

addi $s0, $s0, 1 # increment the index

lb $t2, str1($s0) # Load the current byte from str1

j word1 # finally loop

word2:

addi $s0, $s0, 1 # increment the index to remove space

lb $t2, str1($s0) # Load the current byte from str1

add $t1, $t1, 1 # increment the counter

beq $t2, 32, word3

add $t1, $t1, 1 # increment the counter

sb $t2, str3($s1) # store current character in the str3

add $s1, $s1, 1 # increment special index for str3

lb $t2, str1($s0) # Load the first byte from address in $t0

j word2 # finally loop

word3:

addi $s0, $s0, 1 # increment the index to remove space

lb $t2, str1($s0) # Load the current byte from str1

add $t1, $t1, 1 # increment the counter

beq $t2, 32, word4

add $t1, $t1, 1 # increment the counter

sb $t2, str4($s2) # store current character in the str4

add $s2, $s2, 1 # increment special index for str4

lb $t2, str1($s0) # Load the first byte from address in $t0

j word3

word4:

addi $s0, $s0, 1 # increment the index to remove space

lb $t2, str1($s0) # Load the current byte from str1

add $t1, $t1, 1 # increment the counter

beq $t2, 32, word5

add $t1, $t1, 1 # increment the counter

sb $t2, str5($s3) # store current character in the str5

add $s3, $s3, 1 # increment special index for str5

lb $t2, str1($s0) # Load the first byte from address in $t0

j word4

word5:

addi $s0, $s0, 1 # increment the index to remove space

lb $t2, str1($s0) # Load the current byte from str1

add $t1, $t1, 1 # increment the counter

beq $t2, $0,next

add $t1, $t1, 1 # increment the counter

sb $t2, str6($s4) # store current character in the str6

add $s4, $s4, 1 # increment special index for str6

lb $t2, str1($s0) # Load the first byte from address in $t0

j word5

next:

addi $t3, $0, 0x2b

addi $t4, $0, 0x2d

addi $t5, $0, 0x2a

addi $t6, $0, 0x2f

addi $t9, $0, 0x3d

add $t0, $0, $0

add $t1, $0, $0

add $t2, $0, $0

add $t7, $0, $0

add $t8, $0, $0

la $t8, str5

lb $t1, ($t8)

lw $t6, str4

lw $t7, str6

sw $t6, int1

sw $t7, int2

beq $t3, $t1, adder

beq $t4, $t1, subtractor

beq $t5, $t1, multiplier

beq $t6, $t1, divider

j end

adder:

add $t2, $t6, $t7

j end

multiplier:

mult $t6, $t7

mflo $t2

j end

subtractor:

sub $t2, $t6, $t7

j end

divider:

div $t6, $t7

mflo $t2

j end

end:

sw $t2, finalAnswer

#display the results

li $v0, 4

la $a0, str2

syscall

li $v0, 11

la $a0, ($t9)

syscall

li $v0, 1

lw $a0, finalAnswer

syscall

#tell the OS that this is the end of the program

li $v0, 10

syscall

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

=+What religious holidays do you celebrate?

Answered: 1 week ago

Question

Discuss all branches of science

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago