Skip to content

Commit

Permalink
Programmentwurf TI20 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
rdrcode committed Mar 14, 2022
1 parent db6f36d commit edb5611
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ lettercount/asciitable.inc
asciitoint/asciitoint
copyij/copyij
copyij/copyji
pe2022/list_test
pe2022/timediff
45 changes: 45 additions & 0 deletions pe2022/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#=============================================================================
#
# Makefile
#
#-----------------------------------------------------------------------------
#
# DHBW Ravensburg - Campus Friedrichshafen
#
# Vorlesung Systemnahe Programmierung
#
# Author: Ralf Reutemann
#
#=============================================================================

CC = gcc
LD = ld
NASM = nasm
NASMOPT64 = -g -f elf64 -F dwarf
LDOPT64 =
CFLAGS = -Wall -g -std=gnu11 -O2 -fno-inline-small-functions -static
INCDIR = ../syscall/

TARGETS = timediff list_test

.PHONY: all
all: $(TARGETS)

timediff : timediff.o list.o
$(LD) $(LDOPT64) -o $@ $^

timediff.o : $(INCDIR)/syscall.inc

list_test : list_test.o list.o
$(CC) $(CFLAGS) -o $@ $^

%.o : %.asm
$(NASM) $(NASMOPT64) -I$(INCDIR) -l $(basename $<).lst -o $@ $<

%.o : %.c
$(CC) $(CFLAGS) -c -o $@ $<

.PHONY: clean
clean:
rm -f *.o *.lst $(TARGETS)

109 changes: 109 additions & 0 deletions pe2022/list.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
;-----------------------------------------------------------------------------
;
; DHBW Ravensburg - Campus Friedrichshafen
;
; Vorlesung Systemnahe Programmierung (SNP)
;
;----------------------------------------------------------------------------
;
; Architecture: x86-64
; Language: NASM Assembly Language
;
; Authors:
;
;----------------------------------------------------------------------------


;-----------------------------------------------------------------------------
; SECTION TEXT
;-----------------------------------------------------------------------------
SECTION .text


;-----------------------------------------------------------------------------
; extern void list(void)
;-----------------------------------------------------------------------------
global list_init:function
list_init:
push rbp
mov rbp,rsp

; your code goes here

mov rsp,rbp
pop rbp
ret

;-----------------------------------------------------------------------------
; extern short list_size(void);
;-----------------------------------------------------------------------------
global list_size:function
list_size:
push rbp
mov rbp,rsp

; your code goes here

mov rsp,rbp
pop rbp
ret


;-----------------------------------------------------------------------------
; extern bool list_is_sorted(void);
;-----------------------------------------------------------------------------
global list_is_sorted:function
list_is_sorted:
push rbp
mov rbp,rsp

; your code goes here

mov rsp,rbp
pop rbp
ret


;-----------------------------------------------------------------------------
; extern short list_add(struct timeval *tv);
;-----------------------------------------------------------------------------
global list_add:function
list_add:
push rbp
mov rbp,rsp

; your code goes here

mov rsp,rbp
pop rbp
ret


;-----------------------------------------------------------------------------
; extern short list_find(struct timeval *tv);
;-----------------------------------------------------------------------------
global list_find:function
list_find:
push rbp
mov rbp,rsp

; your code goes here

mov rsp,rbp
pop rbp
ret


;-----------------------------------------------------------------------------
; extern bool list_get(struct timeval *tv, short idx);
;-----------------------------------------------------------------------------
global list_get:function
list_get:
push rbp
mov rbp,rsp

; your code goes here

mov rsp,rbp
pop rbp
ret
81 changes: 81 additions & 0 deletions pe2022/list_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*===================================================================
* DHBW Ravensburg - Campus Friedrichshafen
*
* Vorlesung Systemnahe Programmierung (SNP)
*
* list_test.c
*
* Author: Ralf Reutemann
* Created: 2022-03-14
*
*===================================================================*/

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <sys/time.h>
#include <assert.h>


// function prototypes
extern void list_init(void);
extern short list_size(void);
extern bool list_is_sorted(void);
extern short list_add(struct timeval *tv);
extern short list_find(struct timeval *tv);
extern bool list_get(struct timeval *tv, short idx);


struct timeval timestamps[] = {
{1400000000, 123456},
{1450000000, 200000},
{1500000000, 0},
{1550000000, 500000},
{1590000000, 999999},
{1600000000, 2},
{1600000000, 5},
{1700000000, 100000},
{0, 0}
};


int
main(int argc, char *argv[])
{
struct timeval tv_tmp;

list_init();
assert(list_size() == 0);
assert(list_is_sorted() == false);
assert(list_get(&tv_tmp, 0) == false);
assert(list_get(NULL, 0) == false);

int idx = 0;
while(timestamps[idx].tv_sec != 0) {
short pos = list_add(&timestamps[idx]);
assert(pos == idx);
idx++;
}
assert(list_size() == idx);
assert(list_is_sorted() == true);

assert(list_get(&tv_tmp, 0) == true);
assert(memcmp(&tv_tmp, &timestamps[0], sizeof(struct timeval)) == 0);
assert(list_find(&timestamps[0]) == 0);

assert(list_get(&tv_tmp, idx/2) == true);
assert(memcmp(&tv_tmp, &timestamps[idx/2], sizeof(struct timeval)) == 0);
assert(list_find(&timestamps[idx/2]) == idx/2);

assert(list_get(&tv_tmp, idx-1) == true);
assert(memcmp(&tv_tmp, &timestamps[idx-1], sizeof(struct timeval)) == 0);
assert(list_find(&timestamps[idx-1]) == idx-1);

struct timeval tv = {1700000000, 0};
list_add(&tv);
assert(list_size() == idx+1);
assert(list_is_sorted() == false);

exit(EXIT_SUCCESS);
} /* end of main */
39 changes: 39 additions & 0 deletions pe2022/timediff.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
;-----------------------------------------------------------------------------
; timediff.asm -
;-----------------------------------------------------------------------------
;
; DHBW Ravensburg - Campus Friedrichshafen
;
; Vorlesung Systemnahe Programmierung (SNP)
;
;----------------------------------------------------------------------------
;
; Architecture: x86-64
; Language: NASM Assembly Language
;
; Authors:
;
;----------------------------------------------------------------------------

%include "syscall.inc" ; OS-specific system call macros


;-----------------------------------------------------------------------------
; SECTION TEXT
;-----------------------------------------------------------------------------
SECTION .text

;-----------------------------------------------------------
; PROGRAM'S START ENTRY
;-----------------------------------------------------------
global _start:function ; make label available to linker
_start:
nop

;-----------------------------------------------------------
; call system exit and return to operating system / shell
;-----------------------------------------------------------
.exit: SYSCALL_2 SYS_EXIT, 0
;-----------------------------------------------------------
; END OF PROGRAM
;-----------------------------------------------------------

0 comments on commit edb5611

Please sign in to comment.