# 'Assembly Language Programming' Problem

Discussion in 'Programming' started by a_to_z123, Nov 27, 2005.

Tags:
Not open for further replies.
1. ### a_to_z123asia://india/ka/bangalore

Joined:
Nov 4, 2004
Messages:
288
0
Trophy Points:
16
Location:
Bangalore, India
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...

2. ### swatkatNew Member

Joined:
Mar 12, 2004
Messages:
2,058
1
Trophy Points:
0
Location:
Shimoga/ಶಿವಮೊಗ್ಗ
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.

3. OP

### a_to_z123asia://india/ka/bangalore

Joined:
Nov 4, 2004
Messages:
288
0
Trophy Points:
16
Location:
Bangalore, India
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.

4. ### swatkatNew Member

Joined:
Mar 12, 2004
Messages:
2,058
1
Trophy Points:
0
Location:
Shimoga/ಶಿವಮೊಗ್ಗ
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.)

5. OP

### a_to_z123asia://india/ka/bangalore

Joined:
Nov 4, 2004
Messages:
288
0
Trophy Points:
16
Location:
Bangalore, India
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!!

6. ### King_NiralNew Member

Joined:
May 12, 2005
Messages:
403
0
Trophy Points:
0
Location:
JABALPUR (M.P)
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 !!