-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chap-05: Add demo showing data sections
Source code files are both in C and in assembly. Signed-off-by: Razvan Deaconescu <[email protected]>
- Loading branch information
1 parent
d0bff4e
commit 537ff1b
Showing
4 changed files
with
61 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/data_c | ||
/data_asm | ||
/data_c.s |
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,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 |
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,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 |
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,8 @@ | ||
int non_init; | ||
int init = 3; | ||
const int ro = 10; | ||
|
||
int main(void) | ||
{ | ||
return 0; | ||
} |