Questions
Assignment Instructions: 1) The Factorial The factorial of a non-negative integer ??, denoted by ??!, is...

Assignment Instructions:

1) The Factorial

The factorial of a non-negative integer ??, denoted by ??!, is the product of all positive integers less than or equal to ??. The textbook has an example of a recursive MIPS implementation of factorial. Additionally, a simplified version of the MIPS assembly language recursive implementation of the factorial function is attached. Trace the factorial example carefully using QTSPIM

2) Recursive definition of multiplication

The function ??????????(??, ??) for two positive integers 1 ? ??, and 1 ? ??, is defined as the following:

??????????(??, 1) = ??; ??????????(??, ??) = ?? + ??????????(??, ?? ? 1)

Write a recursive version of ??????????() in C or C++ and a pseudo C program (based on chapter 2 in the book) then use these programs to develop a MIPS program that gets as input two integers 0 < ?? ? 255, and 0 < ?? ? 255, and returns the result of ??????????(??, ??) in $v1.

Your deliverable should be the pseudo C and the assembly level function

Given code file one:

//copyable code

1.

.data

messagestr: .asciiz "Enter Number: "

.text

.globl main

main:

la $a0, messagestr

#load the data

li $v0, 4

#system call

syscall

#load the data

li $v0, 5

#system call

syscall

#move the data

move $a0,$v0   

jal factorial

move $a0,$v0   

li $v0,1   

syscall

li $v0,10

syscall

factorial:

#add the value

addi $sp,$sp,-8

#store the value  

sw $s0,0($sp)

#store the value   

sw $ra,4($sp)

#move the data

move $s0,$a0

#load the data   

li $v0,0x00000001 # 1

beq $s0,$v0,loop2

#branch instruction  

addi $a0,$s0,-1   

jal factorial

#multiply the data

mult $v0,$s0   

mflo $v0   

j loop3

#loop

loop2:

li $v0,0x00000001

loop3:

lw $ra,4($sp)   

lw $s0,0($sp)   

addi $sp,$sp,8   

jr $ra # return

Given code file two:

#####################################################################################
#       Functional Description: Main program to test Factorial function
#       Enter a negative number to terminate run
#####################################################################################

                .data
                .align          2

                .text
main:           addiu           $sp,  $sp,  -8  # Allocate space
mloop:

                li              $v0,  4         # Get value for N

                sw              $v0, 0 ($sp)
                jal             Fac             # Call factorial
                or              $v1,  $v0, $0
                addiu           $sp,  8         # Deallocate space

                li              $v0,  10
                syscall
#####################################################################################
# Functional Description: Recursive Factorial Fac  (N:  in,  N! :out)
#####################################################################################
Fac:
        lw              $a0,   0 ($sp)


        addiu           $sp,   $sp,   -16       #   Allocate    
        sw              $ra,   12 ($sp)         #   Save return address
        sw              $a0,   8($sp)
        slti            $t0,   $a0,  2          #   If N is 1 or 0,  then return the value 1
        beqz            $t0,   Go
        li              $v0,   1
        b               facret
Go:
        addi            $a0,   $a0,   -1                #
        sw              $a0,   0 ($sp)          #   Pass N-1 to factorial function
        jal             Fac                     #   Recursive call
        lw              $v0,   4($sp)           #   Get  (N-1)  !  back.
        lw              $ra,  12  ($sp)
        lw              $a0,  8 ($sp)
        mult            $v0,  $a0                       #  N* (N-1)  !
        mflo            $v0
facret:
        addiu           $sp,  $sp,  16          #  Deallocate
        sw              $v0,  4 ($sp)
        jr              $ra

In: Electrical Engineering

Describe the use of Destructive and Non-Destructive Analyses and Containment and Surveillance in the context of...

Describe the use of Destructive and Non-Destructive Analyses and Containment and Surveillance in the context of safeguards. Compare the different approaches and describe the benefits and shortcomings of each.

In: Mechanical Engineering

Profit function is homogenous of degree one and non-decreasing in input prices.

Briefly explain why you think the following statements are true, false, or uncertain.

Your grade will depend largely on the quality of your explanations.

  1. Profit function is homogenous of degree one and non-decreasing in input prices.
  2. If the demand faced by a firm is inelastic, selling one more unit of output will decrease revenues.
  3. It is usually assumed that a perfectly competitive firm's supply curve is given by its marginal cost curve. In order for this to be true, these additional assumptions are necessary:

I.          That the firm seek to maximize profits.

II.        That the marginal cost curve be positively sloped.

III.       That prices exceed average variable cost.

IV.       That prices exceed average total cost.

  1. If price is equal to short‑run average variable cost, the firm is at the point known as the profit maximizing point.

In: Economics

(a) With the aid of a diagram, explain the meanings of ‘pecuniary price”, ‘non-pecuniary price’ and...

(a) With the aid of a diagram, explain the meanings of ‘pecuniary price”, ‘non-pecuniary price’ and “full-economic price” by using this example.

(b) Explain why economic efficiency is not achieved even all tickets were sold out.

(c) Explain why profit-seeking concert organizers do not raise prices.

In: Economics

Justify selection of a non-destructive testing method to be used for inspection of welds on a...

Justify selection of a non-destructive testing method to be used for inspection of welds on a 3m high 2m diameter steel storage tank on a remote worksite.

In: Mechanical Engineering

The fermi function value is non zero within the band gap of a semiconductor. if the...

The fermi function value is non zero within the band gap of a semiconductor. if the fermi level is within the band gap. Do you expect electrons or holes to populate

energy states within the band gap? If yes, why? If not, why?

In: Physics

A random sample of non-English majors at a selected college was used in a study to...

A random sample of non-English majors at a selected college was used in a study to see if the student retained more from reading a 19th-century novel or by watching it in DVD form. Each student was assigned one novel to read and a different one to watch, and then they were given a 100-point written quiz on each novel. The test results are shown. Book 90 80 90 75 80 90 84 DVD 95 82 80 80 70 85 90 Use a 0.05 significance level to test the claim that the students score higher after watching the DVD.

1.Find the P-value.

2.Based on the P-value found , state your conclusion about the null hypothesis.

3.Based on your conclusion, state the conclusion about the claim.

4.Construct the 90% confidence interval to estimate the mean differences of the scores.

5.Based on the confidence interval, state the conclusion about the means.

In: Statistics and Probability

8. Definition: A set A is finite if there exists a non-negative integer c such that...

8. Definition: A set A is finite if there exists a non-negative integer c such that there exists a bijection from A to {n ∈ N : n ≤ c}. (The integer c is called the cardinality of A.)

(a) Let A be a finite set, and let B be a subset of A. Prove that B is finite. (Hint: induction on |A|. Note that our proof can’t use induction on |B|, or indeed refer to “the number of elements in B” at all, because we don’t yet know that B is finite!)

(b) Prove that the union of two disjoint finite sets is finite.

(c) Prove that the union of any two finite sets is finite. (Hint: A ∪ B = A ∪ (B − A))

In: Advanced Math

Imagine you are the manager of a non-profit business, and you are looking to hire a...

Imagine you are the manager of a non-profit business, and you are looking to hire a recent college graduate. You list the position as paying $20,000/year. After interviewing candidates you decide that some will be offered the expected salary, while some will be offered more because of experience and interviewing skills. Others will be offered less than expected until they can demonstrate competence and their salary will increase when they are fully qualified.

Using Microsoft® Excel®, run a chi square Goodness of Fit test to determine whether these observed starting salaries are significantly different. What do the findings tell you?

Write a 75- to 100-word summary to describe your results.

Paste your Microsoft® Excel® output below your summary.

Expected Salaries

Observed Salaries

Applicant 1

$20,000

$17,500

Applicant 2

$20,000

$20,000

Applicant 3

$20,000

$22,000

Applicant 4

$20,000

$20,500

Applicant 5

$20,000

$20,000

In: Statistics and Probability

Let A be a non-negative random variable (A>0) a) If A is discrete, show that E[A]...

Let A be a non-negative random variable (A>0)

a) If A is discrete, show that E[A] >= 0

b) If A is continous , show E[X]>=0

In: Statistics and Probability