Reputation: 11
BITS 16
ORG 0x0100
SECTION .text
MAIN:
mov DI,array
call GetString
call Putln
call PutString
call Putln
mov SI,array
;jmp Next
;Next:
mov AX,4C00H
;mov AL,00H
int 21H
%INCLUDE 'STDIO.ASM'
SECTION .data
mesg db 'I','h','a','t','e','a','s','s','e','m','b','l','y' ;
SECTION .bss
array resb 256 ;reserve 256 bytes of space
Putch: ;outputs character in DL
push DI
mov AH,02H
int 21H
pop DI
ret
Getch: ;inputs a character into AL
push DI
; mov BH,AH
mov AH,08H
int 21H
; mov AH,BH
mov DL,AL
pop DI
ret
Putln: ;prints out a new line
mov AH,02H
mov DL,CR
int 21H
mov DL,LF
int 21H
ret
GetString:
call Getch
cmp DL,0DH
je End
call Putch
stosb
jmp GetString
End:
mov AL,00H
stosb
ret
PutString:
cld
lodsb
cmp AL,00H
jz End1
mov DL,AL
call Putch
jmp PutString
End1:
ret
SECTION .data
;mesg db 'I',' ','h','a','t','e',' ','a','s','s','e','m','b','l','y' ;
CR equ 0AH
LF equ 0AH
I am trying to output a string from array in 8086 assembly, but when I run it, even though I can input characters, when I press Enter it gives me symblols.
Upvotes: 1
Views: 2841
Reputation: 1428
I think your data segment register might not be set up correctly. As you're operating in real mode, it is good to start your program with
mov ax,.data ; The way this is done can vary between assemblers
mov ds,ax
Also, as long as I remember, DOS calls operate not with zero-terminated strings, but ones with '$' at the end, so the cause might be that you did not declare mesg
as follows:
mesg db 'I love assembly!$'
(Actually, you seem not to have the string terminted by any means)
Upvotes: 2