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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:01:41+00:00 2026-06-15T15:01:41+00:00

So I’m fairly new to Assembly language I have a pretty solid grasp on

  • 0

So I’m fairly new to Assembly language I have a pretty solid grasp on the fundamentals but user input has always baffled me. So right now I have the following code to receive a single digit from the user:

mov eax, 3
mov ebx, 0
mov ecx, inStrBuf
mov edx, StrLen
int 80h

And then the definitions are as follows

SECTION .bss
inStrBuf:  times StrLen resb  ' ' 

Section .data
StrLen: equ 8 

After I put the value in ecx, the value is the digit + 2608. So what I have been doing is simply subtracting 2608 and getting the digit. Now when I put in more than one digit, like the number 46, I get, when I convert to decimal, 669236. There is no simple way of just subtracting 2608 like I was before.

First of all, what’s up with the 2608, and is there any way to just accept a number like 654 and put it in a register (in a hex value of course). Thanks!

  • 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-15T15:01:42+00:00Added an answer on June 15, 2026 at 3:01 pm

    I have no idea where 2608 came from, even less 669236! The general idea is:

    ;zero out someplace to put result
    top:
    ;get a digit/character
    ;make sure it represents a decimal digit
    ;(if not - go to done)
    ;subtract '0' to convert character to number
    ;multiply "result so far" by 10
    ;add in the new number
    ;go to top
    done:
    

    This is what I usually use…

    section .bss
        inStrBuf resb StrLen ; 12+ is good...
    
    section .text
        ...
        push inStrBuf ; pass parameter on stack
        call atoi
        add esp, 4 ; clean up stack
        mov [someplace], eax
        ...
    
    ;--------------------
    atoi:
        push ebx
    
        mov edx, [esp + 8]  ; pointer to string
        xor ebx, ebx ; assume not negative
    
        cmp byte [edx], '-'
        jnz .notneg
        inc ebx ; indicate negative
        inc edx ; move past the '-'
    .notneg:
    
        xor eax, eax        ; clear "result"
    .top:
        movzx ecx, byte [edx]
        inc edx
        cmp ecx, byte '0'
        jb .done
        cmp ecx, byte '9'
        ja .done
    
        ; we have a valid character - multiply
        ; result-so-far by 10, subtract '0'
        ; from the character to convert it to
        ; a number, and add it to result.
    
        lea eax, [eax + eax * 4]
        lea eax, [eax * 2 + ecx - '0']
    
        jmp short .top
    .done:
        test ebx, ebx
        jz .notminus
        neg eax
    .notminus:
        pop ebx
        ret
    ;------------------------
    

    This uses the “clever” method of two leas to multiply by ten, subtract ‘0’, and add in the new number. It has the disadvantage of not setting flags, so we can’t check for overflow – it just silently rolls over. Any “invalid” character stops – works for xero, linefeed (which sys_read will have there)… or “garbage”. When it returns, the “invalid” character will be in ecx (just cl is interesting), and edx points to the next character. Handy for parsing “192.168.1.1” or so. You may prefer to use something more straightforward. 🙂 The C library “atoi” or “scanf” work… if ya wanna do it THAT way…

    Really curious where that 2608 came from!

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

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.