This exercise is mostly more of the same of exercise #4. Convert the
files to X86_64 assembly code. Once again to do this I recommend copying
.c file to the
.s file and begin converting the code line by line.
It is not recommended that you use the syscall registers:
r11) for your main program except for system calls, use
r15. Preferably use memory for variable storage.
The "command line parameters" to your assembly program are placed on the stack for you by the kernel. They are located immediately before where the stack register (
rsp) points to. The first parameter is "
argc", the value of which would be at
argvis then "above" that location, each pointer is 8 bytes, thus
[rsp+16], etc. If the value at
[rsp+n*8]== 0, then you are at the end of the arguments list.
To access the first character of
argv, placing it in
r15would then require:
mov r14, [rsp+16] ; loads address of argv into r14. Remember that ; argv is a pointer (i.e. an address) to the ; string, it must still be de-referenced. mov r15, BYTE [r14] ; Move the byte at the address in r14 into r15.
Refer to exercise #4 for the
argv.s code to access the command line
Furthermore the library is in its own sub-directory, so use 'lib/lib.h' as path to the header file in your .s files if you wish to use the library and its functions in your program.