Hello, I'm new on assembly and am having problems with a program I am trying to create. The program is supposed to display the number of arguments given by the user and each of the arguments the user entered. It should also display a message when no argument is given (By not counting the program invoking statement as an argument). I am having trouble figuring out how to loop the arguments so that the program will display all of the arguments no matter how many is given by the user. Does anyone know how I can solve this problem? Thanks!
Here is the code:
%include "CPsub64.inc"
global main ;entry point for assembly
extern puts
section .text
main:
push rdi ;save to stack
push rsi ;save to stack
;show # of arguments
mov rax, rdi
call WriteDec
;put blank line
mov rdi, blankline
call puts
;if more than 1 argument is given then jump to great
mov rcx, 1
cmp rcx, rdi
jg great
jmp less
;return original values
pop rsi
pop rdi
great:
loop:
;show items
push rdi ;save to stack
push rsi
sub rsp, 8 ;align stack boundary
add rsi, 8 ;move address to next item
mov rdi, [rsi] ;argument from command line
call puts
cmp rsi, rdi
jne loop
add rsp, 8 ;realign boundary
pop rsi ;restore registers
pop rdi
jmp skip
less:
pop rsi
pop rdi
;display noarg message
mov rax, 1
mov rsi, noarg
mov rdx, noarglength
syscall
jmp end
skip:
end:
;display end message
mov rax, 1
mov rsi, endmessage
mov rdx, endmessagelength
syscall
ret ;close C functions
section .data
blankline: db " ",0
noarg: db 'No arguments found.',0,0ah
noarglength: equ ($-noarg)
endmessage: db 'The program is completed',0,0ah
endmessagelength: equ ($-endmessage)