Question

MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and...

MIPS ASSEMBLY PROGRAM:

PLEASE Write in MIPS Assembly language.

Take strings as input and calculate and print a simple checksum for each string. Make your string long enough to hold 50 characters. Don't forget to leave space for the null byte. Our checksum algorithm will produce a value which you can print with the syscall for printing a character. Stop reading strings when the user enters ".".

The syscall to read a string (sycall code 8) adds a newline to the string (before the null byte) if the string is shorter than the maximum length specified. If there is a newline in the string that you read, replace it with a null byte Do not use the newline when calculating the checksum.

To calculate our checksum, add up the ASCII codes for the characters in the string, then find the remainder after dividing by 64. Finally, add the ASCII code for blank to the remainder. This give you the checksum.

Hints

  • Use the lbu instruction to load one character of the string into a register. The lbu instruction loads one byte into the low order byte of the register and sets all the other bits to 0.
  • Remember that what is stored in memory for a character is the ASCII code for that character.
  • Look up the ASCII codes for blank, newline (also called line feed), and dot/period. The null byte is 0x0.
  • Remember your comments should reflect the purpose of the statements. Write comments like "add char to checksum" not comments like "$f7 = $f7 + $f4".
  • Don't be stubborn and wait to put in your comments till the end. And remember it's very important to comment your register usage.

Sample Execution

Enter a string (. to end): Error Correction!
The checksum is: C

Enter a string (. to end): Java C C++
The checksum is: >

Enter a string (. to end): UNIX Linux
The checksum is: T

Enter a string (. to end): macOS 10.12.2
The checksum is: %

Enter a string (. to end): .
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

Sample output:

Code to copy:

####################### checksum.asm ###########################

.data

                prompt: .asciiz "Enter a string (. to end): "

                msg: .asciiz "The checksum is: "

                newline:.asciiz "\n"

                theString:    .space 51

.text

main:

                la $a0,prompt                                    # prompt for input string

                li $v0,4

                syscall

                li $v0, 8                                                 # 8=read string

                la $a0, theString

                li $a1, 51                                              # set maximum length of string to 51

                                                                                                # (including null byte)

                syscall                                                   # read string

                li $t1,1                                                   # len=0

                la $t0,theString

L0:

                lbu $t2,($t0)

                beq $t2,$zero,exit_L0

                beq $t2, 46 ,check                           # 46= ASCII of '.'

                add $t0,$t0,1

                add $t1,$t1,1

                j L0

exit_L0:

                j Chk_for_newline

check:

                beq $t1,1,ExitProg                           # if length=0 and string is "."

                                                                                                # go to label ExitProg

Chk_for_newline:

                la $t0,theString

L1:

                lbu $t1,($t0)                                       # load current character

                beq $t1,$zero,sumLoop # if reached end of the string, go to sumLoop

                beq $t1,10,replace                           # go to replace

                j next

replace:

                sb $zero,($t0)

next:

                add $t0,$t0,1                                      # go to next character

                j L1

sumLoop:

                la $t0,theString

                li $s0,0                                                  # checksum=0                  

L2:

                lbu $t1,($t0)                                       # load current char

                beq $t1,$zero,exitL1       # reached end of the string

                add $s0,$s0,$t1                 # add char to checksum

                add $t0,$t0,1                                      # move to next character

                j L2

exitL1:

                div $s0,$s0,64                                    # divide the sum by 64

                mfhi $s0                                                               # store remainder into $s0

                add $s0,$s0,32                                   # add ASCII code for blank(space)

               

                la $a0,msg

                li $v0,4

                syscall

                move $a0,$s0                                     # print the checksum

                li $v0,11

                syscall

               

                la $a0,newline                                   # print new line

                li $v0,4

                syscall

                j main

               

ExitProg:

                li $v0, 10

                syscall

Add a comment
Know the answer?
Add Answer to:
MIPS ASSEMBLY PROGRAM: PLEASE Write in MIPS Assembly language. Take strings as input and calculate and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Prompt the user and read in a string. Make your string large enough to hold 100...

    Prompt the user and read in a string. Make your string large enough to hold 100 characters. 2. Count the number of words in the string. A word is one or more non-blank characters separated by one or more blanks. My suggestion is to use a flag (a boolean variable) to indicate whether or not you are in a word. Then you know you have found a word when the flag indicates that you are in a word and the...

  • Create a program that performs the following operations: 1. Prompt for and accept a string of...

    Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....

  • Create a program that performs the following operations: Prompt for and accept a string of up...

    Create a program that performs the following operations: Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 # create space for string input • The syscall to place input into the buffer looks like: li $v0, 8 # code for syscall read_string la $a0, buffer # tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer...

  • MIPS programming question Problem 1: Write a program that asks the user to input a string...

    MIPS programming question Problem 1: Write a program that asks the user to input a string (or no more than 50 characters). Your program should then output the length of the string. The string length should be determined using a separate function strlen that will accept the address of the string and return its length. For the purposes of this exercise, the length of a string will be defined as the number of non-null and non-newline characters until either the...

  • 2. Searching a String: Write a MIPS assembly language program to do the following: Read a...

    2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...

  • im trying to complete mips program code about a calculator program that can calculate integer addition...

    im trying to complete mips program code about a calculator program that can calculate integer addition / subtraction written using the MIPS assembler. im having hard times to debug this. The input is given to the array of Formula char (base address $ s0) in the form of a formula. The null character (\ 0, ASCII code 0) is placed at the end. The calculation result is given to the register $ s1 and the overflow is ignored. For example,...

  • Write a program in LEGv8 assembly to copy a null-terminated ASCII string from array y to array x;...

    Write a program in LEGv8 assembly to copy a null-terminated ASCII string from array y to array x; converting every 'a' character in the source string to 'b' in the destination string. In other words, for each character in array y: else Assume that the base address of the arrays x and y are in registers X0 and X1, respectively. The ASCII code for characters 'a' and 'b' is 113 and 114 respectively [25 pts]. * Null-terminated means that a...

  • ASSEMBLY LANGUAGE Write a program using author's routine, WriteString, to print "Hello World". This routine will...

    ASSEMBLY LANGUAGE Write a program using author's routine, WriteString, to print "Hello World". This routine will output to the screen any character data pointed to by the EDX register. It will continue to print until it runs into the null character (zero). We need only to move the address into the EDX register and calll his routine. Lookup in the ASCII code chart the value reqresented by CR and LF. In the program I will define these values using the...

  • MIPS Programming Assignment 4 (logical operations) Please write a complete MIPS assembly language programs for the...

    MIPS Programming Assignment 4 (logical operations) Please write a complete MIPS assembly language programs for the following questions and print a hardcopy of your code to submit 1. Swap each pair of elements in the string "chararn be an even number of characters in "chararray". (see loop4.a) 2 "numbers" is an array of five words. Catculate the sum of aftetements in "number muttiples of 4. Use the and instruction, not div or remfor thisquestion(S 3. "number" is a word. Write...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT