I wanted to create a simple program in Emu8086 Assembly Language that will prompt the user for a value. 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.
This is how you solve it.
BL
and BH
.DL
. There's no need to use the longer DX
register here.call
when needed.lea dx, SomeLabel
instructions get a shorter encoding (from 4 bytes to 3 bytes) if you write mov dx, offset SomeLabel
.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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.