CE_
CE_

Reputation: 1118

Subtract of two char into rax

When I do :

endnf:
    add al, BYTE[rdi]
    sub al, BYTE[rsi]
    jmp end

When BYTE[rdi] = 116 and BYTE[rsi] = 122 the result is 250 instead of -6 because al = sizeof(char)

So I tried :

endnf:
    add rax, BYTE[rdi]
    sub rax, BYTE[rdi]
    jmp end

But I doesn't work :

nasm -f elf64 strcmp.s                            16:31:07
strcmp.s:24: error: invalid combination of opcode and operands

What should I do to subtract rdi[0] and rsi[0] ?

Upvotes: 2

Views: 374

Answers (1)

Sep Roland
Sep Roland

Reputation: 39411

The error stems from the fact that you should have written ... rax, qword ptr [...] to have operands of matching size.

I don't get why you wrote an add instruction to fetch the value at [rdi].

The simplest solution is:

mov   al, [rdi]
sub   al, [rsi]
movsx rax, al

If you wrote the next lines, you would have gotten the same result. It's silly but it does leave the same result in AL which as before can be extended to suit your needs.

mov   rax, [rdi]
sub   rax, [rsi]
movsx rax, al

Upvotes: 3

Related Questions