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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:32:50+00:00 2026-05-26T17:32:50+00:00

This needs to be done in pure assembly (ie. no libraries or calls to

  • 0

This needs to be done in pure assembly (ie. no libraries or calls to C).

I understand the essence of the problem: one needs to divide the integer by 10, convert the one-digit remainder to ASCII, output that and then repeat the process with the quotient.

But for some reason, it’s just not working. I’m using NASM on x86.

Here’s what I have up to now (doesn’t output anything, but doesn’t throw any assembler errors either):

; integer to output is stored in eax
mov ecx, 10   ; for base 10

loop:
div ecx  ;EAX contains the quotient, EDX the remainder

; Do something to EDX to convert it to ASCII, not sure if this is correct
add edx, '0'

push eax    ;We'll be playing with EAX to output EDX, save EAX to the stack

mov eax, 4              ; sys_write
mov ebx, 1              ; to STDOUT
mov ecx, edx
mov edx, 1
int 0x80

pop eax  ;restore EAX

cmp eax, 0   ;If EAX is 0, our job is done
jnz loop

There are a number of questions similar to this one (namely, this and this), but I’m lost in the implementation. This question (for DOS) was also helpful, but I’m still confused.

I must be missing something here. Thoughts?

  • 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-26T17:32:50+00:00Added an answer on May 26, 2026 at 5:32 pm

    There are at least two more problems. beyond the corruption of ecx that @sarnold mentioned:

    1. div ecx divides the 64-bit value edx:eax by ecx, so you need to ensure that you set edx to 0 before the division.

    2. The second argument to the write system call (in ecx) should be a pointer to a buffer containing the character you want to print, not the character itself.

    One way to solve the second problem is to push the register containing the character you want to print on the stack, and then assign the stack pointer esp to ecx (the stack pointer points at the most recently pushed item, and x86 stores values little-endian, so the first byte is the low 8 bits). e.g.

    push edx         ; save value on stack
    mov  eax, 4      ; sys_write
    mov  ebx, 1      ; to STDOUT
    mov  ecx, esp    ; first byte on stack
    mov  edx, 1      ; length = one byte
    int  0x80
    pop  edx         ; remove what we pushed (or "add esp, 4" would do just as well here;
                     ;                        we don't need the actual value again)
    

    That should be enough to get some output…

    (But at that point, you might notice a “feature” of your algorithm, and want to re-think how you store the digits that are produced by the division!)

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

Sidebar

Related Questions

How does one create Dynamic CSS and JavaScript On-The-Fly (using PHP). This needs to
I need to create a midnight DateTime I've just done this: DateTime endTime =
I'm almost done with this, just a few last hiccups. I now need to
I haven't actually done this yet, and maybe I don't need to, but it
This isn't working. Can this be done in find? Or do I need to
I need to create a Firebird Database programmatically using DBExpress. I have done this
I need to migrate Access databases to SQL Server 2005. Since this needs to
I'm looking for a way to format numbers using tokens. This needs to be
I'm hoping this just needs a new pair of eyes casting over it. I
http://localhost:50034/Admin/Delete/723 Always needs this parameter to perform the action, however, if you go to

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.