Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 27-11-2005, 05:07 PM   #1 (permalink)
asia://india/ka/bangalore
 
a_to_z123's Avatar
 
Join Date: Nov 2004
Location: Bangalore, India
Posts: 293
Default 'Assembly Language Programming' Problem


Well guys here is something which I couldn't find anywhere.

I wrote a simple program to add two numbers in Assembly Language.

So is there any way to show the output on the screen. Any way.............is there???
I mean I know how to output a string on the screen (i.e. by using 'MOV ah, 9h'), but I dunno how to print a number on screen.

If there is, then do tell me...

Thx in advance!!!
__________________
:) I've got my F, C and K . Now all I need is You !!! :)
a_to_z123 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 27-11-2005, 05:41 PM   #2 (permalink)
Human Spambot
 
swatkat's Avatar
 
Join Date: Mar 2004
Location: India
Posts: 2,033
Default

You have to first unpack the Hex number's upper and lower nibble and then convert both the upper and lower nibbles to their equivalent ASCII (by adding 30H). After this you will get two 1 byte ASCII codes representing the original number's upper nibble and lower nibble. You can later use Int 21 to print these two ASCII charactrers one after another which show up as numbers on screen.
__________________
http://swatrant.blogspot.com/
swatkat is offline  
Old 27-11-2005, 09:44 PM   #3 (permalink)
asia://india/ka/bangalore
 
a_to_z123's Avatar
 
Join Date: Nov 2004
Location: Bangalore, India
Posts: 293
Default

Thx SwatKat,

I'll surely try out your method and let you know. Actually I'm new to assembly language so let me understand what do you mean exactly.
Then I'll implement it.

Thx again.
a_to_z123 is offline  
Old 27-11-2005, 11:42 PM   #4 (permalink)
Human Spambot
 
swatkat's Avatar
 
Join Date: Mar 2004
Location: India
Posts: 2,033
Default

Hi,
Here's the code to do it:-

MOV AX,0000 ;clear AX

MOV AL, 12 ; Here 12 is the number that is to be displayed.

PUSH AX ; Back up the number

SHR AX, 4 ; Shift AX to right 4 times to get the upper nibble (of AL) to lower position. (Now, AL <= 01)

ADD AL, 30 ; Add 30H to convert it to ASCII (Now, AL <= 31)

MOV CH, AL ; Store this ASCII of upper nibble in CH (CH <= 31)

POP AX ; Restore AX

AND AL, 0F ; Mask the upper 4 bits. (Now, AL <= 02)

ADD AL, 30 ; Convert to ASCII (AL <= 32)

MOV AH, CH ; Copy CH to AH. Now, AH contains ASCII of 1 and AL contains ASCII of 2.
(AH <= 31 and AL <= 32, so AX=3132).


Now, you can store the contents of AX at some memory location and then use the INT 21 with the 09H. (Make sure to store 24 (ASCII of $) at the end of the ASCII of numbers storeed in memory.)
__________________
http://swatrant.blogspot.com/
swatkat is offline  
Old 03-12-2005, 12:19 PM   #5 (permalink)
asia://india/ka/bangalore
 
a_to_z123's Avatar
 
Join Date: Nov 2004
Location: Bangalore, India
Posts: 293
Default

Thanx a lot swatkat!!!

Actually I got in a fix with two digit nos.
I could only print single-digit nos by adding 30h.

I got the gist behind it. Actually it adds 48 to the no and makes it equivalent to its ASCII code. Hai naa.

Well thx again!!

Waiting to try it!!
a_to_z123 is offline  
Old 03-12-2005, 02:51 PM   #6 (permalink)
In The Zone
 
Join Date: May 2005
Location: JABALPUR (M.P)
Posts: 403
Default

hey swat ur brilliant MAN !!!

Man watz ur qualif ???

Ur an engineer or Mca student or just interest ??

coz if its interest ur EXTREMELY Brilliant !!! Hey even if it the other 2 options ur Brilliant as well !!

neway!!

Cheers !!
__________________
\"Live Life as it comes & Live it KINGSIZE\"
\"Learn From Yesterday,Live For Today & Hope For Tomorrow\".
Bye 4 Now - N_!_r_a_L
King_Niral is offline  
Closed Thread

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:40 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2