Skip to content

Commit

Permalink
chapters/{memory-layout,stack}: Add tasks and reading material for C …
Browse files Browse the repository at this point in the history
…- Assembly interaction

Created standalone makefiles for solutions.
Added messages in readmes to point to the path of the exercices.
Modified `config.yaml` and removed guides from this lab.

Signed-off-by: cezar <[email protected]>
Signed-off-by: Teodor Dutu <[email protected]>
  • Loading branch information
savacezarmarian14 authored and teodutu committed Jan 3, 2025
1 parent 6fa6eaf commit 4a6220c
Show file tree
Hide file tree
Showing 99 changed files with 1,658 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Repair Export Problems

Navigate to `drills/tasks/export-fix/support/`.

Each subdirectory (`support/a-func/`, `suppoer/b-var/`, `support/c-var-2/`) contains a problem related to exporting some symbols (functions or variables).
In each subdirectory, run the `make` command, identify the problem and edit the files needed to fix the problem.

If you're having difficulties solving this exercise, go through [this relevant section](../../../reading/memory-layout-c-asm.md) reading material.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: BSD-3-Clause

int hidden_value;

void init(void)
{
hidden_value = 0;
}

void set(int value)
{
hidden_value = value;
}

int get(void)
{
return hidden_value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>
#include "ops.h"

int main(void)
{
set(10);
printf("get(): %d\n", get());

age = 33;
print_age();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef OPS_H_
#define OPS_H_ 1

void init(void);
void set(int value);
int get(void);

extern int age;
void print_age(void);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>

int age;

void print_age(void)
{
printf("age: %d\n", age);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: BSD-3-Clause

static int hidden_value;

void init(void)
{
hidden_value = 0;
}

void set(int value)
{
hidden_value = value;
}

int get(void)
{
return hidden_value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>
#include "ops.h"

int main(void)
{
set(10);
printf("get(): %d\n", get());

age = 33;
print_age();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef OPS_H_
#define OPS_H_ 1

void init(void);
void set(int value);
int get(void);

extern int age;
void print_age(void);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>

int age;

void print_age(void)
{
printf("age: %d\n", age);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: BSD-3-Clause

static int hidden_value;

void init(void)
{
hidden_value = 0;
}

void set(int value)
{
hidden_value = value;
}

int get(void)
{
return hidden_value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>
#include "ops.h"

int main(void)
{
set(10);
printf("get(): %d\n", get());

age = 33;
print_age();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef OPS_H_
#define OPS_H_ 1

void init(void);
void set(int value);
int get(void);
extern int age;
void print_age(void);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>

int age;

void print_age(void)
{
printf("age: %d\n", age);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CFLAGS = -Wall -g
CXXFLAGS = -Wall -g

.DEFAULT_GOAL: all

.PHONY: all clean

all: main

main: main.o hidden.o plain.o
$(CC) $(LDFLAGS) -o $@ $^

main.o: main.c ops.h

hidden.o: hidden.c

plain.o: plain.c

clean:
-rm -f main *.o
-rm -f *~
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: BSD-3-Clause

int hidden_value;

void init(void)
{
hidden_value = 0;
}

static void set(int value)
{
hidden_value = value;
}

int get(void)
{
return hidden_value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>
#include "ops.h"

int main(void)
{
set(10);
printf("get(): %d\n", get());

age = 33;
print_age();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef OPS_H_
#define OPS_H_ 1

void init(void);
void set(int value);
int get(void);

extern int age;
void print_age(void);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>

int age;

void print_age(void)
{
printf("age: %d\n", age);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CFLAGS = -Wall -g
CXXFLAGS = -Wall -g

.DEFAULT_GOAL: all

.PHONY: all clean

all: main

main: main.o hidden.o plain.o
$(CC) $(LDFLAGS) -o $@ $^

main.o: main.c ops.h

hidden.o: hidden.c

plain.o: plain.c

clean:
-rm -f main *.o
-rm -f *~
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: BSD-3-Clause

static int hidden_value;

void init(void)
{
hidden_value = 0;
}

void set(int value)
{
hidden_value = value;
}

int get(void)
{
return hidden_value;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>
#include "ops.h"

int main(void)
{
set(10);
printf("get(): %d\n", get());

age = 33;
print_age();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef OPS_H_
#define OPS_H_ 1

void init(void);
void set(int value);
int get(void);

extern int age;
void print_age(void);

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: BSD-3-Clause

#include <stdio.h>

static int age;

void print_age(void)
{
printf("age: %d\n", age);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/main
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CFLAGS = -Wall -g
CXXFLAGS = -Wall -g

.DEFAULT_GOAL: all

.PHONY: all clean

all: main

main: main.o hidden.o plain.o
$(CC) $(LDFLAGS) -o $@ $^

main.o: main.c ops.h

hidden.o: hidden.c

plain.o: plain.c

clean:
-rm -f main *.o
-rm -f *~
Loading

0 comments on commit 4a6220c

Please sign in to comment.