Question

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 it out in base 2 as a sequence of 32 bits. (See logic2.a file.)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

KIPS CODE 1 :

swapTwoStrings:

            addiu   $sp, $sp, -24  

            sw $ra, 0($sp)    

            sw $fp, 4($sp)    

            addiu   $fp, $sp, 20

            add $t0, $zero, $a0        

            add $t1, $zero, $a1        

            add $t2, $zero, $a2       

            sll $t3, $t1, 2           

            sll $t4, $t2, 2           

            add $t5, $t0, $t3

            add $t6, $t0, $t4

            lw $t3, 0($t5)           

            lw $t4, 0($t6)           

            sw $t5, 0($t4)           

            sw $t6, 0($t3)                           

            lw $fp, 4($sp)

            lw $ra, 0($sp)

            addiu   $sp, $sp, 24

            jr $ra            

MIPS CODE 2:

.data

prompt1: .asciiz "\n\n Enter an integer:"

array: .space 24

linefeed: .asciiz "\n"

enterkey: .asciiz "Press any key to end the program."

.text

main:

li $s0, 0

for:

bge $s0, 6, end_for

li $v0, 4

la $a0, prompt1

syscall

li $v0, 5

syscall

move $t1,$v0

sw $t1,array($t0)

addi $t0,$t0,4

addi $s0,$s0,1

j for

end_for:

li $v0,4

la $a0,linefeed

syscall # print linefeed

li $v0,4

la $a0,enterkey

syscall # print enterkey

li $v0,5 # code for read_int

syscall #get int from user --> returned in $v0

li $v0,10 # code for exit

syscall # exit program

Add a comment
Know the answer?
Add Answer to:
MIPS Programming Assignment 4 (logical operations) Please write a complete MIPS assembly language programs for the...
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
  • CDA-3101 – MIPS Assembly Programming 1. Write the following code segment in MIPS assembly language code:...

    CDA-3101 – MIPS Assembly Programming 1. Write the following code segment in MIPS assembly language code: 3. Write a MIPS program to find the sum of squares from 1 to n. Where n=10. For example, the sum of squares for 10 is as follows: 12+22+32+……+n2=385

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

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

  • Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence....

    Write a program in MIPs Assembly Language to compute nth number of a fibonacci number sequence. Your program should prompt for an integer input n from the user. The program should call a recursive function to compute the nth fibonacci number. Your program must follow programming convention. You should submit program and screenshot of output in a single word/pdf file. You should use following recursive definition of fibonacci function: fib(0) = 0 fib(1) = 1 fib(n) = fib(n-1) +fib(n-2)

  • In this part of the assignment, you will write MIPS assembly code to replace characters in...

    In this part of the assignment, you will write MIPS assembly code to replace characters in a string. This program asks the user for a string named string and two characters orig and new. It then replaces each instance of the character orig found in string with the character new. It outputs the resulting string and the number of substitutions that were made. For example, if string were "wow", orig were 'w', and new were 'b', the program would output...

  • # ECE 445 Computer Organization # Homework 3, problem 9 # Write a MIPS assembly language...

    # ECE 445 Computer Organization # Homework 3, problem 9 # Write a MIPS assembly language program to count the number of positive values in an array of integers. # The array of integers and the array length are provided in the .data section below. # After running your code, the variable count (in memory) should contain the number of positive values in the array Insert your name here > Insert the date here > # Author: # Date: .text...

  • Assembly Language For x86 Processors 7th edition When you write programs to solve the programming exercises,...

    Assembly Language For x86 Processors 7th edition When you write programs to solve the programming exercises, use multiple procedures when possible. Follow the style and naming conventions used in this book. Use explanatory comments in your programs at the beginning of each procedure and next to nontrivial statements. Random Strings Create a procedure that generates a random string of length L, containing all capital letters. When calling the procedure, pass the value of L in EAX, and pass a pointer...

  • Write a program in ARM assembly language that copies each element of array A to consecutive...

    Write a program in ARM assembly language that copies each element of array A to consecutive fourth elements of array B, i.e., A[0] to B[0], A[1] to B[3], A[2] to B[7], etc. The array A is 12 elements long, and each element is a number that is 32 bits (1 word) wide. Assume the base address of array A is in register R2, and the base address of array B is in R3.

  • Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers...

    Q-1: Write a program in Assembly language using MIPS instruction set that reads 15 integer numbers from user and stores all the numbers in the array intArray. Now, read another integer number N from the user, find the total number of array elements that are greater or equal to the number N, and the total number of array elements that are lower than the number N You must have two procedures: i. ReadIntegerArray: this procedure should read integer array elements...

  • Write common assembly language (RISC) programs to a) sum the first n elements of an array...

    Write common assembly language (RISC) programs to a) sum the first n elements of an array A, and b) compute r = ab for unsigned integers a and b. Each program will consist of a driver and a subprogram. The drivers will 1) read one or more values from the keyboard, 2) call the subprogram, and 3) print a result. The subprograms must not: ● store into memory, ● use registers $1 – $9, or ● make system calls

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