×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

output doesn't display #

output doesn't display #

output doesn't display #

(OP)
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

RE: output doesn't display #

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."

RE: output doesn't display #

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close