X86装配转换小写为大写 [英] X86 Assembly Converting lower-case to uppercase

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

问题描述

实现在一个字符串小写字母转换功能TOUPPER
为大写。这个函数有一个参数:字符*字符串。字符串是一个
char类型的指针,它指向字符串的开头。因为C-
风格的字符串由零终止,我们并不需要采取的长度
字符串作为另一个参数。

我需要帮助起步,我不知道我在做什么!

无效TOUPPER(字符*字符串){
__asm​​ {
        PUSH EAX
        PUSH EBX
        PUSH ECX
        PUSH EDX
        PUSH ESI
        PUSH EDI        MOV EBX,串
        / *您code开头这条线之下。 * /
        / *您code上面这行结束。 * /
        POP EDI
        POP ESI
        POP EDX
        POP ECX
        POP EBX
        POP EAX
    }
}


解决方案

您需要将每个字符装入8位寄存器(MOV AL,[EBX]),检查是否达到结束的字符串,决定是否需要转换(与边界'一'比较AL ..'Z')和移动相应的大写字母回[EBX]如果是。然后增加EBX和环回。

 大写字母'A'..的ASCII code'Z'是0x41..0x5A
小写字母'A'..'Z'ASCII code是0x61..0x7A

这样的情况下可以通过从小写字母减去0x20的改变,
或者通过屏蔽掉第5位(和AL,0xDF)。

Implement the toUpper function that converts lower-case letters in a string to upper-case. The function takes one parameter: char *string. string is a char type pointer, which points to the beginning of the string. Because C- style strings are terminated by a zero, we do not need to take the length of the string as another parameter.

I need help getting started, I don't know what I am doing!!

void toUpper(char *string) {
__asm{
        PUSH EAX
        PUSH EBX
        PUSH ECX
        PUSH EDX
        PUSH ESI
        PUSH EDI

        MOV EBX, string
        /* Your code begins below this line. */


        /* Your code ends above this line. */
        POP EDI
        POP ESI
        POP EDX
        POP ECX
        POP EBX
        POP EAX
    }
}

解决方案

You need to load each character into 8bit register (MOV AL,[EBX]), check if end-of-string is reached, decide whether it needs to be converted (compare AL with boundaries 'a'..'z') and move the corresponding uppercase letter back to [EBX] if yes. Then increment EBX and loop back.

ASCII code of uppercase letter 'A'..'Z'  is 0x41..0x5A
ASCII code of lowercase letter 'a'..'z'  is 0x61..0x7A

so the case can be changed either by subtracting 0x20 from lowercase letter, or by masking off the 5th bit (AND AL,0xDF).

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

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