Skip to content

Commit

Permalink
chap-05: Add demo showing data sections
Browse files Browse the repository at this point in the history
Source code files are both in C and in assembly.

Signed-off-by: Razvan Deaconescu <[email protected]>
  • Loading branch information
razvand authored and gabrielmocanu committed Mar 30, 2024
1 parent d0bff4e commit 537ff1b
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions curs/chap-05-ihs/08-data/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/data_c
/data_asm
/data_c.s
25 changes: 25 additions & 0 deletions curs/chap-05-ihs/08-data/Makefile
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions curs/chap-05-ihs/08-data/data_asm.asm
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions curs/chap-05-ihs/08-data/data_c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
int non_init;
int init = 3;
const int ro = 10;

int main(void)
{
return 0;
}

0 comments on commit 537ff1b

Please sign in to comment.