【问题标题】:ASCIIZ String Assembly 8086 (Replacing Character)ASCIIZ 字符串汇编 8086(替换字符)
【发布时间】:2015-04-18 07:58:55
【问题描述】:

我想从汇编语言 (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

【问题讨论】:

    标签: string assembly ascii x86-16


    【解决方案1】:

    您的输入缓冲区的字节值必须是缓冲区在第一个字节中可以容纳的最大字符数。加上另一个字节作为实际读取的字符数的占位符,并为字符串本身增加字节数。

    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 文件,我们必须设置数据段寄存器,并且我们也必须分配堆栈段。

    【讨论】:

    • Tasm 在第 16 行返回此错误:“Illegal instruction for current selected processor(s)”,即:“movzx di, [si]”。我使用 DOS*.com 文件。我该如何解决?
    • 对不起,这条指令不存在。但是我们可以用这两条指令来修复它:“mov al, [si]” + “movzx di,al”
    • 另一种变体:"xor ax,ax" + "mov al,[si]" + "mov di,ax"
    • 对不起,我不明白我必须使用的最终代码
    • 现在我已经编辑了上面答案的中间部分,用于计算回车字节的偏移地址以将其替换为零。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-25
    • 2019-12-29
    • 1970-01-01
    • 2015-02-26
    • 2013-01-08
    • 1970-01-01
    相关资源
    最近更新 更多