Created
October 1, 2021 03:24
-
-
Save nekodjin/f908438feca45826541ce2e2b7ede872 to your computer and use it in GitHub Desktop.
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> | |
#include "sum.h" | |
int main(void) { | |
uint64_t x = sum(7, 1, 2, 3, 4, 5, 6, 7); | |
printf("%llu\n", x); | |
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
global sum | |
segment .text | |
sum: | |
xor rax, rax | |
xchg rcx, rdi | |
jrcxz _0_register_args | |
dec rcx | |
jrcxz _1_register_args | |
dec rcx | |
jrcxz _2_register_args | |
dec rcx | |
jrcxz _3_register_args | |
dec rcx | |
jrcxz _4_register_args | |
dec rcx | |
jrcxz _5_register_args | |
_stack_args: | |
add rax, [rcx*8+rsp] | |
loop _stack_args | |
_5_register_args: | |
add rax, r9 | |
_4_register_args: | |
add rax, r8 | |
_3_register_args: | |
add rax, rdi | |
_2_register_args: | |
add rax, rdx | |
_1_register_args: | |
add rax, rsi | |
_0_register_args: | |
ret |
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
#ifndef __SUM_H__ | |
#define __SUM_H__ | |
#include <stdint.h> | |
extern uint64_t sum(uint64_t count, ...); | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment