aboutsummaryrefslogtreecommitdiff
path: root/semestr-4/ask/lista5/zad1.c
blob: 9379bb2caf2331d4edfbaa1ab5347ea17a18b192 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <stdio.h>
#include <stdint.h>

int puzzle(long x /* rdi */ , unsigned n /* rsi */) {
    if (n == 0) {
        return n;
    }
    int t = 0;              // edx := 0
    int result = 0;         // eax := 0
    do {
        int m = x & 0xffffffff;     // ecx := edi
        m &= 1;
        result += m;
        x >>= 1;
        t++;
    } while (t != n);
    return result;               // ????
}

int main() {
    long x;
    unsigned n;
    scanf("%ld%u", &x, &n);
    return puzzle(x, n);
}