Results 1 to 10 of 10

Thread: Converting number into displayable strings...

  1. #1

    Thread Starter
    Fanatic Member HaxSoft's Avatar
    Join Date
    May 2000
    Location
    Ohio
    Posts
    593
    Well, you'd have to write a routine to do that. For example, if you have decimal 7 in Abc, you could simply print character 48 (decimal) + Abc IF Abc plus 48 is less than or equal to 57 (the "9" character).

    If it's greater, then you have to 'mod' it to find out what the least significant digit should be and work your way up until you have all the right digits.

    Hope this makes sense; it's a little hard to explain.

  2. #2
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    Yes, I've this kind of idea at first...
    But dont know how should I code it...
    Is it kinda like recursive procedure?

    If it's binary to hex string...
    That'll be more easy by splitting the high and low nibble
    then using XLAT to translate it...

    But this is decimal...
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  3. #3
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    Cool

    This is something every assembly programmer should have been done before when they want to display a number.

    I have done a module in x86 assembly 5 years ago so I don't remember the instructions set now.

    But I can roughly tell you the steps and logic of how I did it.(for numbers only, not floating point numbers).

    eg,

    1234

    1234/10000, get the result = 0 store nA.
    if not 0, subtract the result from the number.

    1234/1000, get the results = 1 store nB.
    if not 0, subtract the result from the number.

    234/100, get the result and store nC.
    if result not 0, subtract the result from the number.

    34/10, get the result and store in nD.
    if not 0, subtract the result from the number.

    4/10, get the remainder and store in nE

    Run a loop to check nA,nB,nC, is 0.

    Upon hitting the first non zero, break out of loop and start to prepare for display.

    Prepare for display: add 48 to the numbers, eg(1 add to 48 will be 1 in ascii), do some logic yourself to avoid displaying the leading zeros by adding a tag or something like that, up to you.

    Now can display, also do some coding for merging the numbers with the string you want to display together.

    The above is for 16 bit number and 16bit number max is 65535(5 numbers max, that's y you got to divide by 10000 first)

    The logic for 32 bit is the same, divide by 1000 000 000.

    Assembly programming is very tedious and long.

    There is little rewards in writing such a routine. IMO only

    It is better to combine your assembly skills with higher level language to get the performance you want if necessary.(Don't use asssembly unnecessary. also IMO only.
    Last edited by transcendental; Mar 16th, 2002 at 07:07 PM.

  4. #4
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    Uh, thanx, ur algorithm seems to take up lots of resources...
    Lots of divide

    I am making a BASIC to ASM converter...
    But not the usual one,
    this BASIC is concentrating on creating system apps or OS...
    so I've to keep on minimizing and speeding up the codes...

    I am making the assembly codes for the Val & Str
    functions.

    So, impossible to combine with high level lang...

    Anyway, while making this BASIC, is there anyway to avoid
    pushing registers while executing a code?
    For example...
    There's a loop, CX has the counter...
    While in the loop, I am running a display string code...
    Where it uses CX register...
    And thus I've to push those registers...
    This is really tedious...
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  5. #5
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Originally posted by jian2587

    There's a loop, CX has the counter...
    While in the loop, I am running a display string code...
    Where it uses CX register...
    And thus I've to push those registers...
    This is really tedious...
    I think you have to push or try to freed and use some other register like AX ,as Intel CPU is really lack of registers which programmer could use.

    Assembly programming is tedious, as I told you. It is not as straightforward as other higher languages where you call other people's code most of the time.

  6. #6
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    *Lol*
    PUSHA and POPA
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  7. #7
    DaoK
    Guest
    You will need to move the hexa number to the ascii number with SHL and SHR.

    Example:
    If you want to print the number 19 you will need to split the 1 and the 9 in 2
    1)
    [0][0][1][9] should be [0][1][0][9]

    2) After you will need to increment of 20 both to have the ascii number

    [2][1][2][9]

    3)after you print seperatly both and here you are.

  8. #8
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    Pls explain more...
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  9. #9
    DaoK
    Guest
    How can I explain it more than that ?

  10. #10
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963
    How about writing the asm code for it?
    I'll figure it myself
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width