-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,3 +69,5 @@ lettercount/asciitable.inc | |
asciitoint/asciitoint | ||
copyij/copyij | ||
copyij/copyji | ||
pe2022/list_test | ||
pe2022/timediff |
This file contains 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
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) | ||
|
This file contains 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
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 |
This file contains 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
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(×tamps[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, ×tamps[0], sizeof(struct timeval)) == 0); | ||
assert(list_find(×tamps[0]) == 0); | ||
|
||
assert(list_get(&tv_tmp, idx/2) == true); | ||
assert(memcmp(&tv_tmp, ×tamps[idx/2], sizeof(struct timeval)) == 0); | ||
assert(list_find(×tamps[idx/2]) == idx/2); | ||
|
||
assert(list_get(&tv_tmp, idx-1) == true); | ||
assert(memcmp(&tv_tmp, ×tamps[idx-1], sizeof(struct timeval)) == 0); | ||
assert(list_find(×tamps[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 */ |
This file contains 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
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 | ||
;----------------------------------------------------------- |