Created
November 30, 2011 14:08
-
-
Save tatsuru/1409187 to your computer and use it in GitHub Desktop.
cyclic shift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gcc -O3 -S shift.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned int cshift (const unsigned int src, const unsigned char shift) { | |
return (src >> shift) | (src << (sizeof(unsigned int)*8 - shift)); | |
} | |
main() { | |
cshift(0xabcd, 3); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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