i'd like to make a program in assembly which shows the n-th word in a given string for example we run a program
./program 3 'ax ab cd fg'
and we should get
cd
as a result
here is my code
.intel_syntax noprefix
.text
.globl main
.data
m1 db '' , 0
main:
// compile: gcc prog.s -o prog -m32 -nostdlib
// 0 to eax, ebx
mov eax, 0
mov ebx, 0
// run ./programm 3 'ax ab cd fg'
mov eax , [esp+8] // "argv[1]" -> 3
mov ebx, [esp+12] // "argv[2]" -> 'ax ab cd fg'
cld
search:
// load to AL bite from ESI
lodsb
// check end of string (char '\0')
cmp AL, 0
// if yes -> out
je out
// check if number of spaces == 1?
cmp eax, 1
je nthWord
cmp al, ' '
je space
lodsb // load next bit
jmp search
space:
dec eax // dec number of spaces
jmp search // go back to search
nthWord:
//copy chars to m1
//and show var m1 at the console
out:
unfortunately i don't know how to copy chars to a variable m1 and show it and the end