`
bits 64
default rel
section .data
fmt db “%s”, 0xd, 0xa, 0
err db “Correct usage: echo “
section .text
extern printf
extern ExitProcess
global main
main:
;Set up stack
push rbp
mov rbp, rsp
sub rsp, 32
;Save cli args in r11 and r12
mov r11, rcx ;argc
mov r12, rdx ;argv
cmp r11, 2
jl .wrong_num_of_args_error
mov rbx, 1
;Loop through argv
.loop:
cmp rbx, r11
je .end
mov rdx, [r12 + rbx * 8]
mov rcx, fmt
call printf
inc rbx
cmp rbx, r11
jl .loop
jmp .end
;Exit
.end:
xor rax, rax
call ExitProcess
.wrong_num_of_args_error:
;Prepare to call printf
mov rcx, err
call printf
;Exit
xor rax, rax
call ExitProcess`
The loop in this code runs for too long. I tried many ways but I can’t get it to work. The logic looks sound too. I’m using x64 asm with win64calling convention
I tried decrementing r11 (the argc), mov rbx, 2 (rbx is the counter)
I got all the args I passed to it and two (null)s
New contributor
Angad Warhadpande is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.