Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

c - x86 convert to lower case assembly

This program is to convert a char pointer into lower case. I'm using Visual Studio 2010.

This is from another question, but much simpler to read and more direct to the point.

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

At my OR instruction, where I'm trying to change the register that contains the address to token into all lower case, I keep getting unhandled exception...access violation, and without the brackets nothing, I don't get errors but nothing gets lowercased. Any advice? This is part of some bigger code from another question, but I broke it down because I needed this solution only.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your code can alter only the first char (or [edi], 20h) - the EDI does not increment.

EDIT: found this thread with workaround. Try using the 'dl' instead of 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:

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...