从用户读取一个字符串并存储它

时间:2014-10-27 21:19:20

标签: assembly

你好,我对组装很新,我仍然有点失去了一切如何工作无论我多少次阅读在线论坛或教程,它仍然相当模糊。所以我的第一个任务是从用户读取一个字符串并将其存储在数据段中。我还想假设字符串的长度不超过20个字符,并且用户永远不会输入超过20个字符。我该怎么做?我目前有:

mov ah, 0Ah         ; Function 0Ah Buffered input
mov dx, string_buf  ; ds:dx points to string buffer
int 21h

我不认为这会起作用......

2 个答案:

答案 0 :(得分:1)

这个DOS软件中断需要一个输入缓冲区。

            ; Example using Microsoft Macro Asssembler (MASM)

.MODEL small 
.STACK 100h

.DATA
BUFF DB 20
ACTR DB ?
ASCII 20 dup DB ("$")
DB "$" ; We needd to have one "$" for print function.

.CODE
START:
MOV AX, @DATA
MOV DS, AX
MOV AH, 0Ah          ; Function 0Ah Buffered input
MOV DX, OFFSET BUFF  ; ds:dx points to string buffer
INT 21h

MOV AH, 9            ; Print to output device
MOV DX, OFFSET ASCII ; ds:dx points to string
INT 21h

MOV AX, 4C00h        ; Return to DOS with ERRORLEVEL=0
INT 21h
END START

-

Ralf Browns x86/MSDOS Interrupt List(RBIL)
http://www.pobox.com/~ralf
http://www.pobox.com/~ralf/files.html
ftp://ftp.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/

inter61b.zip->INTERRUP.F
--------D-210A-------------------------------
INT 21 - DOS 1+ - BUFFERED INPUT
AH = 0Ah
DS:DX -> buffer (see #01344)
Return: buffer filled with user input
Notes:  ^C/^Break are checked, and INT 23 is called if either detected
reads from standard input, which may be redirected under DOS 2+
if the maximum buffer size (see #01344) is set to 00h, this call returns
immediately without reading any input
SeeAlso: AH=0Ch,INT 2F/AX=4810h

Format of DOS input buffer:
Offset  Size    Description (Table 01344)
00h BYTE    maximum character buffer can hold
01h BYTE    (call) number of chars from last input which may be recalled
    (ret) number of characters actually read, excluding CR
02h  N BYTEs    actual characters read, including the final carriage retur

答案 1 :(得分:-2)

我喜欢汇编语言,我很高兴你想学习它。但你似乎有点新鲜,我会建议买一本书。我认为一个好的是装配艺术和x86装配。也就是说,刚刚开始几天前就已经开始了,你的语法并不是装配工作的真正原因所以我保证你会在阅读其中一本书之后会好起来。