Skip to content

Commit 9df2967

Browse files
committed
add github action
1 parent 6c5aee3 commit 9df2967

6 files changed

Lines changed: 55 additions & 34 deletions

File tree

.github/workflows/make.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: make
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- run: ./action.sh

action.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
#see .github/workflows/make.yml
3+
4+
cd cat
5+
make
6+
make check

cat/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ default:
22
$(CC) cat.s -c -g
33
$(LD) -o cat cat.o
44

5-
test:
6-
@./cat | md5sum | grep -q ^06aa985f3 && printf "\033[1;32m[OK]\033[0m\n"
5+
check:
6+
./cat | md5sum | grep -q ^06aa985f3 && printf "\033[1;32m[OK]\033[0m\n"
77

88
clean:
99
@rm -f cat.o cat

cat/cat.s

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,14 @@ _start:
129129
pushq %rbp
130130
movq %rsp, %rbp
131131

132-
call _print_ouch
133-
134132
call _open
135133
call _stat
136134
call _mmap
137135
call _read
138136
call _write
139137
call _close
140138
call _munmap
139+
call _exit
141140

142141
call _print_ouch
143142

group3/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
default:
2-
$(CC) group3.S -c -g
2+
$(CC) group3.s -c -g
33
$(LD) -o group3 group3.o
44

55
clean:

group3/group3.S renamed to group3/group3.s

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,40 @@
88
.equ MMAP, 9
99
.equ MUNMAP, 11
1010
.equ OFFSET_SIZE, 48
11+
.equ CHAR_O, 0x4f
12+
.equ CHAR_U, 0x55
13+
.equ CHAR_C, 0x43
14+
.equ CHAR_H, 0x48
15+
.equ BANG, 0x21
16+
.equ NEWLINE, 0xa
1117

12-
.data
18+
.data
1319

1420
fh:
1521
.quad 0
1622
buffer:
1723
.quad 0
24+
siz:
25+
.quad 0
1826
st:
1927
.zero 1024
2028

21-
.section .rodata
29+
.section .rodata
2230

2331
file:
2432
.asciz "data.txt"
2533

26-
.text
27-
28-
.globl _start
34+
.text
35+
.globl _start
2936

3037
_mmap:
3138
movq $MMAP, %rax
32-
movq $0, %rdi #addr
33-
movq $3, %rdx #prot r=1 w=2
34-
leaq st, %rbx
35-
movq 48(%rbx), %rsi #len
36-
movq $-1, %r8 #fd
37-
movq $0, %r9 #offset
38-
movq $34, %r10 #flags map_private=0x02, map_anonymous=0x20
39+
movq $0, %rdi #addr
40+
movq $3, %rdx #prot r=1 w=2
41+
movq siz(%rip), %rsi #len
42+
movq $-1, %r8 #fd
43+
movq $0, %r9 #offset
44+
movq $34, %r10 #flags map_private=0x02, map_anonymous=0x20
3945
syscall
4046
movq %rax, buffer(%rip) #store buffer
4147
ret
@@ -48,27 +54,27 @@ _exit:
4854

4955
_print:
5056
movq $WRITE, %rax
51-
pushq %rdi #print contents of rdi
57+
pushq %rdi #print contents of rdi
5258
movq $STDOUT, %rdi
53-
pushq %rsp #push leaves RSP pointing to the data that was pushed
54-
popq %rsi #copy RSP to RSI
55-
movq $1, %rdx #size
59+
pushq %rsp #push leaves RSP pointing to the data that was pushed
60+
popq %rsi #copy RSP to RSI
61+
movq $1, %rdx #size
5662
syscall
5763
popq %rdi
5864
ret
5965

6066
_print_ouch:
61-
movq $0x4f, %rdi
67+
movq $CHAR_O, %rdi
6268
call _print
63-
movq $0x55, %rdi
69+
movq $CHAR_U, %rdi
6470
call _print
65-
movq $0x43, %rdi
71+
movq $CHAR_C, %rdi
6672
call _print
67-
movq $0x48, %rdi
73+
movq $CHAR_H, %rdi
6874
call _print
69-
movq $0x21, %rdi
75+
movq $BANG, %rdi
7076
call _print
71-
movq $0xa, %rdi
77+
movq $NEWLINE, %rdi
7278
call _print
7379
ret
7480

@@ -86,23 +92,23 @@ _stat:
8692
movq fh(%rip), %rdi #load fh
8793
leaq st, %rsi #into st
8894
syscall
95+
movq 48(%rsi), %rbx #store size
96+
movq %rbx, siz(%rip)
8997
ret
9098

9199
_read:
92100
movq $READ, %rax
93101
movq fh(%rip), %rdi #int fd
94102
movq buffer(%rip), %rsi #char *buf
95-
leaq st, %rbx
96-
movq 48(%rbx), %rdx #len
103+
movq siz(%rip), %rdx #len
97104
syscall
98105
ret
99106

100107
_write:
101108
movq $WRITE, %rax
102109
movq $STDOUT, %rdi #int fd
103110
movq buffer(%rip), %rsi #char *buf
104-
leaq st, %rbx
105-
movq 48(%rbx), %rdx #len
111+
movq siz(%rip), %rdx #len
106112
syscall
107113
ret
108114

@@ -115,8 +121,7 @@ _close:
115121
_munmap:
116122
movq $MUNMAP, %rax #munmap
117123
leaq buffer, %rdi #buffer
118-
leaq st, %rbx
119-
movq 48(%rbx), %rsi #len
124+
movq siz(%rip), %rsi #len
120125
syscall
121126
ret
122127

@@ -132,4 +137,3 @@ _start:
132137
call _close
133138
call _munmap
134139
call _exit
135-
leave

0 commit comments

Comments
 (0)