flat assembler
Message board for the users of flat assembler.

Index > DOS > Print ing a number

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
davetheant



Joined: 09 Aug 2012
Posts: 1
davetheant
Hello everyone. I tried searching for the answer to this in the forums but I couldn't seem to find anything.. I have a number in EAX that I'd like to print out. I've seen things in other forums about repeatedly dividing by 10 and printing digit by digit, but I was unsure if this is the way to do it in FASM. Thanks!
Post 09 Aug 2012, 02:05
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
davetheant,

There are many ways, you may import printf() from MSVCRT.DLL if you're Windows-fancy, or use various itoa() equivalents that are plenty here.
Post 09 Aug 2012, 03:10
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Do you want to do it in "fasm", or do you mean (fasm) assembly?

This macro displays a four-digit number in fasm. It can be used as pseudocode if you want to write a converter in assembly.

Code:
macro print description,number
{
   display description
   value=number
   pos=1000
   repeat 4
      digit=value/pos
      value=value-(digit*pos)
      pos=pos/10
      display ('0'+digit)
   end repeat
   display $d,$a
}    

_________________
This is a block of text that can be added to posts you make.
Post 09 Aug 2012, 04:30
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
mindcooler,

The key phrase was "a number in EAX". Wink
Post 10 Aug 2012, 08:11
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Is that some internal fasm variable? Smile
Post 10 Aug 2012, 10:55
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1399
Location: Toronto, Canada
AsmGuru62
I found some old DOS code -- maybe it will help.
It prints AX however, not EAX.
And it does not consider negative numbers - all unsigned.
Code:
PrintAX:
  ;
   ; Assumption: all segments are set to the same value (COM program)
      ;
   pusha

   sub     sp, 16          ; Reserve 16 character buffer on stack
      lea     di, [sp + 15]   ; DI = address of a last character
  mov     byte [di], '$'        ; This is for AH=9 INT 21H
  mov     cx, 10          ; Will be dividing DX:AX by this
@@:
     xor     dx, dx
      div     cx              ; Divide DX:AX by 10

        dec     di              ; Avoiding AGI
      add     dl, '0'               ; Convert to a digit
        mov     [di], dl        ; And store it into buffer

      test    ax, ax          ; Check if there is more to divide?
 jnz     @r              ; Yes. Divide again.

    mov     dx, di          ; Dump string to console
    mov     ah, 9
       int     21h

     add     sp, 16          ; Restore stack and return
  popa
        ret
    
Post 10 Aug 2012, 12:17
View user's profile Send private message Send e-mail Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac
I made some little dos applicaton for to converting 32 bit values.

Dez2bit
Dez2hex
Hex2bit
Hex2dez (including routine for printing decimal values of eax)

www.alice-dsl.net/freecracmaps/Tool/Zahlswap.zip

Dirk
Post 18 Aug 2012, 08:46
View user's profile Send private message Send e-mail Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 759
Location: Massachusetts, USA
bitshifter
maybe this work for you? (i didnt test it...)
Code:
;assumes ds=es
itoa:
;in: ax = value
;    bx = base
;    di -> buffer
 cmp bx,10
 jne utoa
 test ax,ax
 jns utoa
 neg ax
 mov byte[ds:di],'-'
 inc di
;jmp utoa

utoa:
;in: ax = value
;    bx = base
;    di -> buffer
 xor dx,dx
 div bx
 push dx
 test ax,ax
 jz .purge
 call utoa
.purge:
 pop ax
 and al,0x0F
 cmp al,0x0A
 sbb al,0x69
 das
 stosw
 dec di
 ret
    
Post 02 Nov 2012, 09:59
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386
davetheant wrote:
Hello everyone


Welcome to FASM (oops, 3 moths later) Smile

Quote:
tried searching for the answer to this in the forums but I couldn't seem to find anything.. I have a number in EAX that I'd like to print


This had been discussed already 1'000'000'000'000 times.

Quote:
things in other forums about repeatedly dividing by 10 and printing digit by digit, but I was unsure if this is the way to do it in FASM


Definitely YES : see Main FAQ Group "E. MATH" http://board.flatassembler.net/topic.php?t=2530

> There are many ways, you may import printf()
> from MSVCRT.DLL if you're Windows-fancy

This is an inferior way to to on Windows and a NO-GO in DOS Wink

