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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:36:29+00:00 2026-06-13T18:36:29+00:00

I am working through some simple problems for practise, and one of the problems

  • 0

I am working through some simple problems for practise, and one of the problems is to read in a number, and then output that number plus 1.

For example:

Please enter a number: 4
5

Now, with that input and output, it should be easy. But I want to make my program capable of processing multiple digit numbers. And that is where I am stumped. Because if I was given the input of 999, how could my program know to make the last 9 a 0, and add 1 to the tens column? And then, how could it know to make the number into 1000 by adding another digit?

Here is my code so far:

SECTION .data
msg        db "Please enter a number: ",0
msglen     EQU $-msg
sz         EQU 32
NUL        EQU 0
len        EQU 32

SECTION .bss
num        resb len

SECTION .text
GLOBAL _start
_start:

Msg:                             ; display the message
mov        eax, 4
mov        ebx, 1
mov        ecx, msg
mov        edx, msglen 
int        80h              

Read:                            ; read in the number
mov        eax, 3
mov        ebx, 1
mov        ecx, num
mov        edx, len
int        80h


Length:                          ; Find length of string
mov        eax, num
mov        ebx, 0
loop:
cmp        BYTE[eax], NUL
je         Set 
inc        eax
inc        ebx
jmp        loop                               

Set:                             ; set up the registers and variables
mov        ecx, num

Print:                           ; main section - prints out the number plus 1
cmp        BYTE[ecx], NUL
je         Exit 
mov        eax, 4
mov        ebx, 1
mov        edx, 1            ; NOTE- does not yet add 1 to the number
int        80h

inc        ecx
jmp        Print 

Exit:                            ; exits safely
mov        eax, 1
mov        ebx, 0
int        80h  

Could someone show me how to do this problem? I just can’t figure out the adding part. I can print out multiple digits, up to 32 bits, but the adding is just a mystery.

Thanks in advance,

Rileyh

  • 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-13T18:36:30+00:00Added an answer on June 13, 2026 at 6:36 pm

    How about using atoi() to convert it into the integers and then printf() to output the result? There are some sample codes about it:

    http://cs.lmu.edu/~ray/notes/nasmexamples/

    As for your integer-adding problem, if I were you, I’d start by tearing the problem down to “add one”. You’ll notice you’re following this algorithm there:

    1. Set the pointer to the last character in the string.
    2. Increase the character by one. If the character’s below ASCII ‘9’, return.
    3. Else, set the pointer to the previous character. If its number is not -1, jump to 2.
    4. If we’re trying to overwrite the character number -1, allocate n+1 bytes for the new string, copy the old one’s contents to a new one and add ‘1’ to as the first character.

    From this point, you’ll only need to figure out what changes if you want to add more than one digit of the input.

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

Sidebar

Related Questions

I'm working through some tutorials and examples of java.util.concurrent package. Usually example authors put
I'm working through some simple applications to get familiar with Swing and running into
I am working through a KnockOutJs Sample and am having some posting problems with
I am working through some practise problem sets for an upcoming CS exam. I
I am working though some simple DX tutorials, and have hit an early snag.
I'm working through some android tutorials right now in preparation for a two week
I'm working through some MSDN examples, and some books on ADO.Net. What they all
I'm currently working through some exercises in a c++ book, which uses text based
I am working through some examples in a WCF book. There is a Host
I'm looking through some code for learning purposes. I'm working through this portion of

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.