Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 16th, 2006, 3:47 PM   #1
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
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.
kruptof is offline   Reply With Quote
Old May 16th, 2006, 4:46 PM   #2
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
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.
Narue is offline   Reply With Quote
Old May 16th, 2006, 4:54 PM   #3
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
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
kruptof is offline   Reply With Quote
Old May 16th, 2006, 5:15 PM   #4
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>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
After the div instruction, AX (the quotient) will contain 12 and DX (the remainder) will contain 3. This design is well suited for a loop where the least significant digit is chopped off of AX for each iteration.
__________________
Even if the voices aren't real, they have some pretty good ideas.
Narue is offline   Reply With Quote
Old May 16th, 2006, 5:32 PM   #5
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
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:
mov dx,0
mov ax,12
mov bx,10
div b
kruptof is offline   Reply With Quote
Old May 16th, 2006, 7:20 PM   #6
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>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.
Narue is offline   Reply With Quote
Old May 17th, 2006, 6:02 AM   #7
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
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.
kruptof is offline   Reply With Quote
Old May 17th, 2006, 8:26 PM   #8
Narue
Professional Programmer
 
Narue's Avatar
 
Join Date: Sep 2005
Posts: 419
Rep Power: 4 Narue is on a distinguished road
>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.
Narue is offline   Reply With Quote
Old May 18th, 2006, 12:00 PM   #9
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
wow thanks Narue.............but why did u put 2 in the di regester
kruptof is offline   Reply With Quote
Old May 18th, 2006, 12:07 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:15 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC