0

我正在尝试编写一个程序来从输入中读取字节字符串并将其存储为 ASCIIZ 格式(字符串以 结尾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
4

1 回答 1

0

您可以通过以下方式执行此操作(在 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

(注意这不是最优化的方法)

于 2013-01-14T18:34:02.743 回答