如何在程序集中迭代char *

时间:2014-02-05 05:58:14

标签: assembly masm

我是汇编语言的新手。我的问题很简单,如何使用汇编语言中的循环迭代未知大小的char *?一个例子就是很棒。谢谢!

1 个答案:

答案 0 :(得分:-1)

如果您在下面的汇编代码中将char*称为bytes,则可以执行以下操作:

mov cl, 0             ; cl is the counter register, set it to
                      ; zero (the first character in the string)

start:                ; Beginning of loop
  mov al, bytes[cl]   ; Read the next byte from memory

  cmp al, 0           ; Compare the byte to null (the terminator)
  je end              ; If the byte is null, jump out of the loop

  sub al, 20h         ; Convert to upper case
                      ; A better solution would be: and al, 0DFh

  ; Output the character in al

  add cl, 1           ; Move to the next byte in the string
  jmp start           ; Loop
end: