Computer Architecture, First Course
Assembly 1
This assignment is mandatory and must be satisfactory solved to get credits for the course.
Before You Begin!
We strongly recommend to start with the following "Getting Started" exercises:
Examination
All source code must be well commented and well structured. There will be an oral examination/presentation of the assignment to the teacher(s). All participants in a group (one or two students) must be able to explain how the program works and how parameters are transferred from the main function to the subroutines. You should also be able to explain how the register windows and the stack work. Bring printout of your code to the examination, and make sure there is a working, compiled/assembled, version of your solution in your home account on the department computer system. In case two students work together, both must be able to demonstrate and run the program.
NOTE: You will also get questions about general assembly programming at the examination. For example: What happens with the local registers when the CPU performs a save operation?
Part I: Adding Numbers
Purpose
The purpose of this assignment is to gain understanding of how the stack works and is maintained on the SPARC, and how to write subroutines and manage register windows.
Background
It is common to transfer parameters to functions and procedures using the computer registers and stack. Most computer architectures have a policy how to do this. Compilers generate code according to this policy and assembly code should be written to comply with this policy, since it simplifies linking between different modules and libraries. It also makes the code easier to read and understand. In this assignment, both register and stack transfer of parameters will be explored.
NOTE: The subroutines must be self-contained and must not jump into other code. They must be called by the call operation and return according to the SPARC convention.
Assignment
Write a subroutine that adds a vector of integers. The subroutine takes the length of the vector and the vector itself as input parameters. The subroutine should return the sum of the numbers in the vector. Then write a main function that calls the add function with ten parameters.
An example program may begin like this. The total number of integers to add is stored at the label "length", the vector is stored at the label "vector", and the result should be written at the label "result" before the main function returns. Observe that the subroutine must not use any of these labels directly. The main function may assume that the length is a constant.
.data length: .word 10 vector: .word 1,23,12,4,5,67,7,13,98,5 result: .skip 4 .text .globl main main:
Make two versions of the program:
- Version 1:
-
- Use "call by value", i.e., send a copy of each element in the vector to the subroutine. The length of the vector is larger than the number of registers available for transferring parameters, so you must use the stack. Follow the SPARC calling conventions. Also, write a main function that calls the subroutine.
- Version 2:
-
- Transfer the length of the vector and a pointer to the first parameter. Note that this is not call by value. What is it? Put the two parameters in registers.
Part II: A Calculator
Purpose
The assignments purpose is to practice assembly programming and give an introduction in using system/library calls for I/O.
Assignment
Write a simple calculator. The program should ask the user for a string of the form integer+integer, parse the string and check syntax, perform the addition, and print out the result. Your program does not need to handle integer overflow, but must be able to detect any kind of syntax error (see below for the example run).
An important part of the task is to parse the string and convert it to and from ASCII. Here, you can reuse some of the work from exercise 2.
The program must be well structured, function calls must follow the SPARC calling convention, and you must have at least two subroutines in your program. The subroutines must perform well defined tasks, for example integer to ASCII conversion, and must not access global variables. You may (should in case of strings) use "call by reference".
Write a comment in the source code for each subroutine that describes its function, and in and out parameters.
You should write this program in two versions: one that runs on the simulator, and one that runs on a real SPARC workstation/server.
Example runs of the simple calculator
The program must handle all these cases correctly.
Example 1
Give addition: 589+485 The sum is: 589+485=1074 Do you want to make another addition? (y/n)
Example 2
Give addition: 10000+4 The sum is: 10000+4=10004 Do you want to make another addition? (y/n)
Example 3
Give addition: hej+hopp Error! Do you want to make another addition? (y/n)
Example 4
Give addition: +563 Error! Do you want to make another addition? (y/n)
Example 5
Give an addition: 123+ Error! Do you want to make another addition? (y/n)
Part III: Test Your Calculator
You must include a short (1/2 - 1 page, or more if you include test runs) description of how you tested your program. Describe the method you used, how you came up with test cases, etc. Report any bugs you found and how/if you fixed them. Did you find any unforeseen limitation in the calculator? Document limitations and problems. You are encouraged to work with another group when you do this part of the assignment. Swap programs with another group and test each other's programs. However, both groups must hand in their own test report. Please state in your test report if you have tested your own or another group's calculator.