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

Group-assemblers directive-microprocessor, GROUP : Group the Related Segme...

GROUP : Group the Related Segments:- The directive which is used to form logical groups of segments with same purpose or type. This isused to inform the assembler to form a log

Define word (dw)- assemblers directive-microprocessor, DW : Define Word:- ...

DW : Define Word:- The DW directive serves the same purposes as the DB directive, but now it makes the assembler  which reserves thenumber ofmemory words (16-bit) instead of by

Control transfer or branching instruction-microprocessor, Control Transfer ...

Control Transfer or Branching Instruction Control transfer instructions transfer the flow of execution of the program to a new address specified in the instruction indirectly o

NASM assembly language programming, NASM assembly language program: Consid...

NASM assembly language program: Consider a sequence of 19 strictly positive decimal digits, most likely stored in an array. There are obviously duplicates, and the sequence is un

8251 programmable/communication interface-microprocessor, 8251 Programmable...

8251 Programmable/Communication Interface As an instance of a serial interface device let us suppose Intel's 8251 A programmable communication interfaces. The 8251A is diagram

Lods-stos-string manipulating instruction-microprocessor, LODS : Load Stri...

LODS : Load String Byte or String Word:- The LODS instruction loads AL/AX register by the content of a string pointed to by DS:SI register pair. The SI is automatically modifie

Flow chart and pseudocode, #question.flow chart for a program to find out t...

#question.flow chart for a program to find out the number of even and odd numbers from a given series of 16-bit hexadecimal numbers.

Shr-sar-logical instruction-microprocessor, SHR : Shift Logical Right: Thi...

SHR : Shift Logical Right: This instruction performs bit-wise right shifts on the operand word or byte that might be reside in  a memory location or a register, by the specified c

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

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