Computer Organization and Structure


Homework #2

Due: 2009/10/27


Please write the following three programs in MIPS assembly language.


1.      Triangle Area (30%):
We will give you three 2D points (x1,y1,x2,y2,x3,y3), and your job is to calculate the area between this three points.


Your output should look like this.


----Triangle Area----

Please type 6 integers, x1,y1,x2,y2,x3,y3, and each with the Enter key:







The area is [the area]


2.      Greatest Common Divisor (35%):
We will give you two integers, and your job is to calculate the greatest common divisor. The algorithm described below is Euclidean Algorithm, which is an efficient method for computing the greatest common divisor.


function gcd (a,b)

    if a = 0

        return b

    while b != 0

    if a > b

        a := a – b


        b := b – a

    return a


Your output should look like this


----Greatest Common Divisor----

Enter the first number: 45

Enter the second number: 9

The G.C.D. is 9



3.      Goldbach’s conjecture (35%):
Goldbach's conjecture
is one of the oldest unsolved problems in number theory. It states:

Every even integer greater than 2 can be written as the sum of two primes. Expressing a given even number as a sum of two primes is called a Goldbach partition of the number. For example,

4 = 2 + 2
6 = 3 + 3
8 = 3 + 5
10 = 3 + 7 = 5 + 5 ...


We will give you an even number greater than 2, and your job is to find two primes, where their sum equals to the even number.


Your output should look like this


----Goldbach’s Conjecture----

Please type an even number, which is greater than 2: 10

The answer is/are:

3 + 7