Created
December 6, 2020 04:41
-
-
Save codekittie/730e9c05d9b763e2a0a6b601728a8a91 to your computer and use it in GitHub Desktop.
Sum of positives in array
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
SECTION .text | |
global positive_sum | |
; eax = return value (positive sum) | |
; rdi = pointer to array of ints (4 bytes) | |
; esi = length of array in rdi | |
positive_sum: | |
xor eax, eax | |
loop: | |
cmp WORD [rdi], 0 ; check if [rdi] greater than 0 | |
jle skip | |
add eax, [rdi] | |
skip: | |
cmp esi, 0 ; check if any nums left | |
je return ; if not, jump to return | |
add rdi, 4 ; add 4 to rdi, to go to next int in array | |
sub esi, 1 ; subtract one from our count, stored in esi | |
return: | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Khety! Great to see how you're coming along as a badass asm coder (especially at 13!). Here is what I believe to be a working version: