遍历内存编辑每个字节(Iterate through memory editing each byte)

编程入门 行业动态 更新时间:2024-10-27 07:27:48
遍历内存编辑每个字节(Iterate through memory editing each byte)

我正在编写汇编代码,提示用户输入一个小写字符串,然后用所有UPPER-CASE字符输出相同的字符串。 我的想法是遍历从特定地址开始的字节,并从每个字节中减去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!

最满意答案

通常,字符串以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:

更多推荐

本文发布于:2023-08-04 14:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1417617.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:遍历   字节   内存   编辑   byte

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!