遍历内存编辑每个字节

发布于 2024-12-07 12:52:16 字数 198 浏览 0 评论 0原文

我正在编写汇编代码,提示用户输入一串小写字符,然后输出包含所有大写字符的相同字符串。我的想法是迭代从特定地址开始的字节,并从每个字节中减去 20H(将小写变为大写),直到到达具有特定值的字节。我对 Assembly 相当缺乏经验,所以我不确定这样的循环的语法是什么样的。

谁能提供一些示例代码或指导我在哪里可以找到此类语法的示例?

非常感谢任何帮助!

I'm writing assembly code that prompts the user for a string of lower-case characters then outputs the same string with all UPPER-CASE characters. My idea is to iterate through the bytes starting at a specific address and subtract 20H (turns a lower case to upper-case) from each one until I reach a byte with a specific value. I'm fairly inexperienced with Assembly so I'm not sure what the syntax for such a loop would look like.

Can anyone provide some sample code or direct me where I can find examples of such syntax?

Any help is greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏剧牡丹亭 2024-12-14 12:52:16

通常,字符串以 null(十六进制的 0x00)结尾。假设这就是您选择执行的操作,下面是一些示例代码。我不确定您使用的是哪种汇编器,甚至不确定哪种语法,但是这个 x86 代码应该在 MASM 中工作:

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:

Typically, a string is terminated with a null (0x00 in hex). Assuming this is what you choose to do, here's some sample code. I'm not sure which assembler you're using, or even which syntax, but this x86 code that should work in MASM:

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:
你げ笑在眉眼 2024-12-14 12:52:16

好吧,一个简洁的(但不是当前处理器性能的最佳选择)是:

  • 使用某种类型的计数器来控制循环
  • 点 ds:si 和 es:di 在开始时
  • 执行 lodsb、al、dfh、stosb 序列在循环中

Well, one concise (but not optimal for performance on current processors) choice would be:

  • have a counter of some type to control the loop
  • point ds:si and es:di at the beginning
  • do a lodsb, and al, dfh, stosb sequence in the loop
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文