Question: Write in MIPS the following 1) Ask for user input 2) Iterate over each character 3) Print each character to the screen Here is my
Write in MIPS the following
1) Ask for user input
2) Iterate over each character
3) Print each character to the screen
Here is my code:
###################################
#
# Simple Integer Calculator
#
#
#
####################################
.data
buffer: .space 20
str1: .asciiz "Enter in the problem: "
str2: .asciiz "The result is: "
.text
main:
la $a0, str1 # Load and print string asking for string
li $v0, 4
syscall
li $v0, 8 # take in input
la $a0, buffer # load byte space into address
li $a1, 20 # allot the byte space for string
move $t0, $a0 # save string to t0
syscall
la $a0, str2 # load and print "The result is" string
li $v0, 4
syscall
# la $t0, str # la means load address (so we load the address of str into $t0)
li $t1, 0 # $t1 is the counter. set it to 0
la $t3, 61 # 43 is ASCII of '+' in DEC
countChr:
lb $t2, 0($t0) # Load the first byte from address in $t0
beqz $t2, end # if $t2 == 0 then go to label end
addi $t1, $t1, 1
bne $t2, $t3, proceed # branch if symbol equals 43 (+)
move $t4, $t1 # save the position
proceed:
addi $t0, $t0,1 # else increment the address
j countChr # finally loop
end:
li $v0,1 # print $t0
move $a0,$t4
syscall
#la $a0, buffer # reload byte space to primary address
#move $a0, $t0 # primary address = t0 address (load pointer)
#li $v0, 4 # print string
#syscall
li $v0, 10 # end program
syscall
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
