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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:25:18+00:00 2026-06-11T18:25:18+00:00

My program is written in C++ with some x86 assembly language being embedded into

  • 0

My program is written in C++ with some x86 assembly language being embedded into it. I have 2 nested for-loops in assembly language that I must go through. However, however when I compile my program, I get an infinite loop. The equivalent program in C++ would look something like this:

#include<iostream>
using namespace std;
int main()
{
    int a[4] = {3,6,4,7};

    for(int k = 0 ; k < 4;k++)
    {
        for(int l = 0 ; l < a[k];l++)
        {
            cout<<'*';
        }
        cout<<endl;
    }

    system("pause");
    return 0;
}

 /*

  *** 
  ******
  ****
  *******
  Press any key to continue . . .
  */

This is the same thing, but done with assembly mixed in.

#include<iostream>
using namespace std;
void output(); //function for making an '*'
void makeSpace(); //function for making a space

int main()
{
    int a[4]={3,6,4,7};

    int counter = 0; //counter that will be used for first forloop
    int counter2 = 0; // counter to be used for second forloop

_asm{

    mov ebx,0 // this is to move from element 0,1,2,3,4, through the array
    mov ecx,0 // ecx will get the data from the array, only to be used as a
              // counter in forloop2 though.

     for1:

    cmp counter,4 //begins for firloop

    je starts 
    mov ecx,[a+ebx] // move the 0th element from array to ecx
    add ebx,4// ebx = ebx+4, I'm doing this to advance the array position (int)
    inc counter// increment counter by one

      for2:
    cmp counter2,ecx //begin forloop2, 
    je starts2
    call output
    inc counter2 //increment counter2 by one

    jmp for2 
      starts2:

    call makeSpace
    jmp for1
      starts:
}

    return 0;
}

void output()
{
    cout<<'*';
    }

void makeSpace()
{
    cout<<endl;
}

Why does this result in an infinite 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-06-11T18:25:19+00:00Added an answer on June 11, 2026 at 6:25 pm

    There are at least two things you need to fix:

    • When you call output() only the following registers are guaranteed to not be trashed:

      • edi, esi, ebx, and ebp

      In particular, you’re using ecx, which the function is permitted to trash.

    • You never reset counter2 to 0, so the inner loop isn’t equivalent to your C code.

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

Sidebar

Related Questions

I've inherited a 10K-line program written in 8051 assembly language that requires some changes.
I have a program written in C# that serializes data into binary and write
I have written some sample program and DLL to learn the concept of DLL
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
In a .NET program that's written to follow declarative style, what are some legitimate
i have a problem. Some sql in my program could be written by the
i have planned to develop a tool that converts a program written in a
I have written some simple and working assembly code on 8085 trainer hardware. But
I have seen that some programs which were written by me and assembled for
We have a program written in VB6 that in the past connected to Oracle

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.