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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:49:50+00:00 2026-06-05T14:49:50+00:00

I’m trying to figure out how to use scanf to get user input. I

  • 0

I’m trying to figure out how to use scanf to get user input. I know to use printf: all I have to do is push the data I want to write on the screen into the stack like this:

global _main
extern _printf
extern _scanf

section .data
msg db "Hi", 0

section .text
_main:
  push ebp
  mov ebp, esp  

  push msg
  call _printf

  mov esp, ebp
  pop ebp
ret

But I can’t figure out how to use scanf. Can someone please just give me the simplest possible source code you can for scanf? I really just want to put what the user types in.

I’m not used to 32bit Assembly. I’ve only ever used 16bit, and I know in 16bit (DOS) you can just do this:

mov ah, 3fh
mov dx, input
int 21h

input rb 100d

And whatever you type in will the placed at the address of “input.”

  • 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-05T14:49:53+00:00Added an answer on June 5, 2026 at 2:49 pm

    I found this ‘Programming in NASM.PDF’

    ; add1.asm
    SECTION .data
        message1: db "Enter the first number: ", 0
        message2: db "Enter the second number: ", 0
        formatin: db "%d", 0
        formatout: db "%d", 10, 0 ; newline, nul terminator
        integer1: times 4 db 0 ; 32-bits integer = 4 bytes
        integer2: times 4 db 0 ;
    SECTION .text
       global _main 
       extern _scanf 
       extern _printf     
    
    _main:
    
       push ebx ; save registers
       push ecx
       push message1
       call printf
    
       add esp, 4 ; remove parameters
       push integer1 ; address of integer1 (second parameter)
       push formatin ; arguments are right to left (first parameter)
       call scanf
    
       add esp, 8 ; remove parameters
       push message2
       call printf
    
       add esp, 4 ; remove parameters
       push integer2 ; address of integer2
       push formatin ; arguments are right to left
       call scanf
    
       add esp, 8 ; remove parameters
    
       mov ebx, dword [integer1]
       mov ecx, dword [integer2]
       add ebx, ecx ; add the values          ; the addition
       push ebx
       push formatout
       call printf                            ; call printf to display the sum
       add esp, 8                             ; remove parameters
       pop ecx
       pop ebx ; restore registers in reverse order
       mov eax, 0 ; no error
       ret
    

    Which is the asm version of this C function:

    #include <stdio.h>
    int main(int argc, char *argv[])
    {
        int integer1, integer2;
        printf("Enter the first number: ");
        scanf("%d", &integer1);
        printf("Enter the second number: ");
        scanf("%d", &integer2);
        printf("%d\n", integer1+integer2);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Basically, what I'm trying to create is a page of div tags, each has

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.