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

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

Seg-segment-assemblers directive-microprocessor, SEG : Segment of a Label:...

SEG : Segment of a Label:- The SEG operator is which is used to decide the segment address of the, variable, label or procedure and substitutes the segment base address in plac

Program for dispaying lcd characters, #include"lcd.asm"       ; assembly fi...

#include"lcd.asm"       ; assembly file is included for displaying lcd characters Main: PORTA EQU 0xF80  ; PORTS PORTB EQU 0xF81 PORTC EQU 0xF82 PORTD EQU 0xF83 R

Tabular comparison for micro processors parameters, Tabular comparison for ...

Tabular comparison for µ PS' Parameters Tables (a) and (b) list the characteristic of Intel microprocessor. Table(a):   Table(b): It has a 64 bit da

Length-assemblers directive-microprocessor, LENGTH : Byte Length of a Labe...

LENGTH : Byte Length of a Label: This directive is not available in MASM. This is used to mention to the length of a data array or a string. MOV CX. LENGTH ARRAY This sta

Program translation sequence, Program Translation Sequence Developing ...

Program Translation Sequence Developing a software program to accomplish a particular task, the implementer chooses an appropriate language, develops the algorithm (a sequence

Multiplication using shift and add instruction, Multiply two numbers by usi...

Multiply two numbers by using shift and rotate instruction

A/D conversions, A/D conversion: Basic tasks: (a) Write a program that wil...

A/D conversion: Basic tasks: (a) Write a program that will read and display the analog voltage on pin PE7 approximately once every second. (b) Write a program that will read and d

Solotuon, using 8086 assembly language that interchange upper four bits to ...

using 8086 assembly language that interchange upper four bits to lower four bits. assume that data store in byte memory and it written back to same location. and assume the data as

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