Last active
December 24, 2024 18:37
-
-
Save rnelson/2afeb0eac321767b23b11c4e74db7efa to your computer and use it in GitHub Desktop.
take_magic_damage
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
int take_magic_damage(int health, int resist, int amp, int spell_power) { | |
int full_damage = spell_power * amp; | |
int damage_taken = full_damage - resist; | |
return health - damage_taken; | |
} |
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
.text | |
.intel_syntax noprefix | |
.file "answer.c" | |
.globl take_magic_damage # -- Begin function take_magic_damage | |
.p2align 4, 0x90 | |
.type take_magic_damage,@function | |
take_magic_damage: # @take_magic_damage | |
.cfi_startproc | |
# %bb.0: | |
push rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset rbp, -16 | |
mov rbp, rsp | |
.cfi_def_cfa_register rbp | |
# kill: def $esi killed $esi def $rsi | |
# kill: def $edi killed $edi def $rdi | |
imul edx, ecx | |
lea eax, [rdi + rsi] | |
sub eax, edx | |
pop rbp | |
.cfi_def_cfa rsp, 8 | |
ret | |
.Lfunc_end0: | |
.size take_magic_damage, .Lfunc_end0-take_magic_damage | |
.cfi_endproc | |
# -- End function | |
.ident "FreeBSD clang version 18.1.6 (https://github.com/llvm/llvm-project.git llvmorg-18.1.6-0-g1118c2e05e67)" | |
.section ".note.GNU-stack","",@progbits | |
.addrsig |
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
#!/bin/ksh | |
clang -O3 -S -masm=intel answer.c | |
clang -O3 -S -masm=intel dillon.c | |
clang -O3 -S -masm=intel ross.c |
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
int take_magic_damage(int health, int resist, int amp, int spell_power) { | |
int new_health = health - (spell_power * amp - resist); | |
return new_health; | |
} |
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
.text | |
.intel_syntax noprefix | |
.file "dillon.c" | |
.globl take_magic_damage # -- Begin function take_magic_damage | |
.p2align 4, 0x90 | |
.type take_magic_damage,@function | |
take_magic_damage: # @take_magic_damage | |
.cfi_startproc | |
# %bb.0: | |
push rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset rbp, -16 | |
mov rbp, rsp | |
.cfi_def_cfa_register rbp | |
# kill: def $esi killed $esi def $rsi | |
# kill: def $edi killed $edi def $rdi | |
imul edx, ecx | |
lea eax, [rdi + rsi] | |
sub eax, edx | |
pop rbp | |
.cfi_def_cfa rsp, 8 | |
ret | |
.Lfunc_end0: | |
.size take_magic_damage, .Lfunc_end0-take_magic_damage | |
.cfi_endproc | |
# -- End function | |
.ident "FreeBSD clang version 18.1.6 (https://github.com/llvm/llvm-project.git llvmorg-18.1.6-0-g1118c2e05e67)" | |
.section ".note.GNU-stack","",@progbits | |
.addrsig |
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
int take_magic_damage(int health, int resist, int amp, int spell_power) { | |
return health - (spell_power * amp - resist); | |
} |
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
.text | |
.intel_syntax noprefix | |
.file "ross.c" | |
.globl take_magic_damage # -- Begin function take_magic_damage | |
.p2align 4, 0x90 | |
.type take_magic_damage,@function | |
take_magic_damage: # @take_magic_damage | |
.cfi_startproc | |
# %bb.0: | |
push rbp | |
.cfi_def_cfa_offset 16 | |
.cfi_offset rbp, -16 | |
mov rbp, rsp | |
.cfi_def_cfa_register rbp | |
# kill: def $esi killed $esi def $rsi | |
# kill: def $edi killed $edi def $rdi | |
imul edx, ecx | |
lea eax, [rdi + rsi] | |
sub eax, edx | |
pop rbp | |
.cfi_def_cfa rsp, 8 | |
ret | |
.Lfunc_end0: | |
.size take_magic_damage, .Lfunc_end0-take_magic_damage | |
.cfi_endproc | |
# -- End function | |
.ident "FreeBSD clang version 18.1.6 (https://github.com/llvm/llvm-project.git llvmorg-18.1.6-0-g1118c2e05e67)" | |
.section ".note.GNU-stack","",@progbits | |
.addrsig |
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
rnelson@reject:/home/rnelson/tmp/take_magic_damage $ ./compile.sh | |
rnelson@reject:/home/rnelson/tmp/take_magic_damage $ ls | |
answer.c answer.s compile.sh* dillon.c dillon.s ross.c ross.s | |
rnelson@reject:/home/rnelson/tmp/take_magic_damage $ diff answer.s ross.s | |
3c3 | |
< .file "answer.c" | |
--- | |
> .file "ross.c" | |
rnelson@reject:/home/rnelson/tmp/take_magic_damage $ diff answer.s dillon.s | |
3c3 | |
< .file "answer.c" | |
--- | |
> .file "dillon.c" | |
rnelson@reject:/home/rnelson/tmp/take_magic_damage $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment