当前位置: 动力学知识库 > 问答 > 编程问答 >

ASCIIZ String Assembly 8086 (Replacing Character)

问题描述:

I want to delete and then add a character from an ASCII string in Assembly Language (8086). For example in the following code i want to delete the carriage return from the string and add the 0. As a matter of fact the interrupt 39h wants an ASCIIZ pathname but 0Ah adds a final carriage return character and not 0. How can I do it?

.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

网友答案:

Your input buffer must have a byte value of the maximum characters that the buffer can hold in the first byte. Plus another byte as a placeholder for the number of characters actually read and additional the amount of bytes for the string itself.

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

Example:

len = 10
Input_Buffer DB len, ?
folderpath   DB len+1 dup (" ")

After the input we can get the number of the characters for calculating the address of the carriage return and for to override it with a zero byte: Calculating the offset of the carriage return byte = offset of "folderpath" + the number of chars from last input + 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

This instruction(using Intel syntax) does not exist:

lea folderpath ,dx

Use this one instead:

lea dx, Input_Buffer
mov ah, 0ah
int 21h

Hint: for a DOS *.com file are: CS=DS=ES, but for a DOS *.exe file we have to set the data segment register and we have to allocate a stack segment too.

分享给朋友:
您可能感兴趣的文章:
随机阅读: