1

我正在使用 MASM 程序集,我正在尝试编写一个循环来逐字节处理字符串 str1,使用位操作将每个小写字母更改为相应的大写字母。如果字母已经是大写字母,请不要理会它。当我执行我的代码时,我的字符串 str1 似乎没有发生任何事情,我很难弄清楚为什么,也许我不应该这样处理我的数组,但是,这里是代码:

        .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”。任何询问将不胜感激!提前致谢。

4

2 回答 2

2

您必须加载角色,对其进行处理,然后将其存储回来。你不存储它。

就像是:

mov [esi+ebx], al

不见了。

为什么你从 char 分 0x20?为什么要在 esi 上加 5?

更新

在开始编码之前,您应该考虑所需的步骤是什么。

  1. 加载角色。
  2. 如果字符为 0,则字符串完成。
  3. 如果字符是大写,则转换它
  4. 存储字符
  5. 前进到下一个字符并返回 1

而已。现在,当您查看代码示例时,您可以很容易地看到缺少什么以及哪里出错了。

于 2013-05-18T09:01:11.547 回答
0

可以帮到你一点

    .writeLoop2
    mov eax,[ebx]         ;mov eax start of data block [ebx]
    cmp al,&61             ;61hex is "a"
    jb dontsub20           ;if its less don't bother because it's a CAPITAL letter
    sub al,&20             ;else take off 20 hex
    .dontsub20 
    call "osasci"          ;print to screen command. Output the character in eax
    inc ebx                ;move ebx forward to next character
    inc ecx                ;ecx is the rolling count
    cmp ecx,edx            ;when ecx=edx we are at the end of the data block
    jb writeLoop2           ;otherwise loop, there are more characters to print
于 2013-05-18T13:02:34.617 回答