Siddharth Bhansali
Siddharth Bhansali

Reputation: 11

Issues Printing a String in x86 Assembly

So I have this code (it displays "Enter your input: " and then when a user enters a character, it echos it back to them):

.model small
.stack 100h
.data
msg db 'Enter your input: $'

.code
start:
    mov     ah, 09h
    lea     dx, msg
    int     21h

    mov     ah, 1h
    int     21h

    mov     dl, al
    mov     ah, 2h
    int     21h

    mov     ax, 4c00h
    int     21h
end start

When I assemble it, it works, but before it says "Enter your input: ", it shows a bunch of random ASCII characters. Any Help? Thanks.

Upvotes: 1

Views: 1194

Answers (1)

Gunner
Gunner

Reputation: 5874

Hmm, Good ole DOS...

You need to set up the segment registers:

start:
    mov     ax, @data
    mov     ds, ax
    ...
    ...

Upvotes: 3

Related Questions