Skip to content

Instantly share code, notes, and snippets.

@tatsuru
Created November 30, 2011 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatsuru/1409187 to your computer and use it in GitHub Desktop.
Save tatsuru/1409187 to your computer and use it in GitHub Desktop.
cyclic shift
gcc -O3 -S shift.c
unsigned int cshift (const unsigned int src, const unsigned char shift) {
return (src >> shift) | (src << (sizeof(unsigned int)*8 - shift));
}
main() {
cshift(0xabcd, 3);
}
.file "shift.c"
.text
.p2align 4,,15
.globl cshift
.type cshift, @function
cshift:
.LFB0:
.cfi_startproc
movzbl %sil, %eax
movl $32, %ecx
subl %eax, %ecx
movl %edi, %eax
sall %cl, %eax
movl %esi, %ecx
shrl %cl, %edi
orl %edi, %eax
ret
.cfi_endproc
.LFE0:
.size cshift, .-cshift
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB1:
.cfi_startproc
rep
ret
.cfi_endproc
.LFE1:
.size main, .-main
.ident "GCC: (Debian 4.6.2-5) 4.6.2"
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment