Subject Computer Science Assembly Language Programming



Write an assembly language procedure MinMax that finds the smaller and larger of two signed integers passed as arguments.
The first two arguments are the integers to be compared, passed by value. The third argument, passed by reference, returns the smaller value to the calling program. The fourth argument,
passed by reference, returns the larger value to the calling program.

The arguments must be pushed onto the stack by the calling program. The procedure must access the arguments through the stack. The procedure must save and restore any registers that it uses.

Write a main program that invokes the MinMax procedure to find the larger and smaller of 4 and -6. It must print two lines of output as shown.

The smaller number is -6.
The larger number is 4.


Write an assembly language program that uses Newton's method to compute the square root of 6. Use double-precision floating-point. Newton's method uses the formula

xnew = (xold + number / xold) / 2.0

to replace an initial estimate "xold" of the square root of "number" with an improved estimate "xnew". This formula may be applied repeatedly to obtain ever better estimates of the square
root. The process terminates when the difference between the old and new estimates is sufficiently small. Your program should use an initial estimate of 1.0 and should terminate when

abs(xnew - xold) < 1.0e-12.

Your program should print the value of "xnew" during each iteration of the loop (syscall 3 prints the double value in $f12). The output should appear as shown.


Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

Program 1

Small: .word -6
Large: .word 4
Smaller: .word 0
Larger: .word 0
msg1: .asciiz "The smaller number is "
msg2: .asciiz "The larger bumber is "
EndLine: .asciiz ".\n"


sub $sp, $sp, 20
sw $ra, 4($sp) #push $ra to stack
lw $t0, Small
sw $t0, 20($sp) #push Small to stack
lw $t0, Large
sw $t0, 16($sp) #push Large to stack
la $t0, Smaller
sw $t0, 12($sp) #push Smaller address to stack - passed by reference
la $t0, Larger
sw $t0, 8($sp) #push Larger address to stack - passed by reference
jal MinMax # call MinMax

Program 2.

error: .double 1e-12
EndLine: .asciiz "\n"

#f0 - number 6
#f2 - xold
#f4 - xnew
#f6 - error

# load 6 into $f0
li $t0, 6
mtc1.d $t0, $f0
cvt.d.w $f0, $f0

#load 0 to $f2 - xold
li $t0, 0
mtc1.d $t0, $f2
cvt.d.w $f2, $f2

#load 1 to $f1 - xnew - 1 is start estimation
li $t0, 1
mtc1.d $t0, $f4
cvt.d.w $f4, $f4

#load the error tolerance 1e-12 into $f6
l.d $f6, error

#load 2 into $f10
li $t0, 2
mtc1.d $t0, $f10
cvt.d.w $f10, $f10

sub.d $f8, $f4, $f2 #xnew - xold
abs.d $f8, $f8 #abs(xnew - xold)...

This is only a preview of the solution. Please use the purchase button to see the entire solution


or $1 if you
register a new account!

Assisting Tutor

Related Homework Solutions

Get help from a qualified tutor
Live Chats