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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:28:13+00:00 2026-05-26T05:28:13+00:00

I am working on a program – it should be simple – on a

  • 0

I am working on a program – it should be simple – on a Linux OS using NASM and x86 Intel Assembly Syntax.

The problem I am having is that I cannot create a working loop for my program:

section .data
    hello:    db 'Loop started.', 0Ah   ;string tells the user of start
    sLength:  equ $-hello               ;length of string

    notDone:  db 'Loop not finished.', 0Ah ;string to tell user of continue
    nDLength: equ $-notDone                ;length of string

    done:     db 'The loop has finished', 0Ah ;string tells user of end
    dLength:  equ $-done                      ;length of string

section .text

    global _start:
_start:
    jmp welcome         ;jump to label "welcome"

    mov ecx, 0          ;number used for loop index
    jmp loop            ;jump to label "loop"

    jmp theend          ;jump to the last label

welcome:

    mov eax, 4
    mov ebx, 1
    mov ecx, hello
    mov edx, sLength
    int 80              ;prints out the string in "hello"

loop:
    push ecx            ;put ecx on the stack so its value isn't lost

    mov eax, 4
    mov ebx, 1
    mov ecx, notDone
    mov edx, nDLength
    int 80              ;prints out that the loop isn't finished

    pop ecx             ;restore value
    add ecx, 1          ;add one to ecx's value
    cmp ecx, 10
    jl loop             ;if the value is not ten or more, repeat

theend:

;loop for printing out the "done" string

I am getting the first string printed, one “Not done” and the last string printed; I am missing nine more “Not Done”s! Does anyone have any idea as to why I am losing my value for the ecx register?

Thank you.

  • 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-26T05:28:14+00:00Added an answer on May 26, 2026 at 5:28 am
    _start:
        jmp welcome
    

    This means all the code below the JMP is not executed, especially the mov ecx,0 (which should be xor ecx,ecx for a shorter instruction)

    Don’t start with a jump, start with some code. A JMP is a jump, it’s not going back after you’ve jumped, it just continues the execution.

    So after jumping to Welcome:, you go directly to Loop:, thus missing the ecx=0 code.

    cmp ecx, 10
    jl loop
    

    ECX is not 0, it definitely is greater than 10h, so the loop is not taken.

    Try this:

    _start:
        mov eax, 4
        mov ebx, 1
        mov ecx, hello
        mov edx, sLength
        int 80              ;prints out the string in "hello"
        xor ecx,ecx         ;ecx = 0
    
    loop:
        push ecx            ;save loop index
        mov eax, 4
        mov ebx, 1
        mov ecx, notDone
        mov edx, nDLength
        int 80              ;prints out that the loop isn't finished
    
        pop ecx             ;get loop index back in ECX
        add ecx, 1          ;add one to ecx's value
        cmp ecx, 10
        jl loop             ;if the value is not ten or more, repeat
    
    theend:
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a program that has many of those the user SHOULD
I'm working on a program that is using a pipe and forks and need
I am working on a program that needs to create a multiple temporary folders
I'm working on a program that processes many requests, none of them reaching more
I'm working on a program that searches entire drives for a given file. At
I'm working on a program that uses PHP's internal array pointers to iterate along
I'm working on a program that will tell what level a programmer is at
I am working on a program that encodes a file based on a supplied
I have a working program written in Java with the Java Sound API that
I have a working program in C++ that generates data for a Mandelbrot Set.

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.