0

Hi, i have a problem in displaying the added value of two numbers.

I know how to convert the input number into decimal.

So after converting it, i added those value and got it stored in a register.

My problem is how can I display if the sum is like 10, 11 , 12 ,13 ...onwards.

It will display like ?,@,A,B.

Can someone help me on how to display the right number?

This Question has been **Answered**

0

Um, where do you want it displayed? On a billboard, command prompt, in the sky, DOS, in the dirt, windows? What OS does this display device use?

0

Im using tasm xD

In command prompt.

what i mean is everytime i want to display it, it display the @,?,A,B,C etc. when the sum exceeds to 10,11,12,13,14 etc

0

In command prompt.

what i mean is everytime i want to display it, it display the @,?,A,B,C etc. when the sum exceeds to 10,11,12,13,14 etc

Instead of explaining what you meant, had you posted your code here, you may have already got the solution.

0

Here is the example code

```
mov ah, 1
int 21h ; to get a single number input from the user
sub al, 30h ; to make the input number to decimal
mov a, al ; move the content of al to a variable
mov ah, 1
int 21h
sub al, 30h
add al, a ; add the contents of al and a
add al, 30h
mov ah, 2
mov dl, al ; to display the content of al
int 21h
```

here's the problem, when the sum reaches 10 or higher, it will not display 10 but instead the next symbol in the ascii table after the 9. how can i display it?

0

I had written a procedure for displaying integers on the screen a while back, this might help you with your problem.The code is full of comments so I hope you'll not have a hard time figuring out what it does.

```
put_num: ;function put_num: prints value stored in the ax register
;(a 16 bit integer) to stdout
push ax ;save registers
push bx
push cx
push dx
xor cx,cx ;cx=0
mov bx,10d ;bx=10(decimal)
PNloop1:xor dx,dx ;dx=0
div bx ;dx=ax/bx
push dx ;push the result in stack
inc cx ;cx++(cx acts like a counter to notify how many digits in the number)
cmp ax,0 ;but if the ax was zero,
jnz PNloop1 ;then jump to PNloop1
mov ah,2 ;otherwise...(Dos function to print a character)
PNloop2:pop dx ;get the value just pushed in to the stack in dx,
add dl,48 ;convert it in to ascii
int 21h ;and print it
dec cx ;decrease counter
jnz PNloop2 ;if cx not zero (still digits left) then loop again.
;otherwise ..
pop dx ;restore registers and return
pop cx
pop bx
pop ax
ret
```

*Edited
by D33wakar*: n/a

0

I tried the given code, but it displays tons of 5 @___@.

here is my complete code

```
title add.asm
dosseg
.model small
.stack 0100h
.data
t1 db,10,13, "Enter a number: $"
t2 db "The sum is: $"
a db ?
b db ?
.code
mov dx, @data
mov ds, dx
mov ah, 9
lea dx, t1
int 21h
mov ah, 1
int 21h
sub al, 30h
mov a, al
mov ah, 1
int 21h
sub al, 30h
add al, a
push ax
push bx
push cx
push dx
xor cx, cx
mov bx, 10d
pnloop1:
xor dx,dx
div bx
push dx
inc cx
cmp ax, 0
jnz pnloop1
mov ah, 2
pnloop2:
pop dx
add dl, 48d
int 21h
dec cx
jnz pnloop1
pop dx
pop cx
pop bx
pop ax
mov ax, 4c00h
int 21h
end
```

0

It's a procedure, just call it from your main program like this:

```
.model small
.stack 100h
.data
a db 0
.code
start:
mov ax,@data
mov ds,ax
mov ah, 1
int 21h ; to get a single number input from the user
sub al, 30h ; to make the input number to decimal
mov a, al ; move the content of al to a variable
mov ah, 1
int 21h
sub al, 30h
add al, a ; add the contents of al and a
xor ah,ah ;ah=0
call put_num
mov ah,4ch
int 21h
put_num: ;function put_num: prints value stored in the ax register
;(a 16 bit integer) to stdout
push ax ;save registers
push bx
push cx
push dx
xor cx,cx ;cx=0
mov bx,10d ;bx=10(decimal)
PNloop1:xor dx,dx ;dx=0
div bx ;dx=ax/bx
push dx ;push the result in stack
inc cx ;cx++(cx acts like a counter to notify how many digits in the number)
cmp ax,0 ;but if the ax was zero,
jnz PNloop1 ;then jump to PNloop1
mov ah,2 ;otherwise...(Dos function to print a character)
PNloop2:pop dx ;get the value just pushed in to the stack in dx,
add dl,48 ;convert it in to ascii
int 21h ;and print it
dec cx ;decrease counter
jnz PNloop2 ;if cx not zero (still digits left) then loop again.
;otherwise ..
pop dx ;restore registers and return
pop cx
pop bx
pop ax
ret
end start
```

