简体   繁体   English

如何在 Emu8086 汇编语言中显示用户的输入

[英]How to display the user's input in Emu8086 Assembly Language

I wanted to create a simple program in Emu8086 Assembly Language that will prompt the user for a value.我想用 Emu8086 汇编语言创建一个简单的程序,它会提示用户输入一个值。 Then it will display the user's value.然后它将显示用户的价值。 After displaying the user's value, it will display a message.显示用户的值后,将显示一条消息。 However, my problem is I couldn't display the user's value.但是,我的问题是我无法显示用户的价值。 Here's my code:这是我的代码:

org 100h
            
.model small
            
.data

a db "Enter your favorite number; $"

b db "Your favorite number is $"     

c db "My favorite song is Blinding Lights by The Weeknd$"

.code

mov ax,@data
mov ds, ax
             
             
;Displaying a             
lea dx,a
mov ah,09h
int 21h

;User input
mov ah,01
int 21h                        
mov ah,01
int 21h                        

;Newline                     
mov dx,13
mov ah,2
int 21h  
mov dx,10
mov ah,2
int 21h
            
;Displaying b 
lea dx,b
mov ah,09h
int 21h    
 
;Displaying User's input 
mov dl,al
mov ah,2h
int 21h
mov dl,al
mov ah,2h
int 21h
        
;Newline                     
mov dx,13
mov ah,2
int 21h  
mov dx,10
mov ah,2
int 21h      
      
;Displaying c
lea dx,c
mov ah,09h
int 21h



ret

Michael already told you the problems with your code. Michael 已经告诉过您代码的问题。
This is how you solve it.这就是你解决它的方法。

  • The inputted characters that you get from the DOS.GetCharacter function 01h need to be stored somewhere.您从 DOS.GetCharacter function 01h 获得的输入字符需要存储在某处。 In this simple program you can use a couple of byte-sized registers like BL and BH .在这个简单的程序中,您可以使用几个字节大小的寄存器,例如BLBH
  • To output a newline (carriage return 13 and linefeed 10), you can set these values in the register DL .给 output 换行(回车 13 和换行 10),您可以在寄存器DL中设置这些值。 There's no need to use the longer DX register here.此处无需使用较长的DX寄存器。
  • And since you should not repeat yourself, you should place that newline code in a subroutine that you can call when needed.并且由于您不应该重复自己,您应该将该换行代码放在一个您可以在需要时call的子例程中。
  • Those lea dx, SomeLabel instructions get a shorter encoding (from 4 bytes to 3 bytes) if you write mov dx, offset SomeLabel .如果您编写mov dx, offset SomeLabel ,那些lea dx, SomeLabel指令将获得更短的编码(从 4 个字节到 3 个字节)。
mov ax, @data
mov ds, ax

;Displaying a             
mov dx, offset a
mov ah, 09h
int 21h

;User input
mov ah, 01h
int 21h                    
MOV BH, AL
mov ah, 01h
int 21h                       
MOV BL, AL

call Newline
            
;Displaying b 
mov dx, offset b
mov ah, 09h
int 21h    
 
;Displaying User's input 
mov dl, BH
mov ah, 02h
int 21h
mov dl, BL
mov ah, 02h
int 21h

call Newline
      
;Displaying c
mov dx, offset c
mov ah, 09h
int 21h

ret

Newline:
  mov DL, 13
  mov ah, 02h
  int 21h  
  mov DL, 10
  mov ah, 02h
  int 21h
  ret

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM