[英]8086 ASM - Output String to screen
我正在嘗試從鍵盤獲得輸入,然后將其輸出到屏幕。
我的代碼;
BITS 16 ;Set code generation to 16 bit mode
ORG 0x0100;
SECTION .text;
MAIN:
mov SI, MyArray
call GetString
call Putln
call PutString
jmp Exit;
GetString:
call Getch ; get the character stored in DL
cmp dl, 0dh ; if Enter is pressed Exit the subroutine
je Return
; call Putch ;*commeted out to see if putsring works* ; output the character on screen
stosb ; store the character in al to [di] and increment di by 1
jmp GetString ; loop back to GetString
Return:
mov al, 0 ; terminate array with a 0
stosb
ret
PutString:
cld
lodsb ; load the character in [si] to al and increment si by 1
cmp al, 0
jz Return2
mov dl, al
call Putch
jmp PutString ; loop back to PutString
Return2:
Ret
Getch:
push di
mov ah, 7 ; keyboard input subprogram without echo
int 21h ; read the character into al
mov dl, al
pop di
RET ; return
Putch:
push di
mov ah, 2h ; display subprogram
INT 21H ;read the characters from al
pop di
RET ; Return
Putln: ;new line
mov ah, 2
mov dl, 0DH ;Carriage return
int 21h
mov dl, 0AH ;Line feed
int 21H
RET ; return
Exit:
MOV AH,04Ch ; Select exit function
MOV AL,00 ; Return 0
INT 21h ; Call the interrupt to exit
SECTION .bss
MyArray resb 256
但是我不能讓PutString正常工作。 無論在鍵盤上鍵入什么,它都將打印相同的ASCII字符。
任何幫助,將不勝感激!
我看不到您在任何地方初始化DI
。 可能應該像SI
一樣將其設置為指向MyArray
,否則您的STOSB
只會寫到某個隨機位置。
這些是您需要進行的唯一更改:
...
;;;; mov SI, MyArray
mov DI, MyArray ;;;; stosb uses DI
call GetString
call Putln
mov SI, MyArray ;;;; lodsb uses SI
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.