Assembly 将摄氏度转换为华氏度
但它只接受1个字符,我需要它至少4个字符,并且此代码不显示结果。DOS函数1(int 21h)只从键盘输入一个字符。您需要函数0Ah,它是缓冲输入Assembly 将摄氏度转换为华氏度,assembly,x86-16,Assembly,X86 16,但它只接受1个字符,我需要它至少4个字符,并且此代码不显示结果。DOS函数1(int 21h)只从键盘输入一个字符。您需要函数0Ah,它是缓冲输入 org 100h .MODEL SMALL .STACK 200 .DATA crlf DB 0dh,0ah,"$" prompt1 DB "Enter celcius:","$" prompt2 DB "In Fahrenheit:","$" prompt3 DB ".","$" result DB ? c DB ? x1 D
org 100h
.MODEL SMALL
.STACK 200
.DATA
crlf DB 0dh,0ah,"$"
prompt1 DB "Enter celcius:","$"
prompt2 DB "In Fahrenheit:","$"
prompt3 DB ".","$"
result DB ?
c DB ?
x1 Dw ?
y DW 8
x DW 1
z dw 10
.code
.startup
lea dx,prompt1
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,30h
mov c,al
lea dx,crlf
mov ah,09h
int 21h
mov al,c
mul x
mov x1,ax
mov al,c
mul y
idiv z
add al,c
add al,32
mov result,al
lea dx,prompt2
mov ah,09h
int 21h
mov dl,result
add ah,02h
int 21h
.exit
end
抱歉,我被搞糊涂了,那么我要怎么做才能运行这个程序呢?用函数01h(
mov-ah,01h;int-21h
)从键盘上读取一个字符(这是你的主要问题,不是吗),你可以用函数0Ah(mov-ah,0Ah
)并将指向缓冲区的指针设置为DS:DX
),以便从键盘读取多个字符。用户使用键盘输入字符后,输入的字符从位置(DS:DX)+2开始存储在内存中。输入的字符数位于位置DS:DX。因此,您拥有用户键入的字符串。然后您必须将这个字符串转换成一个数字(以摄氏度表示温度)。我强烈建议您对代码的不同部分进行注释。总的来说,这非常重要,但对大会来说至关重要。
Buffered Keyboard Input
AH = 0Ah
DS:DX = pointer to input buffer of the format:
max count BUFFER (N bytes)
count = number of characters returned (byte)
max = maximum number of characters to read (byte)
returns nothing
- N bytes of data are read from STDIN into buffer+2