; ; echo a string on the command line ; section .data space: db ' ' newline: db 10 section .text global _start _start: ; initialize registers xor eax, eax xor ebx, ebx xor ecx, ecx xor edx, edx ; get argc (exclude argv[0]) pop edi dec edi pop esi loop_argv: ; enough arguments? cmp edi, 0 jle term ; get argv[i] pop esi xor ebx, ebx loop_len: ; find the length mov al, byte [esi] cmp al, 0 je cont_argv inc ebx inc esi jmp loop_len cont_argv: ; point to the beginning of the string sub esi, ebx ; print argv[i] mov edx, ebx mov ecx, esi mov ebx, 1 mov eax, 4 int 0x80 ; print a space mov edx, 1 mov ecx, space mov eax, 4 int 0x80 dec edi jmp loop_argv term: ; print a newline mov edx, 1 mov ecx, newline mov ebx, 1 mov eax, 4 int 0x80 ; exit(0) mov ebx, 0 mov eax, 1 int 0x80