EDIT : moved part of post content into the FAQ

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug


Last edited by DOS386 on 29 Apr 2013, 07:38; edited 3 times in total
Post 04 Nov 2012, 13:33
View user's profile Send private message Reply with quote
lamer



Joined: 24 Apr 2013
Posts: 8
lamer
lol, just registered to ask same question... im reading tajga fasm tutorial started to make my own simple apps to practice and realized theres noway to print numbers... i can print string but cant numbers?! why theres no 'print number' interupt? Thats weird...
Post 24 Apr 2013, 12:28
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1399
Location: Toronto, Canada
AsmGuru62
There should be a lot of code posted here over time for that purpose.
Did you view the links posted in previous post?
Post 24 Apr 2013, 13:31
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16997
Location: In your JS exploiting you and your system
revolution
lamer wrote:
why theres no 'print number' interupt?
Because there are many many ways to format numbers of different forms. Do you want binary? Octal? Decimal? Hexadecimal? Other base (like phinary)? And what about integer, float, fixed point? What precision? How many bits? 8? 16? 32? 64? Arbitrary size? Signed or unsigned? etc. etc. etc.

It is usually easier just to program what you need for the job at hand, rather than have the OS/BOIS provide some sort of uber-mega-ultra-bloated-number-to-text conversion routine.
Post 24 Apr 2013, 14:56
View user's profile Send private message Visit poster's website Reply with quote
lamer



Joined: 24 Apr 2013
Posts: 8
lamer
revolution wrote:
lamer wrote:
why theres no 'print number' interupt?
Because there are many many ways to format numbers of different forms. Do you want binary? Octal? Decimal? Hexadecimal? Other base (like phinary)? And what about integer, float, fixed point? What precision? How many bits? 8? 16? 32? 64? Arbitrary size? Signed or unsigned? etc. etc. etc.

It is usually easier just to program what you need for the job at hand, rather than have the OS/BOIS provide some sort of uber-mega-ultra-bloated-number-to-text conversion routine.

not so many. you just make it sound bad but you actually wrote all the cases of a basic number printing interupt. no need to go crazy about it making it phinary and whatevernary. if you point it that way theres no need for a string printing interupt because everything can be coded from scratch 'easier'
Post 25 Apr 2013, 00:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16997
Location: In your JS exploiting you and your system
revolution
lamer wrote:
not so many. you just make it sound bad but you actually wrote all the cases of a basic number printing interupt. no need to go crazy about it making it phinary and whatevernary. if you point it that way theres no need for a string printing interupt because everything can be coded from scratch 'easier'
The printing of a string is a basic function that an OS/BIOS should support because the hardware is different and app programs shouldn't have to concern themselves with hardware differences. But printing a number is not a basic function. A number is formatted into a string and then the string print function is used.

Besides I didn't mention all cases above. There are plenty more, including, but not limited to, character set selection, internationalisation for digit grouping, negative representation (accounting requirements), leading/trailing zeros, left/right justification, out of scope numbers (infinity, NaNs, etc.), etc. etc. etc.
Post 25 Apr 2013, 02:21
View user's profile Send private message Visit poster's website Reply with quote
lamer



Joined: 24 Apr 2013
Posts: 8
lamer
revolution wrote:
lamer wrote:
not so many. you just make it sound bad but you actually wrote all the cases of a basic number printing interupt. no need to go crazy about it making it phinary and whatevernary. if you point it that way theres no need for a string printing interupt because everything can be coded from scratch 'easier'
The printing of a string is a basic function that an OS/BIOS should support because the hardware is different and app programs shouldn't have to concern themselves with hardware differences. But printing a number is not a basic function. A number is formatted into a string and then the string print function is used.

Besides I didn't mention all cases above. There are plenty more, including, but not limited to, character set selection, internationalisation for digit grouping, negative representation (accounting requirements), leading/trailing zeros, left/right justification, out of scope numbers (infinity, NaNs, etc.), etc. etc. etc.

