我是汇编新手,正在为我的实验室工作,为汇编类。在这部分实验中,我需要将字符串转换为相反的大写字母。因此,例如:更改字母大小写(汇编x86)
如果给定的字符串
TheDonald
它应该返回
tHEdONALD
可以有时间或其他特殊字符,在这种情况下,我会离开独自一人。我也不允许使用32位寄存器。我应该只使用8位版本的x86通用寄存器。
到目前为止,我有这样的:
void changeCase(char *string)
{
__asm
{
// BEGIN YOUR CODE HERE
mov eax, string; // move the string into eax
mov ecx, 0; // ecx will be counter
BEGIN_LOOP:
cmp byte ptr[eax + ecx * 1], 0;
je END;
mov al, byte ptr[eax + ecx * 1]; // get the value of the current counter
cmp al, 65; // compare first char with A
jl NEXT_INDEX;
cmp al, 91;
jl UPPER_CASE;
cmp al, 97;
jl NEXT_INDEX;
cmp al, 123;
jl LOWER_CASE;
jmp NEXT_INDEX;
UPPER_CASE: // if upper case, make it lower case then go to next index
add al, 32;
mov byte ptr[eax + ecx * 1], al;
jmp NEXT_INDEX;
LOWER_CASE: // if lower case, make it upper case then go to next index
sub al, 32;
mov byte ptr[eax + ecx * 1], al;
jmp NEXT_INDEX;
NEXT_INDEX:
inc ecx;
jmp BEGIN_LOOP;
END:
// END YOUR CODE HERE
}
}
你不能指望人们编写代码或为你写一篇教程;这不是该网站的内容。开始,然后在有特定问题时回复。如果你不知道从哪里开始,你需要从老师那里得到帮助。 – Carcigenicate
Woops,用我的代码再次编辑帖子 – dppham1
回想一下,第5位(第6位)是7位ASCII中的**情况位**。你只需要改变这一点就可以影响案例。您可以使用'或'或'xor'来获得您的优势。 –