Hello everybody. I ran into a problem programming x86 assembly and was hoping that you guy could help figure out what is wrong. The problem is with the code below. It should output W12 to the console when the enter key is pressed, very simple. The problem is that it outputs garbage. It outputs random characters and the program finishes.
I tried using the code below. Which is very similar just a few changes and it worked perfectly fine.
The first code is the way the professor taught us to structure the code(using SEGMENT, ENDS, etc.), so I am trying to make that work and the second is something I tried by looking up information on the internet.
Rich (BB code):
data SEGMENT
key db 0
msg db "W12$"
data ENDS
code SEGMENT
ASSUME CS: code, DS: data
mov ax, SEG data
mov ds, ax
start:
mov ah, 8 ; read key from keyboard
int 21h
mov key, al
cmp key, 13
JNZ start ; if key is not carriage return go to start
mov ah, 9
mov dx, OFFSET msg
int 21h
mov ah, 04ch
int 21h
code ENDS
END
Rich (BB code):
.model small
.data
key db 0
msg db "W12$"
.code
mov ax, SEG @data
mov ds, ax
start:
mov ah, 8 ; read key from keyboard
int 21h
mov key, al
cmp key, 13
JNZ start ; if key is not carriage return go to start
mov ah, 9
mov dx, OFFSET msg
int 21h
mov ah, 04ch
int 21h
END