so I ma trying to solve an exercise that changes the data in the even with odd positions in a string. My input string is in RDI, RSI is my output, and the input size is in RDX. I am not sure what I am doing wrong as I get plenty of errors when I try to run.
My logic: if number of odds equals number of evens, then I need to add odd, else add even. each time I add in the output, I then verify if number of odds+evens equals the input size. If yes, then I'm finished and I need to finish, else continue.
I am pretty new to this assembly stuff so if I wrote any stupid stuff, know that I am a big noob.
example : input string "airport" -> output string "iaprrot"
mov RCX, RDX
mov RCX, 0 ; keeping track of how many odd positions have been added to the output
mov RSP, 0 ; keeping track of how many evenpositions have been added to the output
myloop:
cmp RSP, RCX
je odd
cmp RCX, RSP
jg even
ret
even:
sub RDI, 1 ; remained on odd position so need to go on the previous position
inc RSP ; increment the number of even positions i managed
mov AL, [RDI]
mov [RSI], AL ; put in the output the character from the even position
inc RSI
add RDI, 2
mov RAX, RCX
add RAX, RSP ; add number of odds with number of evens
cmp RDX, RAX ; if number of odds+evens is less then input size then repeat
jg myloop
ret
odd:
inc RDI ; go on odd position
inc RCX ; increment the number of odd position i managed
mov AL, [RDI]
mov [RSI], AL ; put in output the character from the odd position
inc RSI
mov RAX, RCX
add RAX, RSP
cmp RDX, RAX
jg myloop
ret