我想知道如何读取char并从汇编中的char输出循环?

时间:2013-09-25 08:26:24

标签: assembly x86

我目前正在使用emu8086上课,我对汇编语言很新。我创建了一个asm程序来显示前14个字母的字母表。我想知道如何从编译和运行执行的命令提示符中读取输入中的char。我在想循环中的循环。 到目前为止,这是我的代码:

include emu8086.inc

org 100h

 MOV CX, 14                 

 MOV AH, 2                      
 MOV DL, 65


 LOOPA-N:                       
   INT 21H                    

   INC DL
   ;INC CH
  ; CMP CH, 14  

  Loop LoopA-N

  ; JNZ LOOPA-N

 MOV AH, 03H
 INT 10H

 MOV AL, 0AH
  MOV AH, 0EH
  INT 10H

  MOV AL, 0DH
  MOV AH, 0EH
  INT 10H

 PRINTN 'Would you like to continue? '
 PRINTN 'Press c to continue ' 
 PRINTN 'Press r to start over, clear the screen, and print in the reverse order, from Z to A '
 PRINTN 'Press x to exit ' 


 c:
 MOV CX, 12
 MOV AH, 2
 MOV DL, 79
 LOOPO-Z:

 INT 21H
 INC DL

 Loop LOOPO-Z


 call GET_STRING


 mov Dl, 0DH
 INT 21H

 MOV DL, 0AH
 INT 21H

 MOV DH, 02H
 INT 10H

 MOV AH, 4CH                  
 INT 21H

 ret
END

1 个答案:

答案 0 :(得分:0)

循环中不需要循环来等待按下某个键。以下是如何执行此操作的示例(在NASM语法中):

org 0x100

wait_for_input:
  mov dx,msg        ; Display the prompt
  mov ah,9
  int 21h

  mov ah,1          ; READ CHARACTER FROM STANDARD INPUT, WITH ECHO
  int 21h
  cmp al,'c'        ; The character is returned in AL
  je continue
  cmp al,'r'
  je restart
  cmp al,'x'
  je exit
  jmp wait_for_input   ; Try again

continue:
; Do whatever needs to be done here

restart:
; Do whatever needs to be done here

exit:
mov ax,04c00h
int 21h

msg db 13,10,"Press c, r or x: $"
所有INT 21H函数的

Here's a reference,以备不时之需。 INT 10H为{{1}}。{/ p>


顺便说一下,你对程序结束时调用的中断函数的寄存器内容做了很多假设。我建议您正确设置所有这些函数使用的寄存器 - 以使代码更具可读性。