Question

In: Computer Science

MIPS ASSEMBLY LANGUAGE (I'm using MARS) Can you provide me with the code of this, without...

MIPS ASSEMBLY LANGUAGE (I'm using MARS)

Can you provide me with the code of this, without using DIV

(4a-b)%[(2+c)/d] (a,b,c,d are user inputs)

Solutions

Expert Solution

Given, Asked to write a MIPS assembly code to convert the equation without using division operator.

Explanation: As asked in question not to use division operator I used substraction logic to divide the equation then get the equation part by part. Please check the below code for exact functionality.

MIPS Code:

divide:
addiu $sp,$sp,-24
sw $fp,20($sp)
move $fp,$sp
sw $4,24($fp)
sw $5,28($fp)
lw $2,24($fp)
nop
srl $2,$2,31
andi $3,$2,0x00ff
lw $2,28($fp)
nop
srl $2,$2,31
andi $2,$2,0x00ff
xor $2,$3,$2
andi $2,$2,0x00ff
beq $2,$0,$L2
nop

li $2,-1 # 0xffffffffffffffff
b $L3
nop

$L2:
li $2,1 # 0x1
$L3:
sw $2,12($fp)
lw $2,24($fp)
nop
bgez $2,$L4
nop

subu $2,$0,$2
$L4:
sw $2,24($fp)
lw $2,28($fp)
nop
bgez $2,$L5
nop

subu $2,$0,$2
$L5:
sw $2,28($fp)
sw $0,8($fp)
b $L6
nop

$L7:
lw $3,24($fp)
lw $2,28($fp)
nop
subu $2,$3,$2
sw $2,24($fp)
lw $2,8($fp)
nop
addiu $2,$2,1
sw $2,8($fp)
$L6:
lw $3,24($fp)
lw $2,28($fp)
nop
slt $2,$3,$2
beq $2,$0,$L7
nop

lw $3,12($fp)
lw $2,8($fp)
nop
mult $3,$2
mflo $2
move $sp,$fp
lw $fp,20($sp)
addiu $sp,$sp,24
j $31
nop

$LC0:
.ascii "%0.2f\000"
main:
addiu $sp,$sp,-64
sw $31,60($sp)
sw $fp,56($sp)
move $fp,$sp
li $2,7 # 0x7
sw $2,24($fp)
li $2,3 # 0x3
sw $2,28($fp)
li $2,6 # 0x6
sw $2,32($fp)
li $2,2 # 0x2
sw $2,36($fp)
lw $2,24($fp)
nop
sll $3,$2,2
lw $2,28($fp)
nop
subu $2,$3,$2
mtc1 $2,$f0
nop
cvt.s.w $f0,$f0
swc1 $f0,40($fp)
lw $2,32($fp)
nop
addiu $2,$2,2
lw $5,36($fp)
move $4,$2
jal divide
nop

mtc1 $2,$f0
nop
cvt.s.w $f0,$f0
swc1 $f0,44($fp)
lwc1 $f0,40($fp)
nop
cvt.d.s $f0,$f0
lwc1 $f2,44($fp)
nop
cvt.d.s $f2,$f2
mov.d $f14,$f2
mov.d $f12,$f0
jal fmod
nop

cvt.s.d $f0,$f0
swc1 $f0,48($fp)
lwc1 $f0,48($fp)
nop
cvt.d.s $f0,$f0
mfc1 $7,$f0
mfc1 $6,$f1
lui $2,%hi($LC0)
addiu $4,$2,%lo($LC0)
jal printf
nop

move $2,$0
move $sp,$fp
lw $31,60($sp)
lw $fp,56($sp)
addiu $sp,$sp,64
j $31
nop

Please let me know in the comments if you need more help in this.


Related Solutions

I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two integers. Ideally, the program would ask for the user to type in the two integers. Then, the program would calculate the hamming distance. Afterward, it would ask if you'd like to find another hamming distance. If the user says yes, it would loop back to the beginning and ask for two new integers. Below is the code that I've created so far. Guidance with...
Using MIPS (MARS) - Assembly Language Assignment ( PLEASE USE COMMENTS TO DESCRIBE EACH STEP )...
Using MIPS (MARS) - Assembly Language Assignment ( PLEASE USE COMMENTS TO DESCRIBE EACH STEP ) Take input of name, the input of hours worked, and input of hourly wage, and use input of hourly wage and hours worked to calculate total paycheck and print Name, and paycheck.
In MIPS Assembly Language in Mars, define a method 1 to check if a number is...
In MIPS Assembly Language in Mars, define a method 1 to check if a number is divisible by 4. Then, define a method 2 to generate a random number, call method 1, and return result(number, yes/no) to main. Lastly, have the main method call method 2, and display the results.
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle....
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle. (NAME = John Doe) 2)Write a Program that intializes X to 10, Y to 20 and Z to -50, adds X and Y and Z and prints the following the value of each variable, for example value of x is 10 as well as the result of the addition.
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
Write a MIPS assembly language to transpose a square integer matrix in code
Write a MIPS assembly language to transpose a square integer matrix in code
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Hello there, I'm wondering can you do this problem without arrays? Using the given code on...
Hello there, I'm wondering can you do this problem without arrays? Using the given code on C++ Platform. Let me know ASAP. #include <iostream> #include <time.h> using namespace std; void shoot(bool &targetAlive, double accuracy) { double random = (rand() % 1000) / 1000.; targetAlive = !(random < accuracy); } int startDuel(int initialTurn) { bool personAlive[3] = {true, true, true}; double accuracy[3] = {0.333, 0.5, 1.0}; int turn = initialTurn; // which person has to shoot, initialTurn represents the first person...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT