Tutorium 4

Reading time ~1 minute

Nachbesprechung Übung 2

Aufgabe 2: Pseudocode

if (x<10)
{
    S();
}
else
    if (x==10)
    {
        T();
    }
    else
        if (x>10)
        {
            V();
        }
        else
        {
            W();
        }

und die collatz.asm

global collatz

section .text
collatz:
    xor rcx, rcx
    xor rdx, rdx
    mov r8 , 3
    mov rax, rdi
    L1:
        cmp rax, 1
        jbe END
        inc rcx
        shr rax, 1
        jc  ODD
        jmp L1
    ODD:
        rcl rax, 1
        mul r8
        inc rax
        jmp L1
    END:
        mov rax, rcx
        ret

und collatz.c

#include <stdio.h>
#include <inttypes.h>

extern uint64_t collatz(uint64_t);

int main(void)
{ printf("%"PRIu64"\n", collatz(100)); }

Vorbesprechung Übung 4

Framework für die Programmieraufgabe

#include <stdio.h>
#include <inttypes.h>

extern int32_t formula(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, \
                       int32_t f, int32_t g, int32_t h);

int main(void)
{ printf("%"PRId32"\n", formula(1,2,3,4,5,6,7,8)); }