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

Program, Write an application that does the following: (1) fill an array wi...

Write an application that does the following: (1) fill an array with 50 random integers; (2) loop through the array, displaying each value, and count the number of negative values;

Read file in 8086, Write a procedure to read a text file and copy its cont...

Write a procedure to read a text file and copy its contents to another text file using 8086 assembly language .

Aaa-arithmetic instruction-microprocessor, AAA: ASCII Adjust after Additio...

AAA: ASCII Adjust after Addition operation the AAA instruction is executed after an ADD instruction that adds 2 ASCII coded operands to give a byte of outcome in the AL. The AAA i

Not-logical instruction-microprocessor, NOT : Logical Invert: The NOT inst...

NOT : Logical Invert: The NOT instruction complements (inverts) the contents of an a memory location or operand register bit by bit. The instance are as following: Example :

Totorial, How can i starting with Assembly langauge?

How can i starting with Assembly langauge?

Rep-string manipulation instruction-microprocessor, REP : Repeat Instructi...

REP : Repeat Instruction Prefix :- This instruction is utilized as a prefix to other instructions. The instruction in which the REP prefix is provided, is executed repetitively

Introduction to microprocessor, Introduction to Microprocessor: Micropr...

Introduction to Microprocessor: Microprocessor works like a CPU in a microcomputer. It's present as a single IC chip in a microcomputer. Microprocessor is the soul of the machi

Machine level programs-microprocessor, Machine Level Programs In this s...

Machine Level Programs In this section, a few machine levels programming instance, rather then, instruction sequences are presented for comparing the 8086 programming with that

Program, move a byte string ,16 bytes long from the offset 0200H to 0300H i...

move a byte string ,16 bytes long from the offset 0200H to 0300H in the segment 7000H..

8086 minimum mode system and timing-microprocessor, 8086 Minimum mode Syst...

8086 Minimum mode System and Timing In a minimum mode 8086 system, the microprocessor 8086 is operated in minimum mode by strapping its MN/MX pin to logic 1.All the control si

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