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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:28:24+00:00 2026-05-18T22:28:24+00:00

I’ve written a small assembly snippet (Gas, 32 bit) that takes a command-line argument,

  • 0

I’ve written a small assembly snippet (Gas, 32 bit) that takes a command-line argument, counts its characters and prints the string if it has a certain length (just for debugging purposes). I’m relatively new to assembly, so I’m pretty sure there is something I miss here because I get different behaviour when I store the string in eax compared to, for instance, ecx, edx or esi.

Here is the snippet. When you replace esi with eax, the loop is entered only twice no matter how long the string is, hence the counter (ebx) is always 1. With esi or other registers, everything seems to work fine.

.section .text
.globl _start
_start:
    movl    %esp, %ebp
    movl    0(%ebp), %eax   # get argc
    cmpl    $2, %eax        # ensure argc == 2
    jne     _exit           
    movl    8(%ebp), %eax   # get argv[1]
    movl    $0, %ebx        # set counter to 0
_begin_loop:
    movb    (%eax), %al     # load a character into %al
    cmpb    $0, %al         # see if \0 is reached
    je      _end_loop       # exit loop if at end of string
    incl    %ebc            # increment counter
    incl    %eax            # advance string
    jmp     _begin_loop
_end_loop:
    cmpl    $6, %ebx        # print the string if it's six characters long
    jne     _exit
    movl    $4, %eax        # prepare for output
    movl    $1, %ebx
    movl    8(%ebp), %ecx)
    movl    $6, %edx
    int     0x80
_exit:
    movl    $1, %eax
    movl    $0, %ebx
    int     0x80

Can anybody give me a hint about what I’m doing wrong/misunderstanding?

Greets

  • 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-18T22:28:25+00:00Added an answer on May 18, 2026 at 10:28 pm

    The al register is really the lowest 8 bits of the eax register. So, the instruction movb (%eax), %al destroys the lowest 8 bits of eax, that is your pointer.

    As a general advice, learn to use a debugger to step through your code and spot where the computer does something different from what you expect.

    EDIT: there are some trivial syntax errors in the posted code (such as ebc instead of ebx), but I assume some copying error since you say otherwise it works.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

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.