将小写字母字符串转换为大写字母 [英] Converting lowercase character string to uppercase masm

查看:188
本文介绍了将小写字母字符串转换为大写字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一条printf语句,告诉编译器打印outStr. outStr最初设置为等于emptybuf [1000] ="???尚未翻译???";.我应该将答案移至outStr,后者应更新print语句中的outStr.

there is a printf statement which tells the compiler to print outStr. outStr is originally set to equal emptybuf[1000] = "??? not translated yet ???";. I am supposed to move my answer into the outStr, which should update the outStr in the print statement.

由于某种原因,我的内联程序集无法从下面显示的代码中打印出任何内容.我不明白我在做什么错.我正在尝试将小写字母转换为大写字母,并忽略任何特殊字符.任何建议都将不胜感激.

For some reason my inline assembly will not print out anything from the code shown below. I cannot understand what I am doing wrong. I am trying to convert lowercase letters to uppercase, and ignore any special characters. Any advice is much appreciated.

mov esi,inStr ;To start off initialize  esi point to input string
mov edi,outStr  ;edi point to the output string area

    ; using esi and edi with [esi] and [edi] as indirect operand

    ; suggestion  to start mov each character to al  like   -->  mov al,[esi]
    ; test, and manipulate character in al


        jmp getNext         
getNext: mov al,[esi]
    cmp al,0
 je exitProc
        test al,01100000b ;test to see if its a lowercase letter
        je toUpperCase
        test al,01000000b
        mov [edi],al
        inc esi
toUpperCase: test al,01000000
         AND al,11011111b
         mov [edi],al
         inc esi
         jmp getNext
exitProc: mov outStr, edi

推荐答案

这里有很多错误,因此我将尝试分别解释每个部分.

There is a lot wrong here, so I'll try and explain each section separately.

首先,小写字母的测试(测试01100000b)将无法正常工作.无论哪种情况,它都永远不会为零,因为它们都设置了第6位.

First, the test for lowercase (testing 01100000b) isn't going to work. It'll never be zero, for either case, since they both have the 6th bit set.

如果认为确保只将"a"大写为"z"的唯一方法是显式比较该范围内的字符.因此,您的第一个测试将变成这样:

If think the only way to make sure you're only uppercasing 'a' to 'z' is to explicitly compare for characters in that range. So your first test becomes something like this:

    cmp al,'a'
    jl noChange
    cmp al,'z'
    jle toUpperCase
noChange:
    mov [edi],al
    ...

然后,您在mov [edi],al之前拥有的其他test al,01000000b无效,因此可以将其删除.

Then the additional test al,01000000b you had before mov [edi],al does nothing, so that can be removed.

将字符复制到已经大写的分支中后,您应该跳到循环的顶部,否则您将陷入toUpperCase分支中并再次存储该字符时间.

And once you've copied the character in the branch that is already uppercase, you should be jumping to the top of the loop, otherwise you're going to fall through to the toUpperCase branch and store the character a second time.

另外,您应该增加edi,否则您将一遍又一遍地写到相同的位置.

Also you should be incrementing edi, otherwise you're going to write to the same position over and over again.

    mov [edi],al
    inc edi     ; You need to add this
    inc esi
    jmp getNext ; You need to add this

toUpperCase分支也是如此.您需要增加edi,然后又有一个不执行任何操作的测试.

Same thing goes for the toUpperCase branch. You need to increment edi, and again you have a test there that does nothing.

toUpperCase:
     AND al,11011111b
     mov [edi],al
     inc edi   ; Add this
     inc esi
     jmp getNext

最后,退出时,您需要在outStr的末尾添加一个NULL.不需要将edi分配回outStr,尤其是因为它现在指向字符串的末尾.

Finally, when exiting, you need to add a NULL to the end of the outStr. And there is no need to assign edi back to outStr, especially since it is now pointing to the end of the string.

exitProc:
     mov [edi],0

现在,由于您也有很多重复的代码,因此可以提高效率.但这就是要完成工作所要做的全部工作.

Now this could be made more efficient, in that you have a lot of repeated code as well. But that is all that has to be done to get it working.

这篇关于将小写字母字符串转换为大写字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