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 7809733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:31:53+00:00 2026-06-02T03:31:53+00:00

Im currently trying to get used to assembler and I have written a for

  • 0

Im currently trying to get used to assembler and I have written a for loop in c++ and then I have looked at it in disassembly. I was wondering if anyone could explain to me what each step does and/or how to improve the loop manually.

for (int i = 0; i < length; i++){
     013A17AE  mov         dword ptr [i],0  
     013A17B5  jmp         encrypt_chars+30h (13A17C0h)  
     013A17B7  mov         eax,dword ptr [i]  
     013A17BA  add         eax,1  
     013A17BD  mov         dword ptr [i],eax  
     013A17C0  mov         eax,dword ptr [i]  
     013A17C3  cmp         eax,dword ptr [length]  
     013A17C6  jge         encrypt_chars+6Bh (13A17FBh)  
temp_char = OChars [i];         // get next char from original string
     013A17C8  mov         eax,dword ptr [i]  
     013A17CB  mov         cl,byte ptr OChars (13AB138h)[eax]  
     013A17D1  mov         byte ptr [temp_char],cl  

Thanks in advance.

  • 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-06-02T03:31:54+00:00Added an answer on June 2, 2026 at 3:31 am

    First, I’d note that what you’ve posted seems to contain only part of the loop body. Second, it looks like you compiled with all optimization turned off — when/if you turn on optimization, don’t be surprised if the result looks rather different.

    That said, let’s look at the code line-by-line:

     013A17AE mov dword ptr [i],0
    

    This is basically just i=0.

     013A17B5 jmp encrypt_chars+30h (13A17C0h)
    

    This is going to the beginning of the loop. Although it’s common to put the test at the top of a loop in most higher level languages, that’s not always the case in assembly language.

     013A17B7 mov eax,dword ptr [i]
     013A17BA add eax,1
     013A17BD mov dword ptr [i],eax
    

    This is i++ in (extremely sub-optimal) assembly language. It’s retrieving the current value of i, adding one to it, then storing the result back into i.

     013A17C0 mov eax,dword ptr [i]
     013A17C3 cmp eax,dword ptr [length]
     013A17C6 jge encrypt_chars+6Bh (13A17FBh) 
    

    This is basically if (i==length) /* skip forward to some code you haven't shown */ It’s retrieving the value of i and comparing it to the value of length, the jumping somewhere if i was greater than or equal to length.

    If you were writing this in assembly language by hand, you’d normally use something like xor eax, eax (or sub eax, eax) to zero a register. In most cases, you’d start from the maximum and count down to zero if possible (avoids a comparison in the loop). You certainly wouldn’t store a value into a variable, then immediately retrieve it back out (in fairness, a compiler probably won’t do that either, if you turn on optimization).

    Applying that, and moving the “variables” into registers, we’d end up with something on this general order:

        mov ecx, length
    loop_top:
        ; stuff that wasn't pasted goes here
        dec ecx
        jnz loop_top
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get disk space in byte en used space in byte
I'm currently trying to get the output of an executable console-app into an other
I am currently trying to get data out of a plist. It basically looks
I'm currently trying to get a grip on Android development and working my way
i am currently trying to get Input Mode Editor (IME) support working with a
I am currently trying to get my server to create a connection with a
I'm currently trying to get ActiveAdmin to work on a model of mine but
I'm currently trying to get my head around MUI, and getting some issues with
I'm currently trying to get hold of my NSMutableArray 's index depending on one
I'm currently trying to get a simple client \ server websocket demo up and

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.