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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:39:32+00:00 2026-05-29T05:39:32+00:00

The question consists of an assembly program that takes an input from a C

  • 0

The question consists of an assembly program that takes an input from a C program and divides it by a number, and returns the remainder to the C program to be printed as a string.

Here is my code for both:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int i;
char *str;
str = malloc(1<<9);

printf("Enter a number: ");
scanf ("%d", &i);
printf("Number: %i\n", i);
str=int2string(i);
printf("Number as string is: %s\n", str);

return 0;

}

ASM =

%include "asm_io.inc"

segment .data

segment .bss

buffer resd 4   

segment .text
    global int2string
int2string:
    enter   0,0             ; setup routine
    pusha
    mov edx, 0

    mov eax, [ebp+8]        ; eax contains input value of int2string

    mov ebx, 10     ; sets ebx to value of 10
    div ebx         ; eax = eax / ebx

    call print_int      ; prints eax = quotient
    call print_nl       ; next line

    mov eax, edx        ; store edx (remainder) in eax

    call print_int      ; print remainder
    call print_nl       ; next line

    add eax, 48     ; convert result into ASCII character

    popa
    mov dword[buffer], eax  ; move ASCII character (if I replace eax with 48-57
                            ; it prints 0-9 correctly)
    mov eax, buffer     ; move buffer value to eax
    leave                     
    ret

My understanding is that the ASCII codes for numbers 0-9 is from the range 48-57, but if I don’t put the number explicitly in the buffer move, then the output is either garbage or segmentation fault.

Am I missing something here (eax with a value of 2 + 48, should be ASCII (50) = ‘2’)?

  • 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-05-29T05:39:33+00:00Added an answer on May 29, 2026 at 5:39 am

    It’s likely that either print_int or print_nl may not preserve the value of eax (especially since a common calling convention is to return the result of a function in that register). If your second call to print_int prints the right value but the character is wrong, that’s a distinct possibility.

    An easy test/fix for that is to change:

    call print_int      ; print remainder
    call print_nl       ; next line
    

    into:

    push eax
    call print_int      ; print remainder
    call print_nl       ; next line
    pop eax
    

    Other than that, it looks okay. All I can suggest is to single step through the code to see where it’s going wrong.

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

Sidebar

Related Questions

My question consists of multiple points that are inherently related, I apologize for that.
really simple question: I got a view that consists of two textfields. When the
I have a table that consists of two columns: question and answer. I currently
My question: I have a mysql database that consists of something like a fact
another question of mine. I have created a screen that consists of a Spinner
There is a test that consists of 12 questions. each question must have a
My question actually consists of multiple questions. I'm frequently reading about companies who deploy
Question Can I build a image database/library that has an e-commerce style checkout system
my question consists of tow parts **1- why we need skins for every elements
Despite similar question was asked , I have differnet situation: My app consists mostly

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.