0% found this document useful (0 votes)
13 views3 pages

Lab 5

lab5 part of the cs 382 course offered at Stevens Institute of Technology.

Uploaded by

nilanjan.n.03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Lab 5

lab5 part of the cs 382 course offered at Stevens Institute of Technology.

Uploaded by

nilanjan.n.03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 382 Computer Architecture

Fall 2024 and Organization Lab 5


1 Task 1: Simple Conditionals
The first task of this lab is to write a program that check that if the given three sides can form a right triangle. A
right triangle is the one that has an angle of 90 degrees, and can be verified by the following formula:

𝑐 2 = 𝑎2 + 𝑏 2
where 𝑎, 𝑏, and 𝑐 are the lengths of three sides of the triangle.

The data segment is declared as follows:

1 .data
2 side_a: .quad 3
3 side_b: .quad 4
4 side_c: .quad 5
5 yes: .string "It is a right triangle.\n"
6 len_yes: .quad . - yes // Calculate the length of string yes
7 no: .string "It is not a right triangle.\n"
8 len_no: .quad . - no // Calculate the length of string no

where you can assume side_c is always the longest side. If it is a right triangle, you’d need to print the string
"It is a right triangle.\n " ; otherwise "It is not a right triangle.\n " .

To print a string, you might want to review and borrow the code from lab 2.

Requirements

 Note your code is a complete assembly program (not just a sequence of instructions). It should be able
to assemble, link, and execute without error and warnings. When executed, the program should finish
without problems. If your code cannot assemble, you get no credit – this is the same as C programs that
cannot be compiled;
 MUL instruction can be used for multiplications;
 You can use either CBZ / CBNZ or B.EQ / B.NE for branching;
 Avoid using registers X29 and X30;
 You have to put comments on each line of instruction;
 Put your name and honor code pledge at the top of your code in comments.

2 Task 2: More Conditionals


This task is to get familiar with other conditional branching instructions such as B.LE . You are given the starter
code as follows (it can also be downloaded from Canvas):

1 .text
2 .global _start
3 .extern scanf

1
4

5 _start:
6 ADR X0, fmt_str // Load address of formated string
7 ADR X1, left // Load &left
8 ADR X2, right // Load &right
9 ADR X3, target // Load &target
10 BL scanf // scanf("%ld %ld %ld", &left, &right, &target);
11

12 ADR X1, left // Load &left


13 LDR X1, [X1] // Store left in X1
14 ADR X2, right // Load &right
15 LDR X2, [X2] // Store right in X2
16 ADR X3, target // Load &target
17 LDR X3, [X3] // Store target in X3
18

19 /* Your code here */


20

21 exit:
22 MOV X0, 0 // Pass 0 to exit()
23 MOV X8, 93 // Move syscall number 93 (exit) to X8
24 SVC 0 // Invoke syscall
25

26 .data
27 left: .quad 0
28 right: .quad 0
29 target: .quad 0
30 fmt_str: .string "%ld%ld%ld"
31 yes: .string "Target is in range\n"
32 len_yes: .quad . - yes // Calculate the length of string yes
33 no: .string "Target is not in range\n"
34 len_no: .quad . - no // Calculate the length of string no

The code given to you calls C library function scanf() to receive three signed integers from keyboard (seperated
by space or newline). The first and second integers represent a numerical range (left,right) (exclusive),
while the third integer represents a target number. Your code should check if target is inside the range. If
so, it should print the message labeled as yes ; otherwise no . You can assume left is always smaller than
right .

Again, to print messages, you’d need to invoke system calls learned in lab 3.

Because we used C library function here, during linking, you’d need flag -lc in the command. Related infor-
mation can be found in Appendix B.2.3.3 in the textbook.

Requirements

 Note your code is a complete assembly program (not just a sequence of instructions). It should be able
to assemble, link, and execute without error and warnings. When executed, the program should finish
without problems. If your code cannot assemble, you get no credit – this is the same as C programs that
cannot be compiled;
 Your code should complete the task successfully without errors. Please do check edge cases;
 You have to put comments on each line of instruction;
 Put your name and honor code pledge at the top of your code in comments.

2
3 Grading
The lab will be graded based on a total of 10 points, 5 for task 1 and 5 for task 2. The following lists deductibles,
and the lowest score is 0 – no negative scores:

 Task 1:

• -5: the code does not assemble, or the program terminates abnormally/unsuccessfully;
• -5: the code is generated by compiler;
• -5: the code does not attempt the task;
• -5: the code cannot be explained clearly in person;
• -5: no output is printed;
• -5: not using conditionals;
• -3: the right triangle checking result is wrong;
• -1: one or more instructions is missing comments;
• -1: no pledge and/or name.

 Task 2:

• -5:
the code does not assemble, or the program terminates abnormally/unsuccessfully;
• -5:
the code is generated by compiler;
• -5:
the code does not attempt the task;
• -5:
the code cannot be explained clearly in person;
• -5:
no output is printed;
• -5:
not using conditionals;
• -1:
1 point off for each of the following test cases:
* -5 6 3 ;
* -5 10 -30 ;
* -6 -2 0 ;
* 3 4 3;
* 10 30 30 ;
* -20 20 -20 ;
• -1: one or more instructions is missing comments;
• -1: no pledge and/or name.

Earlybird Extra Credit: 2% of extra credit will be given if the lab is finished by Wednesday 11:59PM EST (1 day
before the lab deadline). For specific policy, see syllabus.

Attendance: check off at the end of the lab to get attendance credit.

Deliverable
Assembly code for both tasks in two separate .s files. No need to zip all files; just submit both files
separately on Canvas.

You might also like