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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:26:08+00:00 2026-05-26T08:26:08+00:00

I plan to convert the X variable to decimal. I’m having a hard time

  • 0

I plan to convert the X variable to decimal. I’m having a hard time using turbo assembler, can you give a hand?

code segment     ;inicio de un segmento unico
assume cs:code,ds:code,ss:code
org 100h       ;localidad de inicio del contador
main  proc     ;procedimiento principal

mov ax,cs
mov ds,ax   ; INICIO 

mov ax, x

mov ah,4ch ;comienzo del fin de programa
int 21h    ;fin del programa

main endp

x dw 0A92FH

code ends   ; fin del segmento de codigo
end main    ;fin del ensamble

Thanks a lot

  • 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-26T08:26:09+00:00Added an answer on May 26, 2026 at 8:26 am

    When converting numbers to a printable format it’s often easiest to start with the last digit.

    Consider converting 123 to “123”, how would we get the last digit? It’s the remained when dividing by 10 (the base). So 123 % 10 gives us 3 and 123 / 10 = 12 conveniently gives us the correct number to work with in the next iteration. On x86 the “DIV” instruction is nice enough to give us both the quotient and remainder (in ax and dx respectively). All that remains is to store printable characters in the string.

    Putting all this together you end up with something like the following (using nasm syntax):

    ; ConvertNumber
    ;   Input:
    ;     ax = Number to be converted
    ;     bx = Base
    ;   
    ;   Output:
    ;     si = Start of NUL-terminated buffer
    ;          containing the converted number
    ;          in ASCII represention.
    
    ConvertNumber:
        push ax            ; Save modified registers
        push bx
        push dx
        mov si, bufferend  ; Start at the end
    .convert:
        xor dx, dx         ; Clear dx for division
        div bx             ; Divide by base
        add dl, '0'        ; Convert to printable char
        cmp dl, '9'        ; Hex digit?
        jbe .store         ; No. Store it
        add dl, 'A'-'0'-10 ; Adjust hex digit
    .store:
        dec si             ; Move back one position
        mov [si], dl       ; Store converted digit
        and ax, ax         ; Division result 0?
        jnz .convert       ; No. Still digits to convert
        pop dx             ; Restore modified registers
        pop bx
        pop ax
        ret
    

    This requires a working buffer (16 for the case when base = 2 and an extra byte for the NUL terminator):

    buffer: times 16 db 0
    bufferend:
        db 0
    

    Adding support for signed numbers is left as an exercise for the reader. Here is roughly the same routine adapted for 64-bit assembly.

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

Sidebar

Related Questions

I need to convert C# code to an equivalent XML representation. I plan to
My plan is to collect lawyer biography data from websites in batches and convert
I have a string variable called tbSKUPrice. I need to convert this into an
I'm trying to create a function to read Morse code from one file, convert
I have the following code: #include <iostream> #include <string> #include <unistd.h> using namespace std;
I plan to be storing all my config settings in my application's app.config section
I plan to serialize a Django model to XML when it's saved or updated.
We plan to redesign, improve our (C#) application architecture. Anyone has some framework, hompage
I plan to use PyInstaller to create a stand-alone python executable. PythonInstaller comes with
I plan to have 2 projects. 1. mbtech.crm.mvc 2. mbtech.crm.tests I will have a

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.