Here is the simple program for addition when running in tasm it gives some garbage value and I cannot figure out what is the error hi Please any help will be apperetated Thank you

.model small
 opr1 dw 1234h
 opr2 dw 0100h
 result dw 001 dup(?),'$'
        mov ax,@data
        mov ds,ax
        mov ax,opr1
        mov bx,opr2
        add ax,bx
        mov di,offset result
        mov [di], ax

        mov ah,09h
        mov dx,offset result
        int 21h

        mov ah,4ch
        int 21h
4 Years
Discussion Span
Last Post by DeanMSands3

There are a number of issues with this code, but the main one is that you are trying to write out an integer with a DOS call that is for writing strings. You need to convert the value of the result to an ASCII string in order to display it with that AH 09h call (unfortunately, there isn't any DOS routine for printing an integer).

The first thing you need to do is change the result variable so that it is large enough to hold a string representation of a 16-bit integer:

result dw 5 dup(?),'$'  ; reserve 5 chars and add a dollar sign at the end

The harder part is writing the routine to convert a decimal to a string. The general algorithm, as written in Python, can be found here; writing it in TASM is left to you to do.


Isn't there any other way to convert value to ASCII String ?

Edited by dendenny01


If you really want to convert the number to a string, you can do this:
Since you're using the Borland Turbo Programming set, you could write a simple snippet in Turbo C without using any of the libraries, then turn on Assembly generation when compiling.

This will give you an assembly code file you can use as a reference.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.