Skip to content

Commit 133d7be

Browse files
committed
Add Chapter2
1 parent 2501243 commit 133d7be

File tree

18 files changed

+243
-0
lines changed

18 files changed

+243
-0
lines changed

Chapter2/a.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Hello World
2+
Hello World
3+
hello world

Chapter2/c.txt

Whitespace-only changes.

Chapter2/common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef __COMMON_H__
2+
#define __COMMON_H__
3+
4+
extern void print(char* str);
5+
extern char* input( );
6+
7+
#endif /* __COMMON_H__ */

Chapter2/e.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
txt

Chapter2/helloworld.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int main(int argc, char** argv)
4+
{
5+
printf("Hello, World!\n");
6+
7+
return 0;
8+
}

Chapter2/helloworld.s

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.arch armv6
2+
.eabi_attribute 28, 1
3+
.eabi_attribute 20, 1
4+
.eabi_attribute 21, 1
5+
.eabi_attribute 23, 3
6+
.eabi_attribute 24, 1
7+
.eabi_attribute 25, 1
8+
.eabi_attribute 26, 2
9+
.eabi_attribute 30, 6
10+
.eabi_attribute 34, 1
11+
.eabi_attribute 18, 4
12+
.file "helloworld.c"
13+
.text
14+
.section .rodata
15+
.align 2
16+
.LC0:
17+
.ascii "Hello, World!\000"
18+
.text
19+
.align 2
20+
.global main
21+
.arch armv6
22+
.syntax unified
23+
.arm
24+
.fpu vfp
25+
.type main, %function
26+
main:
27+
@ args = 0, pretend = 0, frame = 8
28+
@ frame_needed = 1, uses_anonymous_args = 0
29+
push {fp, lr}
30+
add fp, sp, #4
31+
sub sp, sp, #8
32+
str r0, [fp, #-8]
33+
str r1, [fp, #-12]
34+
ldr r0, .L3
35+
bl puts
36+
mov r3, #0
37+
mov r0, r3
38+
sub sp, fp, #4
39+
@ sp needed
40+
pop {fp, pc}
41+
.L4:
42+
.align 2
43+
.L3:
44+
.word .LC0
45+
.size main, .-main
46+
.ident "GCC: (Raspbian 8.3.0-6+rpi1) 8.3.0"
47+
.section .note.GNU-stack,"",%progbits

Chapter2/input.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include "common.h"
4+
5+
char* input( )
6+
{
7+
char *str;
8+
str = (char*)malloc(BUFSIZ);
9+
scanf("%s", str);
10+
11+
return str;
12+
}

Chapter2/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "common.h"
2+
3+
int main( )
4+
{
5+
char* str = input( );
6+
print(str);
7+
print("\n");
8+
9+
return 0;
10+
}

Chapter2/makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# makefile
2+
.SUFFIXES : .c .o
3+
4+
OBJECTS = main.o \
5+
print.o \
6+
input.o
7+
SRCS = $(OBJECTS:.o=.c)
8+
9+
CC = gcc
10+
CFLAGS = -g
11+
TARGET = test helloworld
12+
13+
all : $(TARGET)
14+
helloworld : helloworld.c
15+
$(CC) -o $@ $<
16+
17+
test : $(OBJECTS)
18+
$(CC) -o $@ $(OBJECTS)
19+
20+
clean :
21+
$(RM) $(OBJECTS) $(TARGET) helloworld.o core
22+
23+
main.o : main.c common.h
24+
print.o : print.c common.h
25+
input.o : input.c common.h

Chapter2/makefile1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test :
2+
gcc -o test main.c print.c input.c

0 commit comments

Comments
 (0)