Considering a pared-down example of down-casting unsigned
to unsigned char
,
void unsigned_to_unsigned_char(unsigned *sp, unsigned char *dp)
{
*dp = (unsigned char)*sp;
}
The above C code is translated to assembly code with gcc -Og -S
as
movl (%rdi), %eax
movb %al, (%rsi)
For what reason is the C-to-assembly translation not as below?
movb (%rdi), %al
movb %al, (%rsi)
Is it because this is incorrect, or because movl
is more conventional, or shorter in encoding, than is movb
?