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

Input output memory mapped-microprocessor, Memory Mapped I/O Memory I/O...

Memory Mapped I/O Memory I/O devices are mapped into the system memory map with ROM and RAM. To access a hardware  device, simply write or  read  to  those  'special'  addresse

PIC, LIST p=18f4550 #include org 0x0000 movlw 0x00 _________ movlw 0xFF ...

LIST p=18f4550 #include org 0x0000 movlw 0x00 _________ movlw 0xFF movwf PORTB end .

Write program that will generate array of ten random number, 1. Write a pro...

1. Write a program that will generate an array of ten random 32-bit integers, and that will  display on the monitor the numbers followed by either the words " has the fourth bit se

Hi, i have a question.

i have a question.

Daa-arithmetic instruction-microprocessor, DAA: Decimal Adjust Accumulator...

DAA: Decimal Adjust Accumulator:- This instruction is utilized to convert the result of the addition operation of 2 packed BCD numbers to a valid BCD number. The conclusion has to

The alpha, The Alpha : The development of the Alpha chip start in the y...

The Alpha : The development of the Alpha chip start in the year 1988 The new chip used 64 bit technology, let users to pack  more  complexity  into  their  programs  than  exis

Write a program that will input a number from the keyboard, Write a program...

Write a program that will input a number from the keyboard, and then display the number in binary form, as well as the number of one's in the number. Hint: Shift the value left (or

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.

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..

Bcsl-022, define accounting.briefly explain the accounting concepts which g...

define accounting.briefly explain the accounting concepts which guide the accountant at the recording stage.

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