Home > Blockchain >  split function in x86 asm (loop over characters of a string)
split function in x86 asm (loop over characters of a string)

Time:06-26

So, I need split a string character by character

in JavaScript it will be like this

let text = "abcde";
for (var i = 0; i < text.lenght; i  );
{
    console.log(text.charAt(i));
}

but how to do this is in NASM?

I am not an expert in assembly, but I have already tried to solve this problem for a week

CodePudding user response:

I would not precisely call it 'splitting' a string, but rather iterating over a string.

In the data section

Define your string and make it zero-terminated:

MyText db 'abcde', 0

In the code section

Establish a pointer to the beginning of the string:

    mov  esi, MyText

Read a byte from memory:

Again:
    mov  al, [esi]

Test to see if it is the terminating zero:

    test al, al

Stop the loop if it is indeed the end-of-string marker:

    jz   Done

Output the byte in AL any way you like:

    ...

Increment the pointer:

    inc  esi

Go repeat reading a byte:

    jmp  Again
Done:
  • Related