Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 499643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:00:23+00:00 2026-05-13T06:00:23+00:00

Ok here’s my problem. I want to loop through a simple char buffer using

  • 0

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
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T06:00:24+00:00Added an answer on May 13, 2026 at 6:00 am

    First, there is no EDS, only DS. Even in 32-bit mode, the segment registers remain 16 bits.

    Second, unless you’re working on an ancient system like a DOS extender, or something really unusual (a lot different from a typical desktop/server OS like Windows, Linux, OS/X, BSD, etc.) you shouldn’t modify any segment registers in any case. Most current systems use a “flat” memory model, where the OS sets up all1 the segment registers with a base of 0 and a limit of the top of memory, so you never have any reason to modify any of them at all.

    Unfortunately, while it’s easy to say your code is wrong, it’s a bit harder to say what would be right — you haven’t said enough about what you want to do. Right now, it looks like you’re copying from a buffer, but each time through the loop you’re overwriting the value you wrote in the last iteration, so you might as well just copy the last word and be done. For looping through the buffer to accomplish much, you’d want to copy it to a destination buffer of the same (or larger) size:

    mov ecx, howmany
    mov esi, offset FLAT:source
    mov edi, offset FLAT:dest
    rep movsd
    

    As others have already pointed out, the operand for a loop instruction is a label, not a register. What they don’t seem to have pointed out is that with modern CPUs (anything newer than the original Pentium) you usually want to avoid using the LOOP instruction at all. Just for the sake of argument, however, a loop to do the move like above would look like:

        mov ecx, howmany
        mov esi, offset FLAT:source
        mov edi, offset FLAT:dest
    move_loop:
        lodsd
        stosd
        loop move_loop
    

    For a modern CPU, it’s usually better to use more, but simpler, instructions.

    ; same setup as above
    move_loop:
        mov eax, [esi]
        mov [edi], eax
        inc esi
        inc edi
        dec ecx
        jnz move_loop
    

    The other side of things is that in this case, it’s unlikely to matter — unless it all fits in cache, a block move like this will almost always be limited by the memory bandwidth — moves don’t get much faster, but to get the last little bit of improvement, you want to use SSE instructions/registers.

    Edit: One last detail. VC++ (among others) won’t let you define a label inside an _asm block, so if you need a label, you do something like:

    _asm {
        mov ecx, howmany
        mov esi, offset FLAT:source
        mov edi, offset FLAT:dest
    }
    
    move_loop:
    
    _asm {
        lodsd
        stosd
        loop move_loop
    }
    

    1Well, not all — FS and possibly GS won’t be this way, but CS, DS, ES and SS will be. You don’t want to change any of them anyway (in fact, attempting to do so will normally just get your program shut down).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 291k
  • Answers 291k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I would like to have a user redirected to an… May 13, 2026 at 5:58 pm
  • Editorial Team
    Editorial Team added an answer Assuming you mean that's a CRLF sequence in the text… May 13, 2026 at 5:58 pm
  • Editorial Team
    Editorial Team added an answer There's actually a declarative way of doing this. In your… May 13, 2026 at 5:58 pm

Related Questions

Ok Here is the exact scenario: I have a view named Index I have
Ok here's what I'm trying to do I want to write a class that
Ok here's a little problem I would love to get some help on. I
ok here is my code: var xml:XML = <xml> <typeA amount1=500 amount2=300 amount3=250 date=2008-02-17/>
Ok here is the deal i am building a messaging system by php,ajax,jquery and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.