Question

Write a program to evaluate the arithmetic expression: (25xy - 10x - 6y + 28)/7 Use...

Write a program to evaluate the arithmetic expression: (25xy - 10x - 6y + 28)/7

Use symbolic addresses x, y, answer, and remainder. Pick two registers for x and y and load them from memory. At the end of the program, store the answer and remainder to memory. Assume that the values are small enough so that all results fit into 32 bits. Since load delays are turned on in SPIM be careful what instructions are placed in the load delay slot.

Verify that the program works by using several initial values for x and y. Use x=1, y=1 and x=1, y= -1 to start since this will make debugging easy. Then try some other values. Don’t assume that x and y are positive.

Remember that a value loaded from memory can only be used after a one instruction delay slot. Also, be sure to use the basic assembly two-operand instructions for multiply and divide and to retrieve the results of the operation from the lo and hi registers.

Use register $10 as a base register and use register-offset addressing to load and store values. Set up the base register with a lui instruction. The program at the end of the chapter will be useful.

Set MIPS settings to the following:

ON Bare Machine

ON Enable Delayed Loads

ON Enable Delayed Branches

OFF Load Exception Handler

OFF Enable Mapped IO

OFF Accept Pseudo Instructions

Set these options as specified or QtSpim will start up with options you don’t want. You may have to set the options, close QtSpim, and then restart it for the options to have an effect. Use only those instructions that have been discussed in the notes through chapter 15. Include a register use table in the documentation at the top of your source program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

.data
                # declare varaibles
                # memory address are stored as default in spim as follow
                x:       .word -17   # use address 0x10000000 by default
                y:       .word -13   # next address is 0x10000004
                answer:       .word 0       # at 0x10000008
                remainder:   .word 0       # at 0x1000000c
                # stores 9 bytes including null terminator at end
                ans_text:    .asciiz "Answer: "       
                rem_text:    .asciiz "\nRemainder: "
              
.text
####################################################################
# Procedure main
# Description: evaluates (25xy - 10x - 6y + 28)/7
# parameters:
# return value:
# registers to be used: $8, $9, $10, $11
###################################################################
main:
                # load x into $8
                lui, $10, 0x1000
                lw $8, 0($10)       # $8 = value of x
                # load y in $9
                lw $9, 4($10)       # $9 = value of x
                addi $11, $zero, 25   # $11 = 25
                # evaluate first term of numerator
                mult $11, $8  
                mflo $11       # $11 = 25x
                # assuming result fit into 32 bits
                # so allbits are in lo register
                mult $11, $9
                mflo $11       # $11 = 25xy
                # store result in answer
                # address of answer is 3rd word location
                sw $11, 8($10)       # answer = 25xy
                # evaluate second term of numerator
                addi $11, $zero, -10   # $11 = -10
                mult $11, $8  
                # load answer
                lw $9, 8($10)       # $9 = 25xy
                mflo $11       # $11 = -10x
                add $11, $9, $11   # $11 = 25xy - 10x
                # store result in answer
                sw $11, 8($10)       # answer = 25xy - 10x
                # load y in $9
                lw $9, 4($10)       # $9 = y
                addi $11, $zero, -6   # $11 = -6
                mult $9, $11
                mflo $11       # $11 = -6y
                # load answer
                lw $9, 8($10)       # $9 = 25xy - 10x
                addi $8, $zero, 28   # $8 = 28
                add $11, $9, $11   # $11 = 25xy - 10x - 6y
                add $11, $11, $8   # $9 = 25xy -10x -6y +28
                # perform division
                addi $8, $zero, 7   # $8 = 7
                div $11, $8
                # quotient stored in lo
                mflo $9           # $9 = quotient
                # remainder stored in hi
                mfhi $8           # $8 = remainder
                # store values to memory
                sw $9, 8($10)       # answer = quotient
                sw $8, 12($10)       # remainder = remainder value
              
                # print string
                addi $a0, $10, 16
                addi $v0, $zero, 4
                syscall
                # print answer
                lw $a0, 8($10)
                addi $v0, $zero, 1
                syscall
                # print string
                # calculate next string address
                # string is 9 character long each character stores 1 byte
                # 16 + 9 = 25,
                # address at $10 + 25
                addi $a0, $10, 25
                addi $v0, $zero, 4
                syscall
                # print remainder
                lw $a0, 12($10)
                addi $v0, $zero, 1
                syscall
                # end program
                addi $v0, $zero, 10
                syscall


let me know if you have any problem or doubts. thank you.

