assemblyx86conditional-move

Invalid combination of opcodes and operands when cmov pointer and register


I want to write a piece of code in assembly language, that would change all uppercase characters in a string to lowercase. However, I would like to avoid as many conditional jumps as possible. I tried the following code:

    global tolower_cmov

tolower_cmov:
    enter 0, 0
    mov edx, [ebp + 8]
    xor eax, eax
    xor ecx, ecx
.back:
    test [edx], byte 0xff
    jz .end

    mov eax, [edx]
    mov ecx, [edx]
    add [eax], byte 'a' - 'A'
    cmp [edx], byte 'A'
    cmovb [edx], eax
    cmp [edx], byte 'z'
    cmova [edx],  ecx

    inc edx
    jmp .back
.end:
    leave
    ret

But NASM gives me Invalid combination of opcodes and operands error on both CMOV lines... I don't understand, what is wrong with those lines?


Solution

  • With the help of Michael, I have managed to find a solution, that suits my needs:

        global tolower_cmov
    
    tolower_cmov:
        enter 0, 0
        mov edx, [ebp + 8]
    .back:
        test [edx], byte 0xff
        jz .end
    
        xor eax, eax
        xor ecx, ecx
    
        mov eax, [edx]
        mov ecx, [edx]
        add ecx, dword 'a' - 'A'
        cmp [edx], byte 'A'
        cmovb ecx, eax
        cmp [edx], byte 'Z'
        cmova ecx, eax
        mov [edx], ecx
    
        inc edx
        jmp .back
    .end:
        leave
        ret