![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
Assembler displaying digits
can anybody tell me a good way to display numbers In ASM using dos interrupts, because the dos interrupt 21h sub routine 02 ouputs values in their ascii equivallent so how do i display a two figured result of an calculation, for example how do i display the number 10 because if i use the the does interrupt i said above it would convert it to its asci value which is ":" . Sorry if you have found my explaination confusing. I thank you for your replies in advance.
|
|
|
|
|
|
#2 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
It's a two step process. First you break the number down into individual digits (a simple modulus/division operation). Then you convert each digit into the ASCII representation (try adding 48 to the value). Print the resulting characters in the right order and you're sorted.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
thanks Narue........i understand and know about the adding the 48 trick but i don't understand the moduls/division operation that you have mentioned. perhaps you can give a simple demonstation of that.
okay sorry Narue just took a moment to digest what you have suggested.......and know i understand what you were implying..........but know how do get the remainder of a division operation in ASM .......i am using A86 if that helps. Thanks for the help so far Narue |
|
|
|
|
|
#4 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>but know how do get the remainder of a division operation in ASM
mov dx,0 ; It's important to clear DX because DX:AX is the dividend mov ax,123 mov bx,10 ; Divisor div 10
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
thanks again Narue............but know how do i output these calculations i can't ouput this using sub routine 02 of 21h because whatever is being ouputted has to be stored in dl which is a byte and the calculations of above are in 2 bytes dx ( i think) so you can't do mov dl,dx, so how do know display these calculations.
I appreciate your support Narue. I found a few errors in the code you have posted above, so i took the liberty to correct and post it for other users that browse through this thread: Quote:
|
|
|
|
|
|
|
#6 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>so how do know display these calculations
Save them in memory as a string, then use 09h of interrupt 21h to print the string.
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
what do i just choose a random memory location, and if i do wouldn't there be a possibilty that another program is using that memory location. Can you demonstate this Narue please.
|
|
|
|
|
|
#8 |
|
Professional Programmer
![]() Join Date: Sep 2005
Posts: 419
Rep Power: 4
![]() |
>what do i just choose a random memory location
Something like that. You declare enough space. >Can you demonstate this Narue please. Oh, very well. This is FASM though, I don't have A86: format MZ
org 100h
jmp start
save db 4 dup '$'
start:
mov ax,123
mov bx,10
mov di,2
convert:
mov dx,0
div bx
add dx,'0'
mov [save+di],dl
dec di
test ax,ax
jnz convert
; Display the result
mov ah,09h
mov dx,save
int 21h
; Finish up
mov ah,4Ch
mov al,0
int 21h
__________________
Even if the voices aren't real, they have some pretty good ideas. |
|
|
|
|
|
#9 |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
wow thanks Narue.............but why did u put 2 in the di regester
|
|
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Endianness.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|