Write a mips program that reads a string from user input, Assembly Language

Assignment Help:

Description

Write a MIPS program that reads a string from user input, reverse each word (defined as a sequence of English alphabetic letters or numeric digits without any punctuations) in the string, and prints the string with the reversed words on the screen. For example, "10 is ten, t10 is not." becomes "01 si net, 01t si ton." after processing.

Main program:

Prompt user to enter a string by printing a prompt message "Please enter a string."

Read a string from user input.

If the string is "quit" or "exit" (case insensitive), exit the program.

If the string is empty, go to step 1.

Call Subprogram 1 to reverse the words in the string, passing the following two parameters to the subprogram via the stack.

(1) The start address of the string.

(2) The start address where the string with the reversed words should be stored.

Print the following two lines on the screen.

(1) The first line should read as "There are ### alphabetic letters and *** numeric digits in the string." where "###" and "***" are the real numbers.

(2) The second line is the string with the reversed words using the address returned from the subprogram.

Repeat the above steps.

Subprogram 1:

Identify the start address and length of the next word in the string (starting from left side).

Call Subprogram 2 to reverse the identified word, passing the following three parameters to the subprogram via registers.

(1) The start address of the word.

(2) The length of the word.

(3) The start address where the reversed word should be stored.

Increment the letter counter and digit counter based on the return values.

Copy the punctuations (including spaces) following the word to the corresponding location in the space provided for the result string.

If a null character is met, return the respective number of alphabetic letters and numeric digits in the string; otherwise repeat the above steps.

Subprogram 2:

Reverse the word specified by the first two parameters, and store the reversed word at the addressed given by the third parameter.

Count the respective number of alphabetic letters and numeric digits while reversing.

Return the respective number of alphabetic letters and numeric digits in the word.

# This is how far I have come on my project. I showed it to my Professor and this was his # response. I am stuck. I need help please.

######################################################################

#Checking "exit" and "quit" does not work.                             

# $s2, $s3 registers are used without being preserved first.

# The subprogram does not store the reversed string at the provided address and simply #displays the string in the reverse order. It does not return any value either, inconsistent #with the header.

###################################################################

.data

message_prompt: .asciiz " \n Please enter a string "

in_string: .space 64                                       # declaring space for input string message

test_message_quit: .asciiz "quit"                        # declaring space for quit string message

test_message_exit: .asciiz "exit"                        # declaring space for exit string message

out_string:  .space 64

.text

.globl main

main:

      la    $a0,message_prompt                             # loading address of string

      li    $v0,4                                          # making a system call to print string

      syscall

      la    $a0,in_string                                  # loading address of input string

      li    $a1,64                                         # space declared for string

      li    $v0,8                                          # reading in string

      syscall

      la $t0,in_string                                     # loading address of input string into a register

      la $a0, test_message_quit                            # loading address of quit string into a register

      move $s0,$a0                                         # moving contents of the argument into a stored register

      la $a0, test_message_exit                            # loading address of exit string into a register

      move $s1,$a0

make_lower:

       lb    $t1,($t0)

       beqz  $t1,find_quit

                                                           # if NULL we are don

       blt    $t1,'z',found

       bgt   $t1,'a',found

       addiu $t1,$t1, 32

       sb    $t1,($t0)

found:

      addiu $t0,$t0,1                                      # increment pointer

      j     make_lower

find_quit:                                                 # exit when entered word is quit

         la   $a0, in_string

         move $t3, $a0

         lb   $t4,($s0)

         lb   $t5,($t3)

         bne  $t4, $t5, find_exit

         addi $s1,$s1,1

         addi $t3,$t3, 1

         beqz $t2, exit_call

         j find_quit

find_exit:

         la   $a0, in_string

         move $t3, $a0

         lb   $t4,($s1)

         lb   $t5,($t3)

         bne  $t4, $t5, go_to_reverse

         addi $s0,$s0,1

         addi $t3,$t3, 1

         beqz $t2, exit_call

         j find_exit

go_to_reverse:

               la $a0,in_string

               move $s2,$a0

               la $a0,out_string

               move $s3,$a0

               addi $sp,$sp, -8

               sw   $s2, 0($sp)

               sw   $s3, 4($sp)

               jal reverse

           j main

reverse:   lw $s2, 0($sp)                                  #  Get arguments

           lw $s3, 4($sp) 

           move $t8, $s2

Find_End:

           lb    $t6,($s2) 

                                          # load t0 contents into t1

           beqz  $t6, exit1 

                                        # if t1 = "/0', branch to exit1

           addi  $s2,$s2,1                                  # moving to the next address

           j     Find_End                                   # repeat loop if condition not met

 

exit1:      la $t2, in_string                                # load address of string into t2 register B

 

reverse_string:

              subu $s2,$s2,1                                # decrement register t0 register A

              lb $a0, ($s2)

              li $v0, 11

              syscall           

              beq  $s2, $t8, exit_call

                                                            #  branch to ex--it when address of to equals original address

              j   reverse_string                           #  repeat loop

exit_call:

        jr $ra

exit:

li    $v0,10                                      # exit

syscall


Related Discussions:- Write a mips program that reads a string from user input

Sub-arithmetic instruction-microprocessor, SUB: Subtract :- The subtract in...

SUB: Subtract :- The subtract instruction subtracts the source operand from destination operand and result is left in the destination operand. Source operand might be memory locati

8086 microprocessors, program to find negative and positive integers from g...

program to find negative and positive integers from given signed numbers with output and explanation of every instructions.

PIC lights on, errorlevel -302 ;prevents error code for this...

errorlevel -302 ;prevents error code for this chipset __config 0x373A ;chip config PIC spec page 146 processor 16F877A ;chipset reset code

Stand alone system - assembly language program, Develop an assembly languag...

Develop an assembly language program for the system and simulate it using MPLAB. From this produce a demo program (in Assembly language) that will run on the MatrixMultimedia Devel

Write a mips assembly language program, Write a MIPS/SPIM assembly language...

Write a MIPS/SPIM assembly language program that prints the smallest and largest values found in a non-empty table of N word-sized integers. The address of the first entry in your

Program to evaluate equation, Write a program to evaluate the following exp...

Write a program to evaluate the following expression. You are to evaluate the following equation: num1 - (input + num2) - (num3 + num4) Input will be a hex number input by

Program to accept the input from user, Write an assembly language program t...

Write an assembly language program that will: accept keyboard input of a positive integer value N; compute the sum S= 1+ 2 + 3 + ... + N; print (output) the computed su

Assembly Language Programming, Write a program that defines symbolic consta...

Write a program that defines symbolic constants for all of the days of the week

Rics/cisc architecture-microprocessor, RICS/CISC Architecture An essent...

RICS/CISC Architecture An essential aspect of computer architecture is the design of the instruction set for the processor.  The instruction set selected for a specific compute

Aas-arithmetic instruction-microprocessor, AAS: ASCII Adjust AL After Subt...

AAS: ASCII Adjust AL After Subtraction AAS instruction correct the result in the AL register after subtracting operation of two unpacked ASCII operands. The result is in unpacked

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd