Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gmmastros on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

output doesn't display #

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I want to output a # value but instead I get a wierd symbol, I believe the ascii equivalent. I want the output to be "The value is 55" however I get "The value is *". Its more like a diamond than a *. This is what I have:

%title "Adding 1-10"

ideal

model small
stack 256

dataseg

sum dw 0
count dw 3
message db "The value is ", "$"
excode db 0

codeseg

Start:

mov ax, @data
mov ds, ax

mov ax, 1
mov bx, 2
add ax, bx ; ax = 3

add ax, [count] ; ax = 6

inc [count] ; count = 4
add ax, [count] ; ax = 10

inc [count] ; count = 5
add ax, [count] ; ax = 15

inc [count] ; count = 6
add ax, [count] ; ax = 21

inc [count] ; count = 7
add ax, [count] ; ax = 28

inc [count] ; count = 8
add ax, [count] ; ax = 36

inc [count] ; count = 9
add ax, [count] ; ax = 45

inc [count] ; count = 10
add ax, [count] ; ax = 55

mov [sum], ax ; sum = 55

lea dx, [message] ; move message's address into dx
mov ah, 9h ; function 9h is output string from dx
int 21h ; print the message

mov ax, [sum] ; print from ax
mov ah, 02h ; print one character
int 21h ; call!


Exit:
mov ah, 04Ch
mov al, [excode]
int 21h

end Start
 
There's this part of the code I want you to review:
mov ah, 02h ; print one character
int 21h ; call!

Okay, so now, what does that do? Does it output a number in ax in string form? Or does it output a character, expecting the number given as an ASCII code?

Perhaps you should remember that ah is part of ax and if you're loading a number into ax and THEN change ah, you can't expect ax to retain the higher half of its data.

The main problem some people encounter when first learning computers is the fact that to a computer, everything is numbers. Even text like this, composed of letters and sundry symbols, are composed of numbers as far as the computer is concerned. In your attempt to output the resulting number, you output the ASCII character equivalent of the number you got.

So, what do you think you ought to do BEFORE you attempt to output anything?
"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."
 
Ok, I'am not going to writE the code for you but here's the basic procedure to output any numeric value as a numeral(s).

1. save your value in a register, EAX for example.

2. Define a array to hold characters which will be your value. Each char of the array is 1 digit of the value you want to dispaly.

MyArray db 10 // an array of up to 10 elements

(Be sure your array is large enought for the hightest value you will need to display.)

3. Initialze your array to all 'sp' (space DEC = 32) not NULL or 0'

4. This is how I do it, there are other ways...

Loop through your value dividing it by 10 each time.

The remainder will be 1 digit of your value from the right each time through the loop.

Once you have a digit you must determine what ASCII value represents that digit. Here's the easy solution when converting from a binary value to a numeral:

Value + 48 (dec) = The ASCII value (binary) of the numeral/charactor. (You can look this up on an ASCII chart but I beleive this is correct)

Loop unitl the EAX = 0; jump out of the loop and continue with the next set

(Also, you may have to deal with negitives if the number can be signed. In this case determine if the nubmer is singed before starting the loop. Drop the sign from the value and start the loop).

Also keep in mind that you want to mov your numerals into the array from right to left, i.e. MyArray[8] = x, MyArray[7] = x etc. This will result in a right justified number filled with spaces. You can get fancy if you want and insert ',', '$' and whatever as you load the array.

Once you have done all this you have your value in the array. Now display a char string (you probably wnat to zero terminate the string at the last byte - MyArray[9] = 0.

Now either output a zero termianted string or output 1 character of the array at a time...whichever works best for you purposes.

Hope this helped...

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top