【问题标题】:8086 ASM - Output String to screen8086 ASM - 输出字符串到屏幕
【发布时间】:2013-04-09 09:37:37
【问题描述】:

我正在尝试从键盘获取输入,然后将其输出到屏幕。

我的代码;

    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 字符。

任何帮助将不胜感激!

【问题讨论】:

    标签: string assembly output x86-16


    【解决方案1】:

    我没有看到你在任何地方初始化DI。它可能应该设置为指向MyArray,就像SI 一样,否则您的STOSB 只会写入某个随机位置。

    【讨论】:

    • 哈哈谢谢迈克尔!我被困了好几个小时,我想它只是需要一双新的眼睛!它现在完美运行:) 谢谢!
    【解决方案2】:

    这些是您需要进行的唯一更改:

    ...
    ;;;;    mov SI, MyArray
        mov DI, MyArray ;;;; stosb uses DI
    
        call GetString
        call Putln
    
        mov SI, MyArray ;;;; lodsb uses SI
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2021-06-26
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多