[英]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.这就是你解决它的方法。
BL
and BH
.在这个简单的程序中,您可以使用几个字节大小的寄存器,例如BL
和BH
。DL
.给 output 换行(回车 13 和换行 10),您可以在寄存器DL
中设置这些值。 There's no need to use the longer DX
register here.此处无需使用较长的DX
寄存器。call
when needed.并且由于您不应该重复自己,您应该将该换行代码放在一个您可以在需要时call
的子例程中。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.