Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an assembly program to use the floating point unit to compute pi. Let the

ID: 3861440 • Letter: W

Question

Write an assembly program to use the floating point unit to compute pi. Let the user input the number of terms used for computing pi. For example, the number of terms is 4 in the above formula. You may assume that the number of terms is not larger than 100,000.

Steps:

1. show the student name and student ID.

2. ask the user to input n which is the number of terms.

3. if n == 0, exit the program.

4. If n > 100, 000, set it to 100, 000.

5. estimate pi using n terms.

6. show the estimated pi value.

8. go back to step 2.

Explanation / Answer

#    PROGRAM TO ADD TWO NUMBERS
#    Text segment
#               (all programs start with the next 3 lines)
        .text           #directive identifying the start of instructions
        .globl __start

__start:

# ------------- print prompt on "console" --------------------
        la      $a0, prompt     # address of prompt goes in
        li      $v0, 4          # service code for print string
        syscall

# ------------- read in the integer --------------------------
        li      $v0, 5          # service code
        syscall
        sw      $v0, Num1       # store what was entered
# -------------- read another
        li      $v0, 5          # service code
        syscall
        sw      $v0, Num2       # store what was entered

# ------ Perfrom the addition, $a0 := Num1 + Num2
        lw      $t0, Num1
        add     $a0, $t0, $v0

# ------ print the sum, it is in $a0
        li      $v0, 1          # print integer service call
        syscall

# ------ print a final string identifying the result, and ending with a new line
        la      $a0, final
        li      $v0, 4
        syscall

        li      $v0, 10         # exit program service
        syscall

#------------------------------------------------------------------
#       Data segment
#------------------------------------------------------------------
        .data
Num1:   .word   0
Num2:   .word   0
prompt: .ascii "Please type 2 integers, end each with the "
        .asciiz "Enter key: "
final: .asciiz " is the sum. "

#------ end of file ADDNUMS.ASM

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote