我正试图编写一个程序从输入读取字节字符串并以ascii格式存储它(字符串以0
结束)。下面是我到目前为止的代码;在我读取字符串后,我不知道如何访问字符串中的最后一个字节并将其设置为0
。
READ_ASCIIZ PROC
PUSH BP
MOV BP, SP
MOV AH, 0AH
MOV DX, 4H[BP]
INT 21H
POP BP
RET 2H
READ_ASCIIZ ENDP
您可以用以下方式(使用nasm语法,未经测试):
; saved modified registers
push bx
push si
; get pointer to buffer
mov si, [bp+4]
; grab number of chars read
; (zero-extending as the length is stored as a byte)
movzx bx, byte [si+1]
; write zero at end of character buffer (overwriting the newline)
; (+2 since that's were the buffer starts)
mov byte [si+bx+2], 0
; restore registers
pop si
pop bx
(注意这不是最优化的方式)