Note that the above is a masm code.

0

Thanks alot ! it works :DDDDD Thank you! :DDDDDD

heres the final code in TASM :D

```
.model small
.stack 100h
.data
a db 0
t1 db,10,13, "Enter a number: $"
t2 db,10,13, "The sum is: $"
.code
main proc
mov ax,@data
mov ds,ax
mov ah, 9
lea dx, t1
int 21h
mov ah, 1
int 21h ; to get a single number input from the user
sub al, 30h ; to make the input number to decimal
mov a, al ; move the content of al to a variable
mov ah, 9
lea dx, t1
int 21h
mov ah, 1
int 21h
sub al, 30h
add al, a ; add the contents of al and a
push ax
mov ah, 9
lea dx, t2
int 21h
pop ax
xor ah,ah ;ah=0
call put_num
mov ah,4ch
int 21h
main endp
put_num proc ;function put_num: prints value stored in the ax register
;(a 16 bit integer) to stdout
push ax ;save registers
push bx
push cx
push dx
xor cx,cx ;cx=0
mov bx,10d ;bx=10(decimal)
PNloop1:xor dx,dx ;dx=0
div bx ;dx=ax/bx
push dx ;push the result in stack
inc cx ;cx++(cx acts like a counter to notify how many digits in the number)
cmp ax,0 ;but if the ax was zero,
jnz PNloop1 ;then jump to PNloop1
mov ah,2 ;otherwise...(Dos function to print a character)
PNloop2:pop dx ;get the value just pushed in to the stack in dx,
add dl,48 ;convert it in to ascii
int 21h ;and print it
dec cx ;decrease counter
jnz PNloop2 ;if cx not zero (still digits left) then loop again.
;otherwise ..
pop dx ;restore registers and return
pop cx
pop bx
pop ax
ret
put_num endp
end
```

0

Thanks alot ! it works :DDDDD Thank you! :DDDDDD

heres the final code in TASM :D

`.model small .stack 100h .data a db 0 t1 db,10,13, "Enter a number: $" t2 db,10,13, "The sum is: $" .code main proc mov ax,@data mov ds,ax mov ah, 9 lea dx, t1 int 21h mov ah, 1 int 21h ; to get a single number input from the user sub al, 30h ; to make the input number to decimal mov a, al ; move the content of al to a variable mov ah, 9 lea dx, t1 int 21h mov ah, 1 int 21h sub al, 30h add al, a ; add the contents of al and a push ax mov ah, 9 lea dx, t2 int 21h pop ax xor ah,ah ;ah=0 call put_num mov ah,4ch int 21h main endp put_num proc ;function put_num: prints value stored in the ax register ;(a 16 bit integer) to stdout push ax ;save registers push bx push cx push dx xor cx,cx ;cx=0 mov bx,10d ;bx=10(decimal) PNloop1:xor dx,dx ;dx=0 div bx ;dx=ax/bx push dx ;push the result in stack inc cx ;cx++(cx acts like a counter to notify how many digits in the number) cmp ax,0 ;but if the ax was zero, jnz PNloop1 ;then jump to PNloop1 mov ah,2 ;otherwise...(Dos function to print a character) PNloop2:pop dx ;get the value just pushed in to the stack in dx, add dl,48 ;convert it in to ascii int 21h ;and print it dec cx ;decrease counter jnz PNloop2 ;if cx not zero (still digits left) then loop again. ;otherwise .. pop dx ;restore registers and return pop cx pop bx pop ax ret put_num endp end`

you're welcome.

And also mark this thread solved.

*Edited
by D33wakar*: n/a

This question has already been answered. Start a new discussion instead.

Recommended Topics

Could anyone please review my code

https://github.com/LeoUpperThrower4/GeneticAlgorithm

Hi Guys,

I ussually dont post anything here often, just get everything off of everyone elses questions,

but I'm having a strange problem that im scratching my head over,

I ...