Add a comment
Know the answer?
Add Answer to:
Write a program to evaluate the arithmetic expression: (25xy - 10x - 6y + 28)/7 Use...
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
  • Euclid’s Elements (300 BC) shows that the greatest common divisor of two integers does not change...

    Euclid’s Elements (300 BC) shows that the greatest common divisor of two integers does not change if the smaller is subtracted from the larger. Write a program (in MIPS assembly) that implements this algorithm to find the GCD of two integers. Follow this algorithm: 1. Call the two integers a and b. 2. If a and b are equal: stop: a is the GCD. 3. Subtract the smaller from the larger. Replace the larger with the result 4. Repeat steps...

  • 2. (a) Briefly describe the compiler-based register optimization technique (typically (4 marks) (b) Describe the delayed branch technique and explain why it is more common in (4 marks) tetch, ind...

    2. (a) Briefly describe the compiler-based register optimization technique (typically (4 marks) (b) Describe the delayed branch technique and explain why it is more common in (4 marks) tetch, indirect and moon used for RISC machines). (c) Show the pipeline activity for the following code fragment with and without applying the delayed branch technique. Assume that there are three pipeline stages (fetch-decode, address calculation, data movement) for load and store RISC machines than in superscalar processors. instructions and two stages...

  • A program that executes 12.3x107 instructions is run on a pipelined processor. The table below provides...

    A program that executes 12.3x107 instructions is run on a pipelined processor. The table below provides the percentage of executed instructions for each type of instruction. Instruction Executed P ipeline CPU type instructions (%) w/o hazards ALU 29.4 Load 29.7 Store 14.7 Branch 26.2 2 (w/o prediction) 27% of the load instructions are followed by instructions that need the data being loaded, 47% of the branches are actually.not taken, please assume not taken prediction. a) Please determine the overall cycles...

  • Question#1 Write a short program demonstrating that the INC and DEC instructions do not affect the...

    Question#1 Write a short program demonstrating that the INC and DEC instructions do not affect the Carry flag. Question#2 Write a program that uses addition and subtraction to set and clear the Overflow flag. After each addition or subtraction, insert the call DumpRegs statement to display the registers and flags. Make sure to include an ADD instruction that sets both the Carry and Overflow flags. Using comments, explain how and why the Overflow flag was affected by each instruction. Question#3...

  • [Arithmetic Expression] Write a program that computes y from the following arithmetic expression:             y =...

    [Arithmetic Expression] Write a program that computes y from the following arithmetic expression:             y = mx + c. Use all values as signed words which are stored as variables in the memory. Show your results for different values of m, x and c. please answer in assembly

  • computer analysis

    Questions1.  The function L is defined as L(1) = 2,L(2) = 1,L(3) = 3,L(4) = 4 and for n ≥ 4,L(n + 1) = L(n) + L(n − 1) + L(n − 2)L(n − 3)i.e., the (n + 1)-th value is given by the sum of the n-th, n − 1-th and n − 2-th values divided by the n − 3-th value.(a)  Write an assembly program for computing the k-th value L(k), where k is an integer bigger than...

  • The Fibonacci sequence F is defined as F(1) = F(2) = 1 and for n>= 2,...

    The Fibonacci sequence F is defined as F(1) = F(2) = 1 and for n>= 2, F(n + 1) = F(n) + F(n − 1) i.e., the (n + 1)th value is given by the sum of the nth value and the (n − 1)th value. 1. Write an assembly program typical of RISC machines for computing the kth value F(k), where k is a natural number greater than 2 loaded from a memory location M, and storing the result...

  • 1.) a.) Using the simplified instruction set shown for part b, write code for the following....

    1.) a.) Using the simplified instruction set shown for part b, write code for the following. Suppose memory locations 1400 to 1449 contain 16-bit words. Each word represents 2 ASCII characters. Write code to read in and write out these 100 characters. Left-side character from location 1400 should be first, right-side character from location 1400 should be second, and remaining characters follow in numeric order. Assume you have access to 4 registers: R1, R2, R3, R4. Each register holds one...

  • Group Project 1 The Micro-1 Processor Simulation <Micro-1 Computer> Here's the organization of a computer equipped...

    Group Project 1 The Micro-1 Processor Simulation <Micro-1 Computer> Here's the organization of a computer equipped with a Micro-1 processor Memory contains an array of integer cells: int cell[] = new int[CAP]; where CAP is the capacity of memory. Initially this is set to 256. Internally, the Micro-1 processor is equipped with eight 32-bit data/address registers and two 32 bit control registers: PC, the program counter, contains the address of the next instruction to execute. IR, the instruction register, contains...

  • Create a program that performs the following operations: 1. Prompt for and accept a string of...

    Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....

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