Tutorium 6

Reading time ~2 minutes

Nachbesprechung Übung 4

Aufgabe 1

23+81=104

In den Darstellungen B+V, Einer- und Zweierkomplement identisch:

B+V, E/ZK   Offset 128
 00010111   10010111
+01010001  +11010001
---------  ---------
 01101000   11101000

36-14=22

B+V         Einerkomplement   Zweierkomplement   Offset 128
 00100100    00100100          00100100           10100100
+10001110   +11110001         +11110010          +01110010
---------   ---------         ---------          ---------
 00010110    00010110          00010110           10010110

72-87=-15

B+V         Einerkomplement   Zweierkomplement   Offset 128
 01001000    01001000          01001000           11001000
+11010111   +10101000         +10101001          +00101010
---------   ---------         ---------          ---------
 10001111    11110000          11110001           01110001

-113-37=-150

Ergibt -150 und ist somit größer als die kleinste Darstellbare Zahl -128.

Aufgabe 2

Die Datei form.asm

global form

section .text
form:
    add  edi, esi
    sub  edx, ecx
    imul edi, edx
    sal  r8d, 3
    sal  r9d, 2
    mov  rcx, [rsp+8]
    sar  ecx, 1
    mov  rsi, [rsp+16]
    sar  esi, 2
    add  r8d, r9d
    sub  r8d, ecx
    add  r8d, esi
    imul edi, r8d
    mov  eax, edi
    mov  edi, 3
    cdq
    idiv edi
    ret

mit der bereits bekannten form.c aus dem Tutorium

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

extern int32_t form(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", form(1,2,2,1,1,1,10,12)); }

Vorbesprechung Übung 6

rekursive Berechnung: TI2 CH02 Data Arithmetic_orig 2.81

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

extern int64_t strtoint(const char* str, uint64_t len, uint64_t base);

int main(void)
{ printf("%"PRId64"\n", strtoint("8ASZ", 5, 35)); }