Department of Electrical and Computer Engineering
University of Texas at Austin
EE 306
Fall 2004
Y. N. Patt, Instructor
Siddharth Balwani, Linda Bigelow, Tommy Buell, Jeremy Carrillo, Aamir Hasan,
Danny Lynch, Rustam Miftakhutdinov, Veynu Narasiman, Vishal Parikh, Basit Sheikh, TAs
blah

Programming Assignment 3
Due: Tuesday November 2, 2004 11:59 pm

You must do the programming assignment by yourself. You are permitted to get help ONLY from the TAs and the instructor. The file you submit should be an assembly language file called triangle.asm. This is the only file you need to submit. Submission instructions are posted on the class website in the Software and Documentation section. If you are having trouble submitting, please email Danny (lynch@ece.utexas.edu) or Linda (bigelow@ece.utexas.edu).


Triangles

In this assignment, you are asked to write a program in LC-3 assembly language to determine the properties of a triangle.
Given the lengths of the three sides of the triangle you must first determine if it is possible to form a triangle with sides of these lengths.

If it is possible to form a triangle then you need to classify the triangle as follows:

Your program should start at memory location x3000 and assume that the lengths of the three sides of the triangle are stored in memory locations x3100, x3101, and x3102. You can assume that the length of each side will be a non-negative number less than #100. If you determine that the three lengths cannot be the sides of a triangle then the program should write the number #0 to memory locations x3103 and x3104, output the following, and exit:
Not a triangle

Otherwise the program should behave as follows:

  1. First the program should determine which type of triangle it is
    1. An equilateral triangle has sides that are all of equal length (for example 5, 5, and 5). In this case the program should store the number #1 in memory location x3103 and output:
      Equilateral

    2. An isosceles triangle has two sides that are equal in length (for example 5, 5, and 4). In this case the program should store the number #2 in memory location x3103 and output:
      Isosceles

    3. A scalene triangle has no sides that are the same length (for example 5, 4, and 3). In this case the program should store the number #3 in memory location x3103 and output:
      Scalene

  2. Then the program should do the following
      In the equations below c is the longest side of the triangle:
    1. The triangle is a right triangle if a2 + b2 = c2 (for example 3, 4, 5). In this case the program should store the number #1 in memory location x3104 and output:
      Right
    2. The triangle is an obtuse triangle if a2 + b2 < c2 (for example 2, 6, 7). In this case the program should store the number #2 in memory location x3104 and output:
      Obtuse

    3. The triangle is an acute triangle if a2 + b2 > c2 (for example 6, 6, 7). In this case the program should store the number #3 in memory location x3104 and output:
      Acute



Example 1:

If we have the following values in the following memory locations:
Location 
Contents (in hex) 
x3100 
x0001 
x3101 
x0005 
x3102 
x0004 

The output should be:

Not a triangle

And the following memory locations should be:
Location 
Contents (in hex) 
x3103 
x0000 
x3104 
x0000 

Example 2:

If we have the following values in the following memory locations:
Location 
Contents (in hex) 
x3100 
x0003 
x3101 
x0005 
x3102 
x0004 

The output should be:

Scalene
Right

And the following memory locations should be:
Location 
Contents (in hex) 
x3103 
x0003 
x3104 
x0001 

Hint 1: You can use the .STRINGZ pseudo-op to store strings in your program.

Hint 2: The ASCII code x0A causes the cursor to move to the next line.
 

Notes and Suggestions: