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

  • Home
  • SEARCH
  • 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 932615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:41:55+00:00 2026-05-15T20:41:55+00:00

I have a problem about counting the length of a string. I always get

  • 0

I have a problem about counting the length of a string.
I always get some number like 2432, thou I pass a string like “abc”.

I think the problem is in this line

mov bl, byte [esi]

but I would not know why.
Maybe it is something with character length in bits?

Could the problem be a 64bit operating system or dual core processor? (which I somehow doubt, because I think the first line “bits 32” should solve the problem).

PS.: This is an exercise, that is why I need to determine the length of the string like this.

The code:

bits 32
extern _printf
extern _scanf
global _main

section .data
number_frmt db 10,"%d",10,0
enter_str db "Enter some string: ", 10,0
string_frmt db "%s", 0

section .bss
entered_string resb 100

section .text

_main:
    pushad

    push dword enter_str
    call _printf
    add esp, 4

    push dword entered_string
    push dword string_frmt
    call _scanf
    add esp, 4  ;leave the entered string in the stack

    call count  ; count it and put the result to eax

    push dword eax
    push dword number_frmt
    call _printf
    add esp, 12

    popad
    ret

count:
    push esi    ;save it
    push ebx    ;save it
    mov eax, 0  ;init eax=0
    mov esi, [esp+12] ;put the entered string to esi

.loop:
    mov bl, byte [esi]  ;get the first char
    inc eax             ;eax++
    add esi,1           ;point to next char
    cmp bl,10           ;is it new line?
    jne .loop           ;if not loop
    dec eax             ;eax-- (because of newline at the end)
    pop ebx             ;retrieve ebx
    pop esi             ;retrieve esi
    ret
  • 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-15T20:41:56+00:00Added an answer on May 15, 2026 at 8:41 pm
    cmp bl,10           ;is it new line?
    

    should be

    cmp bl,0
    

    because c/c++ strings are everytime ended/terminated by a 0, so you have in fact searched for an random position in the memory where the next 10 is.

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

Sidebar

Related Questions

Based off this SO question about counting forgein keys , I have a problem.
I have a problem about casting a CallableStatement to OracleCallableStatement . It gives ClassCastException
I have a problem about div position relative alignment. I want the second div
I am using MFC CFile Seek function. I have a problem about Seek out
I have a little problem about the sort direction of a specific column in
I have a great problem about the rotation in three.js I want to rotate
I have a little problem about Google Maps. I'm using Geocoding (xml) for getting
I have a little problem about using jQuery (I really do not know jQuery
I have problem adding arraylist to list view, will explain about my problem here..
I have got a strange problem about in_array recently which I cannot understand. e.g.

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.