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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:12:20+00:00 2026-06-11T14:12:20+00:00

I coded the following assembly script for IA32. It is supposed to read a

  • 0

I coded the following assembly script for IA32. It is supposed to read a number from stdin, increment it and print it to stdout, but it does not behave as expected, it doesn’t print anything (maybe the reading from stdin does not terminate or something with the printing is wrong?)

.section .text
    .globl _start

_start:
    movl $3, %eax       # use syscall 3 (read) to read from stdin
    movl $0, %ebx       # reads from stdin (FD 0)
    movl %edi, %ecx    # store input in register %edi
    movl $4, %edx       # read one byte
    int  $0x80      # invoke system call to read from stdin

    incl %edi          # increment the value we got from stdin

    movl $4, %eax       # use syscall 4 (write) to print to screen
    movl $1, %ebx       # print to stdout (FD 1)
    movl %edi, %ecx    # pointer to text to write out
    movl $4, %edx       # length of text to write out (1 byte)
    int  $0x80          # invoke system call to write to stdout

    movl $1, %eax       # use syscall 1 (exit) to exit
    movl $0, %ebx       # error code = 0
    int  $0x80          # invoke system call

Do you see the error? For any help I thank you in advance,

All the best,
Simon

  • 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-11T14:12:21+00:00Added an answer on June 11, 2026 at 2:12 pm
    movl %edi, %ecx    # store input in register %edi
    movl $4, %edx       # read one byte
    

    This part is all wrong. You can’t store the result of read in a register. What that’s actually doing is storing the result at the address contained in %edi, which since you haven’t set it, is probably somewhere you have no business storing anything. You first need to make room in memory to store the string at. You’re also reading four bytes and not one.

    I would replace that with something like this

    subl $4, %esp
    movl %esp, %ecx
    movl $4, %edx
    

    This will make room for 4 bytes on the stack, then use the top of the stack as the address to store the string at. You’ll also have to modify the arguments for the write syscall to use this address.

    Another problem that you’ll have to deal with is that stdin and stdout usually deal with text, so what you’re reading will probably be a string and not a number, to use it as a number you’ll have to convert it and then convert it back before you write it out.

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

Sidebar

Related Questions

Suppose you are given a Class.dll assembly compiled from the following simple code: namespace
I am Plotting a pixel on the screen from the following code using Assembly
The book of IronPython In Action has the following code to read python script
In the following assembly code that I dumped out using objdump : lea 0x0(%esi,%eiz,1),%esi
My EAX register contains the xxxxxx9D value and I have the following assembly code:
I am trying to run the following code in assembly: mov %si, %ax mov
I have the following code: namespace ConectorV2 { [assembly:InternalsVisibleTo(Pruebas)] internal static class Utilidades {
I have the following Powershell code: Add-Type -Assembly System.Configuration [ExeConfigurationFileMap] $configMap = New-Object ExeConfigurationFileMap
Looking at some assembly code for x86_64 on my Mac, I see the following
I have a simple assembly code file called exit.s that looks like the following:

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.