From 537ff1b3a926ede84ef7acbdd6ba5c061d907e75 Mon Sep 17 00:00:00 2001 From: Razvan Deaconescu Date: Fri, 24 Dec 2021 13:24:08 +0200 Subject: [PATCH] chap-05: Add demo showing data sections Source code files are both in C and in assembly. Signed-off-by: Razvan Deaconescu --- curs/chap-05-ihs/08-data/.gitignore | 3 +++ curs/chap-05-ihs/08-data/Makefile | 25 +++++++++++++++++++++++++ curs/chap-05-ihs/08-data/data_asm.asm | 25 +++++++++++++++++++++++++ curs/chap-05-ihs/08-data/data_c.c | 8 ++++++++ 4 files changed, 61 insertions(+) create mode 100644 curs/chap-05-ihs/08-data/.gitignore create mode 100644 curs/chap-05-ihs/08-data/Makefile create mode 100644 curs/chap-05-ihs/08-data/data_asm.asm create mode 100644 curs/chap-05-ihs/08-data/data_c.c diff --git a/curs/chap-05-ihs/08-data/.gitignore b/curs/chap-05-ihs/08-data/.gitignore new file mode 100644 index 00000000..6f71ad17 --- /dev/null +++ b/curs/chap-05-ihs/08-data/.gitignore @@ -0,0 +1,3 @@ +/data_c +/data_asm +/data_c.s diff --git a/curs/chap-05-ihs/08-data/Makefile b/curs/chap-05-ihs/08-data/Makefile new file mode 100644 index 00000000..f9b608bf --- /dev/null +++ b/curs/chap-05-ihs/08-data/Makefile @@ -0,0 +1,25 @@ +CFLAGS = -m32 -fno-PIC -Wall +LDFLAGS = -m32 -no-pie +ASFLAGS = -f elf32 +AS = nasm + +.PHONY: all clean + +all: data_c data_asm data_c.s + +data_c: data_c.o + +data_c.o: data_c.c + +data_c.s: data_c.c + $(CC) -S -o $@ $< + +data_asm: data_asm.o + +data_asm.o: data_asm.asm + $(AS) $(ASFLAGS) -o $@ $< + +clean: + -rm -f *~ + -rm -f data_c.o data_c + -rm -f data_asm.o data_asm diff --git a/curs/chap-05-ihs/08-data/data_asm.asm b/curs/chap-05-ihs/08-data/data_asm.asm new file mode 100644 index 00000000..c08feeae --- /dev/null +++ b/curs/chap-05-ihs/08-data/data_asm.asm @@ -0,0 +1,25 @@ +section .data +global init + +init: dd 3 + +section .bss +global non_init + +non_init: resd 1 + +section .rodata +global ro + +ro: dd 10 + +section .text + +global main + +main: + push ebp + mov ebp, esp + + leave + ret diff --git a/curs/chap-05-ihs/08-data/data_c.c b/curs/chap-05-ihs/08-data/data_c.c new file mode 100644 index 00000000..0201b7eb --- /dev/null +++ b/curs/chap-05-ihs/08-data/data_c.c @@ -0,0 +1,8 @@ +int non_init; +int init = 3; +const int ro = 10; + +int main(void) +{ + return 0; +}