inline asm buffer loop

Question!

Ok here's my problem. I want to loop through a simple char buffer using inline asm and VC++;

My agenda is to create a loop that reads information from memory as fast as physically possible

heres my code

char buffer[howmany];
memset(buffer,33,howmany);
char arr = 0;
__asm
{
MOV     eax,seg buffer ;operand size conflict
MOV     eds,eax
MOV	ecx,[howmany]
MOV     ebx,ip
MOV     arr, ES::buffer[ecx] ;operand size conflict
                             ;inline assembler syntax error in 'third operand'
                             ;found 'bad token'
LOOP    ebx ;inline assembler syntax error in 'opcode'; found 'bad token'
                ; 'LOOP' : identifier is reserved word
}

I'm pretty new with assembly, but this seems right, but it doesn't work? I'm not sure why. Thanks in advance.

Final Solution

__asm
{
    LEA         esi, buffer
    MOV      ecx,howmany
    buf_loop:   
    mov         eax, [esi]
    inc         esi
    dec         ecx
    jnz         buf_loop
}
By : kelton52


Answers

The line LOOP ebx looks suspect, aren't you supposed to specify a label to jump to?

label:
//some code
LOOP label

Also if you want to avoid looping, check out the

REP MOVS

and

REP STOS

instructions.



Is this protected mode code? If so, don't mess with EDS.

The loop instruction must give a jump destination label. Loading ebx with ip (or eip) cannot be done as ip is not a proper operand.

By : wallyk


I don't have time to write it out, but using SSE2 registers you can read 16 bytes per loop. You will have to have a byte based loop first to align though (and after)



This video can help you solving your question :)
By: admin