flat assembler
Message board for the users of flat assembler.
Index
> DOS > how can I display decimal number from a register hex number? |
Author |
|
kingsz1 23 Mar 2004, 23:28
I set the hexadecimal value in register, e.g. AX = 3F, how I can display the value to screen in decimal number?
|
|||
23 Mar 2004, 23:28 |
|
aaro 16 Apr 2004, 19:22
Here's proc that converts number to string with any base(decimal=10).
Code: ASTR_UPPER = 'A'-'0'-10 ASTR_LOWER = 'a'-'0'-10 ASTR_SIGNED = 80000000h proc AStrFromNum, Num, Base, Flags type noframe var .TmpBuf, 40 begin pushd edi, esi mov eax, [Num] lea edi, [.TmpBuf] xor ecx, ecx test eax, [Flags] jns .notneg neg eax mov [edi], byte '-' inc ecx inc edi .notneg: mov esi, edi add esi, 32 mov [esi], dword 0 .loop: xor edx, edx dec esi div [Base] cmp edx, 10 jb .digit add dl, byte [Flags] .digit: add edx, '0' mov [esi], dl inc ecx cmp eax, 0 jne .loop push ecx add ecx, 3 shr ecx, 2 rep movsd pop ecx lea eax, [.TmpBuf] AStrAllocMac eax, ecx popd esi, edi return endp |
|||
16 Apr 2004, 19:22 |
|
neonz 17 Apr 2004, 09:56
I can suggest following code:
Code: ; ; input: ; al = single hex digit ; ; output: ; al = single ASCII digit ; ; destroys: ; flags ; cmp al,10 ; if x < 10, set CF = 1 sbb al,69h ; 0-9: 96h .. 9Fh, A-F: A1h..A6h das ; 0-9: subtr. 66h -> 30h-39h, ; A-F: subtr. 60h -> 41h..46h I found it on http://www.brillianet.com/programming/assembly/source_code/. |
|||
17 Apr 2004, 09:56 |
|
slave17 20 Apr 2004, 17:03
i would suggest you use a simple hashtable if the numbers to print don't exceed a certain value. pay attention to the memory limits in real mode- even a table of 64k would be too much. if i was you id just modify the method above to make it a little bit faster.it also not stupid to combine these methods: take as base 100d, 1000d and make hashtables,copy the pointed string from the hashtable to a prepared location in mem and then print everything at once.this method is faster than just dividing by 10d and allows printing almost unlimited size numbers.
|
|||
20 Apr 2004, 17:03 |
|
Matrix 10 Sep 2004, 06:17
neonz wrote: I can suggest following code: Hello Neonz, its a nice snipplet, but he wanted to display decimal MATRIX |
|||
10 Sep 2004, 06:17 |
|
Matrix 11 Sep 2004, 06:26
i think i will help again
Code: bwritewordu: ; writes AX to screen @ x,y (at cursor) mov bx,7 ; returns: AX,CX,DX = undefined ; BX = 7 cmp ax,10000 jnb .down1 cmp ax,1000 jnb .down2 cmp ax,100 jnb .down3 cmp ax,10 jnb .down4 jmp .down5 .down1: mov dx,0 mov cx,10000 div cx add al,48 mov ah,0xE int 10h mov ax,dx .down2: mov dx,0 mov cx,1000 div cx add al,48 mov ah,0xE int 10h mov ax,dx .down3: mov cl,100 div cl mov dl,ah add al,48 mov ah,0xE int 10h mov al,dl mov ah,0 .down4: mov cl,10 div cl mov dl,ah add al,48 mov ah,0xE int 10h mov al,dl .down5: add al,48 mov ah,0xE; int 10h ret MATRIX |
|||
11 Sep 2004, 06:26 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.