Sorry if these are naive questions - I have very little understanding of how C really works at the low level.
So I'm generating machine code to write to some mmap'd memory for execution. I'm confused about the use of hexadecimal literals for generating machine code.
Consider the assembly instruction (AT&T syntax): cmove %edx, %ecx
. This has the machine code representation 0x0F44CA
.
So, would doing something like:
char opcode[3] { 0x0F, 0x44, 0xCA };
represent the correct binary string under when 'under the hood'? I suspect it might not, since apparently hexadecimal literals in C are stored as integers. My concern is that, since integers are 32-bit, the actual values getting stored are
0x0000000F 0x00000044 0x000000CA
Which is something completely different from what I need.
Another concern I have is, does the type I give to the array affect the value actually being stored? So would
uint8_t opcode[3] { 0x0F, 0x44, 0xCA };
or
int opcode[3] { 0x0F, 0x44, 0xCA };
be any different from
char opcode[3] { 0x0F, 0x44, 0xCA };
under the hood?