c - x86 转换为小写程序集

标签 c x86 inline-assembly

该程序是将char指针转换为小写。我使用的是 Visual Studio 2010。

这是来自另一个问题,但更容易阅读,也更直接切中要点。

int b_search (char* token)
{
__asm
{
mov eax, 0          ; zero out the result
mov edi, [token]      ; move the token to search for into EDI 
MOV ecx, 0

LOWERCASE_TOKEN:            ;lowercase the token
OR [edi], 20h
INC ecx
CMP [edi+ecx],0
JNZ LOWERCASE_TOKEN
MOV ecx, 0

在我的 OR 指令中,我试图将包含 token 地址的寄存器更改为全部小写,我不断收到未处理的异常...访问冲突,并且没有括号什么都没有,我不明白错误但没有小写。有什么建议吗? 这是另一个问题中一些更大代码的一部分,但我将其分解,因为我只需要这个解决方案。

最佳答案

您的代码只能更改第一个字符(或 [edi], 20h) - EDI 不会增加。

编辑:找到this thread与解决方法。尝试使用“dl”而不是 al。

; move the token address to search for into EDI
; (not the *token, as would be with mov edi, [token])

mov edi, token      

LOWERCASE_TOKEN:            ;lowercase the token
  mov al, [edi]
  ; check for null-terminator here !
  cmp al, 0
  je GET_OUT
  or al, 20h
  mov dl, al
  mov [edi], dl
  inc edi
jmp LOWERCASE_TOKEN
GET_OUT:

关于c - x86 转换为小写程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11656464/

相关文章:

c - 无法将字符串添加到 C 中的 LinkedList

使用左移和按位或将两个无符号字节组合成一个整数值

c - Arduino 电脑鼠标/输入设备

assembly - 从硬盘读取字符串并通过汇编打印到 TTY 选项

c - 在 x86 中使用 BIOS 中断

程序集 x86 : I have to program the Ackermann function

c - 如何将公钥存储为c数组

c++ - 有没有办法在 GCC 中禁用内联汇编程序?

assembly - Rust 组件 : how do I indicate that I need the value of the SP?

c - 在 GNU C 内联汇编中,单个操作数的 xmm/ymm/zmm 的大小覆盖修饰符是什么?