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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:17:49+00:00 2026-06-12T22:17:49+00:00

I am writing a program to print out all the numbers from 0 to

  • 0

I am writing a program to print out all the numbers from 0 to 100, and I need to find the number of digits a variable(in this case the variable counter) holds.

Here is my code:

SECTION .data
len EQU 32

SECTION .bss
counter resd len 
digit1 resd len
digit2 resd len
digit3 resd len

SECTION .text
GLOBAL _start
_start:
nop

Print:
mov eax, 4
mov ebx, 1
mov ecx, counter
mov edx, len
int 80h 

Set:
mov BYTE [counter], 1

Divide:
; HERE IS WHERE I NEED TO FIND THE LENGTH OF THE VARIABLE COUNTER
; initial division
mov ax, [counter]   ; number we want to print
mov ch, 10    ; we divide by ten to siphon digits
div ch        ; divide our number by 10

; al now has 11, ah has 1
mov dh, ah             ; save the remainder in dh
xor ah,ah
mov ch, 10             ; refill ch with the divisor
div ch                 ; al now has 1, ah now has 1

Move:                     ; now to move our digits to a printable state
mov [digit1], dh      ; first digit is in edx
mov [digit2], ah
mov [digit3], al

Adjust:
add BYTE [digit1], '0'
add BYTE [digit2], '0'
add BYTE [digit3], '0'

Print:
mov eax, 4
mov ebx, 1
mov ecx, digit1
mov edx, len
int 80h

mov eax, 4
mov ebx, 1
mov ecx, digit2
mov edx, len
int 80h

mov eax, 4
mov ebx, 1
mov ecx, digit3
mov edx, len
int 80h

Exit:
mov eax, 1
mov ebx, 0
int 80h

I need to find the length so that I know how many times to divide and also how many digits to print the variable counter.

How can I find how long it is?

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-12T22:17:51+00:00Added an answer on June 12, 2026 at 10:17 pm

    For numbers in the range 0..100, I’d just compare at the boundaries, with pseudo-assembler like:

        mov ax, [counter]
    
        mov cx, 3             ; default length
        cmp ax, 100           ; >= 100, use 3
        bge done
    
        dec cx                ; set length to 2
        cmp val, 10           ; >= 10, use 2
        bge done
    
        dec cx                ; set length to 1
    
    done:
                              ; cx now holds the digit count.
    

    That will actually handle up to 999 but you could also add more condition checks before the 100 one if you wanted to expand the range.

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

Sidebar

Related Questions

I am writing this java program to find all the prime numbers up to
Everything was working fine in this program I've been writing, and then out of
I am writing a program to scrape a monster.com job search and print out
The name kind of says it all. I'm writing this program in python 2.7,
I'm writing a program that for one part asks for the program to print
I'm writing a program that needs to print off high resolution .tiff images. The
I'm writing a program where I want the cursor to print letters on the
So I'm writing a program to test the endianess of a machine and print
I am writing a program to get an integer from the user, and then
I'm writing a program to input a number and draw that number of circles

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.