bitcount.c file to X86_64 assembly code. To do this I recommend
bitcount.c file as
bitcount.s 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.
argv.s contain example code for accessing the arguments (and
environment) in assembly and the file
lib.s contains a number of assembly
routines that argv.s uses and that you may find useful for completing this