.model small
.stack 1000h
.data
a db ?
b db ?
c db ?
sum db ?
prompt1 db 'baga un numar',13,10,'$'
prompt2 db 'mai baga unu ca nu te doare mana',13,10,'$'
.code
mov ax,@data
mov ds,ax
xor ax,ax
mov dx,OFFSET prompt1
mov ah,9
int 21h


xor ax,ax
int 16h

xor bx,bx

mov bx,ax
xor dx,dx
xor ax,ax
mov dx,OFFSET prompt2
mov ah,9
int 21h


xor ax,ax
int 16h

add bx,ax

xor dx,dx
xor ax,ax
mov dx,bx
mov ah,9
int 21h





mov ax,4c00h
int 21h
end


the program is supposed to read 2 numbers add them and print the result
yet it prints out a lot of trash characters

what am I doing wrong?
Posted on 2006-04-17 02:53:54 by para
para,
Lets deal with the issue one step at a time and see how we go.
1. You print a prompt of some sort.
2. You scan the keyboard with wait.
3. The result, in AX, is moved to BX (scan code and character)
4. You print another prompt
5. You scan the keyboard with wait.
6. You add the key to the key in BX
7. You try to print the result but you have not stored the value in a buffer that ends in a $.
    That is why it prints a lot of garbage

You need to create a 2 position buffer.  The first position will get the value in BH, the second position gets a $ for a terminatior.
Paul
Posted on 2006-04-17 06:50:24 by PBrennick

.model small
.stack 1000h

.data

prompt1 db 'baga un numar',13,10,'$'
prompt2 db 'mai baga unu ca nu te doare mana',13,10,'$'

.code

mov ax,@data
mov ds,ax

xor ax,ax
mov dx,OFFSET prompt1
mov ah,9
int 21h

xor ax,ax
int 16h

xor bx,bx

mov bh,ah
xor dx,dx

xor ax,ax
mov dx,OFFSET prompt2
mov ah,9
int 21h

xor ax,ax
int 16h

add bh,ah

xor dx,dx
xor ax,ax
mov bl,'$'
mov dx,bx
mov ah,9
int 21h





mov ax,4c00h
int 21h
end


I tryed followind your advice and  I added everything to bh and in bl I moved an '$'
I don't know if this is right I know it does not work
what should I do exactly? to make it work
Posted on 2006-04-17 07:51:50 by para
It is not right

prompt3  db  32,$

Store the value where the 32 is and then

and the code...
mov dx,OFFSET prompt3
mov ah,9
int 21h

will print it
Paul
Posted on 2006-04-17 08:20:00 by PBrennick

It is not right

prompt3  db  32,$

Store the value where the 32 is and then

and the code...
mov dx,OFFSET prompt3
mov ah,9
int 21h

will print it
Paul



I don't understand, how can I store the value where 32 is?
Posted on 2006-04-17 08:52:05 by para
store it - move it ;) to the address where 32 is (you see a addresss there? or a label naming that address?)
Posted on 2006-04-17 09:54:43 by rea

store it - move it ;) to the address where 32 is (you see a addresss there? or a label naming that address?)


I honestly don't follow sorry
Posted on 2006-04-17 13:05:57 by para
para,
This is the complete working program.  It has been tested and works correctly.  The project is also attached.
.Model small
.Stack 300h
.Data
prompt1 db 'baga un numar',13,10,'$'
prompt2 db 'mai baga unu ca nu te doare mana',13,10,'$'
prompt3 db 32,'$'

.code
Start:
mov ax,@data
mov ds,ax
xor ax,ax
mov dx,OFFSET prompt1
mov ah,9
int 21h

xor ax,ax
int 16h
xor bx,bx
mov bx,ax
xor dx,dx
xor ax,ax
mov dx,OFFSET prompt2
mov ah,9
int 21h

xor ax,ax
int 16h
add bx,ax
mov si,OFFSET prompt3
mov ,bl
mov dx,OFFSET prompt3
mov ah,9
int 21h

mov ax,4c00h
int 21h
end Start


Paul


Attachments:
Posted on 2006-04-17 16:26:02 by PBrennick
man this seems to only print out the ascii representation of the sum

I tryed doing sub bx,'0' but It doesn't seem to work

I was also wondering how I might modify this code to work with nubers not just digits and to print them out as well and maby also work with unsigned numbers  but ... first thing's first

Posted on 2006-04-19 21:31:16 by para
There was a 'nice', recursive function floating somewhere here which writes eax's contents in decimal system.
Posted on 2006-04-20 03:31:30 by ti_mo_n
It's just one thread below.

http://www.asmcommunity.net/board/index.php?topic=24594.0
Posted on 2006-04-22 06:47:20 by roticv