Last active
September 19, 2016 03:54
-
-
Save MichaelNecio/0158f2cbaa95d678babcbab527eaa57a to your computer and use it in GitHub Desktop.
Problem of the Week 1, What's up with compilers?
This file contains 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
#include <string.h> | |
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
uint32_t ip; | |
scanf("%u", &ip); | |
uint8_t octets[4]; | |
memcpy(octets, &ip, sizeof(ip)); | |
printf("%u.%u.%u.%u\n", octets[3], octets[2], octets[1], octets[0]); | |
return 0; | |
} | |
~ |
This file contains 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 "memcpyIP.c" | |
.section .rodata.str1.1,"aMS",@progbits,1 | |
.LC0: | |
.string "%u" | |
.LC1: | |
.string "%u.%u.%u.%u\n" | |
.section .text.unlikely,"ax",@progbits | |
.LCOLDB2: | |
.section .text.startup,"ax",@progbits | |
.LHOTB2: | |
.p2align 4,,15 | |
.globl main | |
.type main, @function | |
main: | |
.LFB47: | |
.cfi_startproc | |
subq $24, %rsp | |
.cfi_def_cfa_offset 32 | |
movl $.LC0, %edi | |
movq %fs:40, %rax | |
movq %rax, 8(%rsp) | |
xorl %eax, %eax | |
leaq 4(%rsp), %rsi | |
call __isoc99_scanf | |
movl 4(%rsp), %eax | |
movl $1, %edi | |
movl %eax, %ecx | |
movzbl %ah, %esi | |
movl %eax, %edx | |
shrl $16, %ecx | |
movl %esi, %r8d | |
shrl $24, %edx | |
movzbl %al, %r9d | |
movzbl %cl, %ecx | |
xorl %eax, %eax | |
movl $.LC1, %esi | |
call __printf_chk | |
movq 8(%rsp), %rdi | |
xorq %fs:40, %rdi | |
jne .L5 | |
xorl %eax, %eax | |
addq $24, %rsp | |
.cfi_remember_state | |
.cfi_def_cfa_offset 8 | |
ret | |
.L5: | |
.cfi_restore_state | |
call __stack_chk_fail | |
.cfi_endproc | |
.LFE47: | |
.size main, .-main | |
.section .text.unlikely | |
.LCOLDE2: | |
.section .text.startup | |
.LHOTE2: | |
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609" | |
.section .note.GNU-stack,"",@progbits |
This file contains 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
#include <stdio.h> | |
#include <stdint.h> | |
int main() { | |
typedef union { | |
uint32_t ipWord; | |
unsigned char octets[4]; | |
} ip_t; | |
ip_t ip; | |
scanf("%u", &ip.ipWord); | |
printf("%u.%u.%u.%u\n", ip.octets[3], ip.octets[2], ip.octets[1], ip.octets[0]); | |
return 0; | |
} |
This file contains 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 "unionIP.c" | |
.section .rodata.str1.1,"aMS",@progbits,1 | |
.LC0: | |
.string "%u" | |
.LC1: | |
.string "%u.%u.%u.%u\n" | |
.section .text.unlikely,"ax",@progbits | |
.LCOLDB2: | |
.section .text.startup,"ax",@progbits | |
.LHOTB2: | |
.p2align 4,,15 | |
.globl main | |
.type main, @function | |
main: | |
.LFB23: | |
.cfi_startproc | |
subq $24, %rsp | |
.cfi_def_cfa_offset 32 | |
movl $.LC0, %edi | |
movq %fs:40, %rax | |
movq %rax, 8(%rsp) | |
xorl %eax, %eax | |
movq %rsp, %rsi | |
call __isoc99_scanf | |
movzbl 2(%rsp), %ecx | |
movzbl 3(%rsp), %edx | |
movl $.LC1, %esi | |
movzbl (%rsp), %r9d | |
movzbl 1(%rsp), %r8d | |
xorl %eax, %eax | |
movl $1, %edi | |
call __printf_chk | |
movq 8(%rsp), %rsi | |
xorq %fs:40, %rsi | |
jne .L5 | |
xorl %eax, %eax | |
addq $24, %rsp | |
.cfi_remember_state | |
.cfi_def_cfa_offset 8 | |
ret | |
.L5: | |
.cfi_restore_state | |
call __stack_chk_fail | |
.cfi_endproc | |
.LFE23: | |
.size main, .-main | |
.section .text.unlikely | |
.LCOLDE2: | |
.section .text.startup | |
.LHOTE2: | |
.ident "GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609" | |
.section .note.GNU-stack,"",@progbits |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment