在MASM程序集中逐字节循环和处理字符串 [英] Looping and processing string byte-by-byte in MASM assembly
问题描述
我正在使用MASM汇编,并且正在尝试编写一个逐字节处理字符串str1的循环,使用位操作将每个小写字母更改为相应的大写字母.如果这封信已经是大写字母,那就别说了.当我执行代码时,字符串str1似乎什么都没发生,并且我很难弄清为什么,也许我不应该这样处理我的数组,但是尽管如此,这还是代码:
I am using MASM assembly and I am trying to write a loop that processes the string str1 byte-by-byte, changing each lowercase letter into the corresponding capital letter using bit operations. If the letter is already capital, leave it alone. Nothing seems to happen to my string str1 when I execute my code and I'm having difficulty figuring out why, maybe I shouldn't be processing my array as such, but nonetheless, here's the code:
.386
.MODEL FLAT
str1 dword "aBcD", cr, Lf, 0
....
.code
_start:
output str1
**sub esi, esi ; sum = 0
lea ebx, str1
top: mov al, [ebx + esi] ; attempting to move each character value from
str1 into the register al for comparison and
possible conversion to uppercase
add esi, 5
cmp al, 0
je zero
sub al, 20h** ; convert lowercase to corresponding uppercase
loop top
zero: output zeromsg ; for TESTING of al purposes only
done: output str1value
output str1
没有任何变化,并且在转换未进行的最上面,它以相反的顺序打印字符串.为什么?打印为:"DcBa".任何查询将不胜感激!预先感谢.
Nothing changes , and on top of the conversion not taking place, the string it printing in reverse order. why? prints out as: "DcBa". Any inquiry would be appreciated! Thanks in advance.
推荐答案
您必须加载,处理字符并将其存储回去.您不存储它.
You must load the character, process it, and store it back. You don't store it.
类似的东西:
mov [esi+ebx], al
丢失.
您为什么从char中减去0x20?为什么将5加到esi?
Why do you sub 0x20 from the char? And why do you add 5 to esi?
更新
在开始编码之前,您应该考虑所需的步骤.
Before you start coding, you should think about what the required steps are.
- 加载角色.
- 如果字符为0,则表示字符串已完成.
- 如果字符是大写字母,请将其转换
- 存储字符
- 前进到下一个字符并返回1
就是这样.现在,当您查看代码示例时,可以轻松地看到缺少的内容和出了问题的地方.
That's it. Now when you look at your code example, you can easily see what is missing and where you go wrong.
这篇关于在MASM程序集中逐字节循环和处理字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!