Question

In: Computer Science

Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...

Write a MIPS Assembly Language program to perform the following operations:

Request and read two integers from the console (Dn and Up),

Call a recursive function to compute the result

int RecurseFunc( int Dn, int Up )

{

if( Dn < 1 ) return 0;

else return Dn * Up + RecurseFunc( Dn - 1, Up + 1 );

}

Print out the results

Submit your code and report here.

Solutions

Expert Solution

CODE IN MIPS:

RecurseFunc(int, int):
daddiu $sp,$sp,-48
sd $31,40($sp)
sd $fp,32($sp)
sd $28,24($sp)
sd $16,16($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(RecurseFunc(int, int))))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(RecurseFunc(int, int))))
move $3,$4
move $2,$5
sll $3,$3,0
sw $3,0($fp)
sll $2,$2,0
sw $2,4($fp)
lw $2,0($fp)
bgtz $2,.L2
nop

move $2,$0
b .L3
nop

.L2:
lw $3,0($fp)
lw $2,4($fp)
mult $3,$2
mflo $16
lw $2,0($fp)
addiu $2,$2,-1
move $3,$2
lw $2,4($fp)
addiu $2,$2,1
move $5,$2
move $4,$3
ld $2,%got_disp(RecurseFunc(int, int))($28)
move $25,$2
1: jalr $25
nop

addu $2,$16,$2
.L3:
move $sp,$fp
ld $31,40($sp)
ld $fp,32($sp)
ld $28,24($sp)
ld $16,16($sp)
daddiu $sp,$sp,48
j $31
nop

.LC0:
.ascii "enter two numbers\000"
.LC1:
.ascii "%d%d\000"
.LC2:
.ascii "%d\000"
main:
daddiu $sp,$sp,-48
sd $31,40($sp)
sd $fp,32($sp)
sd $28,24($sp)
move $fp,$sp
lui $28,%hi(%neg(%gp_rel(main)))
daddu $28,$28,$25
daddiu $28,$28,%lo(%neg(%gp_rel(main)))
ld $2,%got_page(.LC0)($28)
daddiu $4,$2,%got_ofst(.LC0)
ld $2,%call16(printf)($28)
move $25,$2
1: jalr $25
nop

daddiu $3,$fp,8
daddiu $2,$fp,4
move $6,$3
move $5,$2
ld $2,%got_page(.LC1)($28)
daddiu $4,$2,%got_ofst(.LC1)
ld $2,%call16(scanf)($28)
move $25,$2
1: jalr $25
nop

lw $2,4($fp)
lw $3,8($fp)
move $5,$3
move $4,$2
ld $2,%got_disp(RecurseFunc(int, int))($28)
move $25,$2
1: jalr $25
nop

sw $2,0($fp)
lw $2,0($fp)
move $5,$2
ld $2,%got_page(.LC2)($28)
daddiu $4,$2,%got_ofst(.LC2)
ld $2,%call16(printf)($28)
move $25,$2
1: jalr $25
nop

move $2,$0
move $sp,$fp
ld $31,40($sp)
ld $fp,32($sp)
ld $28,24($sp)
daddiu $sp,$sp,48
j $31
nop


Related Solutions

Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays the sum and the difference. In the .data section, define two variables num1 and num2 both words. Initialize num1 to 92413 10 and num2 to D4B 16 (use 0xD4B to initialize, Note that D4B is a hexadecimal number). Your main procedure/function should load the values of num1 and num2 into two temporary registers, and display them on the console window. Then add the values...
Write a MIPS Assembly language program to request a file name from the user, open the...
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write out the contents to the console. This is what I have so far: .data    fileName:   .space 100    prompt1:   .asciiz "Enter the file name: "    prompt2:    .asciiz ""    prompt3:   .asciiz "\n"    buffer:    .space 4096 .text    main:        #        li $v0, 4        la $a0, prompt1       ...
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product...
Write a MIPS assembly program to repeatedly read two non-negative integers and print the integer product and quotient without using the multiplication and division instructions. Each input number will be entered on a separate line. Your program will terminate when two zeroes are entered by the user. If only the second number in a pair is zero, then a divide-by-zero error message should be printed for the division operation. Use comments generously in your program. Test your program with the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT