我想删除然后在汇编语言(8086)中添加ASCII字符串中的字符。例如,在下面的代码中,我想从字符串中删除回车并添加0.事实上,中断39h想要一个ASCIIZ路径名,但是0Ah添加了一个最终的回车符而不是0.我怎么能这样做?
.model tiny
.data
folderpath DB "",0
.code
org 0100h
inizio:
mov ah,0ah
lea folderpath ,dx
int 21h
; HERE I WOULD LIKE TO MODIFY THE STRING
lea dx, folderpath
mov ah,39h
int 21h
fine:
mov AH,4Ch
int 21h
end inizio
答案 0 :(得分:0)
您的输入缓冲区必须具有缓冲区可以在第一个字节中保存的最大字符的字节值。另外一个字节作为实际读取的字符数的占位符,并增加了字符串本身的字节数。
Format of DOS input buffer:
00h BYTE maximum characters 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 return
示例:
len = 10
Input_Buffer DB len, ?
folderpath DB len+1 dup (" ")
在输入之后,我们可以得到用于计算回车地址的字符数,并用零字节覆盖它: 计算回车字节的偏移量="文件夹路径"的偏移量+上次输入的字符数+ 1:
lea si, Input_Buffer + 1 ; offset of number of chars from last input
xor ax,ax ; set ax to zero
mov al,[si] ; get the number of chars from last input
mov di,ax ; put it into an address register
mov BYTE PTR[di+folderpath+1], 0 ; override the carriage return(0Dh) with a zero byte
此指令(使用Intel语法)不存在:
lea folderpath ,dx
改为使用这个:
lea dx, Input_Buffer
mov ah, 0ah
int 21h
提示:对于DOS * .com文件是:CS = DS = ES,但对于DOS * .exe文件,我们必须设置数据段寄存器,我们也必须分配一个堆栈段。