I dont know what internationalisation you talk about DOS only cares about USA. Anyway, there's printf function in C lib, same interupt could be made. And that could be a basic number printing interupt. And when you talk about accounting and stuff that goes beyond basic so it should be coded from scratch. Everything can be made complicated, i cant print cyrillic letters with DOS interupt for example according to you logic string printing interupt is useless because of that and should not be made.
Post 25 Apr 2013, 11:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16997
Location: In your JS exploiting you and your system
revolution
lamer wrote:
... according to you logic string printing interupt is useless because of that and should not be made.
Well I am merely defending the lack of any DOS function to convert a number into string format. Complaining about it being missing won't help though because DOS has long since stopped being developed by MS.
Post 25 Apr 2013, 12:47
View user's profile Send private message Visit poster's website Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1903
DOS386
> internationalisation for digit grouping

That's what the world really badly needs ... a crucial feature that distinguishes professional operating systems from toys Smile Smile Smile Smile Smile

> DOS has long since stopped being developed by MS

True but irrelevant ... get FreeDOS (but you still will have to divide by 10 yourself ...) Smile

PS: You'll get 18'446'744'073'709'551'615 Byte's of bloat if you add everything into your OS Smile

> lol, just registered to ask same question...

Look at the FAQ at forum top before asking (doesn't cost registration)

http://board.flatassembler.net/topic.php?t=2530
Post 28 Apr 2013, 14:32
View user's profile Send private message Reply with quote
Just4fasm



Joined: 20 May 2012
Posts: 60
Location: OuterSpace
Just4fasm
A person asked a question then you apesh people are often giving a lame moronic replies!!!. Exclamation Exclamation Exclamation
What is wrong with this person's question???!!! Sad
Quote:
Hello everyone. I tried searching for the answer to this in the forums but I couldn't seem to find anything.. I have a number in EAX that I'd like to print out. I've seen things in other forums about repeatedly dividing by 10 and printing digit by digit, but I was unsure if this is the way to do it in FASM. Thanks!

If you are were normal people with a real basic knowledge of asm and pc! then you are can give this proper answer to him! davetheant, you skipped what you looking for or you confused because of less knowledge! Yes you can! dividing by 10 and printing digit by digit, this is the way to do it in ANY ASM!!!.
I pity you assemblers, moderators! You are look like some kind of poorly programmed bot!. I know, you are a real humans! but you are natively have logic stupidity and lack of knowledge of real things!. Obviously, you are Black Homosapein Orangutang's supporters!. Black Orangutang can easily trick you and you are very close minded apes next to him!. Black Orangutang is half human and half animal! You know he is resident evil internationally United States of Apes!!!.

baldr!!! Mad NO C!!! Because it is all about ASM!!!!!!!.

Lamer! Mad there's no need 'print number' interrupt! if you point it a string printing because everything can be coded very easily!. And you can print cyrillic letters in DOS!. DOS is DOS! DOS doesn't cares about USA or International!!!. Idea

freecrac! Confused Only you have a human brain but sadly only 60%!!! rest of 40% ape!!!. DON'T SUPPORT microsoft!!! cos you often using crap MS-DOS 21h interrupts on very unusual things!!!. Exclamation

revolution!!! Evil or Very Mad MS-DOS stands for Money Swindle from Disk Operating System! Microsoft is stole moneys from DOS! that's why they stopped long time ago! since they can't steal anymore!. You merely knows about the MIGHTY DOS!!!. And you have lack of human brain!!! Your ape brain level is higher than your human brain level.

DOS is powerful than shit thief microsoft OSes!!!. Anything is possible on DOS!. Windows OS will be die! DOS is never ever dies!!!. DOS is the champion of the speed!. Cool

_________________
Assembly language is machine instruction so don't make fake assembly languages other than actual CPU instruction code!.
Fuck stupid Microsoft! for faking instruction codes!!!.
Post 29 Apr 2013, 15:29
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16997
Location: In your JS exploiting you and your system
revolution
Just4fasm wrote:
revolution!!! Evil or Very Mad MS-DOS stands for Money Swindle from Disk Operating System! Microsoft is stole moneys from DOS! that's why they stopped long time ago! since they can't steal anymore!. You merely knows about the MIGHTY DOS!!!. And you have lack of human brain!!! Your ape brain level is higher than your human brain level.
Thank you for your kind words. Apes are smart and interesting creatures.
Post 29 Apr 2013, 15:39
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1399
Location: Toronto, Canada
AsmGuru62
When this thread started -- I politely asked if the thread starter looked at any of posted links.
Still waiting for results.
Because I can write a small function for DOS, which will print the 16-bit integer.
Post 29 Apr 2013, 16:29
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.