Need help with basic ASM

I am trying to convert some c code to assmebly and I need help.

char encode(char plain){
    __asm{
        mov eax, plain
        add eax, 2      
        ret
    }
    //C code
    /*
    char code;
    code = plain+2;

    return code;*/
}

The first problem is that the visual studio complains that the register size does not match, i.e. eax is too small / large for char. I got the impression that they were both FARDS. Also, if I leave the variable in eax and ret in the assembly, it really will return that variable, right?

+3
source share
4 answers

Yes, at least with most x86 C compilers (although this is not theoretically guaranteed) everything you put in [[e] a] x will be considered as a return value of 1/2/4 bytes.

No, char will not (usually) be a dword - it will be a byte.

char encode(char plaintext) { 
    __asm { 
        mov al, plaintext
        add al, 2
        leave
        ret
    }
}
+1

, c , - . , .

+2
  • C char , AL EAX ( ).
  • , RET . x86 , EAX.
+1

A char - 8 . eax - 32 , 4 , 16- , 32- . , , , , eax, , 32- .

0

Source: https://habr.com/ru/post/1742899/


All Articles