Elad Kobi
Elad Kobi

Reputation: 21

Assembly printing a variable

So I am working on a little code in Assembly and I was wonder how can I print a message to the user the include a variable.

For example:

Upvotes: 0

Views: 10964

Answers (1)

Sep Roland
Sep Roland

Reputation: 39676

I know how to print a string, but I don't know to to enter the variable into the string so I could print it all together

a - Prepare your string so it has an appropriate amount of free space available.

msg     db      'Value is       $'

b - Position an output pointer near the end of the string. In this example it'll be pointing at the $ character.

        lea     di, [msg + 14]

c - Move your variable to the AX register.

        mov     ax, [variable]

d - Call following number to text conversion/insertion routine.

; IN (ax,di)
        mov     bx, 10
More:   xor     dx, dx
        div     bx         ; This divides DX:AX by BX
        dec     di
        add     dl, '0'    ; Turn remainder into a character
        mov     [di], dl   ; Write in string
        test    ax, ax
        jnz     More
        ret

e - Print the whole string at once. You know this already...


For further info read Displaying numbers with DOS

Upvotes: 1

Related Questions