This assignment gives practice writing x86_64 assembly code that:
- uses register-based calling conventions
- interacts with C-language I/O routines
- works with arrays of integers and of strings
- uses an x86 function
In completing this assignment you MAY use/access the following resources:
You may NOT use/access:
- Resources not expressly listed above, including, but not limited to,
the following ...
- Source code not provided as part of this assignment. (Obviously, this
includes, but is not limited to, source code written by other students
whether current or in the past).
- Code-generating tools (of which ChatGPT is one of many examples).
- Any web sites not directly linked to from the homework assignment.
Failure to abide by these guidelines will result in a zero for the assignment
and the incident will be reported to the university provost as a violation of
the university academic integrity policy. A second incident of academic
dishonesty (whether from this course or another computer science course) will
result in an F in the course.
In this assignment you will work with the names.txt data file provided in
the data directory of the homework repository. You may find it helpful to
use your finished array_str.asm program as a starting point. Your work
should be done in the hw09 directory.
The program will read the names from the data file into an array of strings.
Then you will display the following information:
- the name of the input file used
- the number of names in the file
- the index in the array of the longest name
- the longest name
The purpose of the program is to learn how to write functions in assembly and
how to interface with a high-level language. For that reason your solution
must follow these additional guidelines:
- Call the C-language function readStrings provided in
in the repository. That function requires two parameters: the address of
the array of names and the address of the name of the file to be read. The
function will fill the array with the file contents and will return the
number of entries read from the file. The function assumes that you will
be leaving 27 characters (26 + null terminator) for each name, so you'll
need to use that size when traversing the array in your program.
- Write (and utilize) an assembly language function called strlen
that accepts the address of a null-terminated string as a parameter and
returns the length of the string.
- Write (and utilize) an assembly language function called findLongPos
that given an array of names as a parameter along with the number of names,
finds and returns the index of the longest name in the array. This function
should call your strlen function.
- Both of your assembly language functions should utilize a register-based
calling convention with caller-saved registers. That is, pass parameters
using the standard register sequence and don't worry about saving the state
of registers in the function. If you want to preserve values of registers
you can do that before and after calling the function.
- Your functions should not directly reference any labels that contain
memory.
To compile and run code from multiple sources:
nasm -f elf64 myprog.asm
gcc -c readstrings.c
gcc myprog.o readstrings.o
./a.out
Your program will be graded according to the following criteria:
| Correctness/Completeness |
20 |
pts |
| Documentation |
2 |
pts |
| x86 Conventions |
2 |
pts |
| Total |
24 |
pts |
See Homework #6 for instructions on proper documentation and on x86 assembly
language conventions.