File tree Expand file tree Collapse file tree 3 files changed +60
-156
lines changed Expand file tree Collapse file tree 3 files changed +60
-156
lines changed Original file line number Diff line number Diff line change 3838
3939fh:
4040 .quad 0
41- source_buffer :
41+ in :
4242 .quad 0
43- out_buffer :
43+ out :
4444 .quad 0
4545siz:
4646 .quad 0
9898 enter
9999 mov $READ, %rax
100100 mov fh(%rip ), %rdi
101- mov source_buffer (%rip ), %rsi
101+ mov in (%rip ), %rsi
102102 mov siz(%rip ), %rdx
103103 syscall
104104 return
@@ -108,11 +108,12 @@ copy:
108108 mov $0 , %rcx
109109 cmp %rcx , siz(%rip )
110110 je copy_done
111+ mov in (%rip ), %rsi
111112copy_loop:
112- lea source_buffer( %rip ) , %rsi
113- add %rcx , %rsi
114- mov (%rsi ), %rdx
115- mov %rdx , out_buffer( %rsi )
113+ mov %rcx , %rdx
114+ add out ( %rip ) , %rdx
115+ mov (%rsi , %rcx ), %rdi
116+ movb %dil , ( %rdx )
116117 inc %rcx
117118 cmp %rcx , siz(%rip )
118119 jne copy_loop
@@ -123,7 +124,7 @@ write:
123124 enter
124125 mov $WRITE, %rax
125126 mov $STDOUT, %rdi
126- mov source_buffer (%rip ), %rsi
127+ mov out (%rip ), %rsi
127128 mov siz(%rip ), %rdx
128129 syscall
129130 return
@@ -138,7 +139,11 @@ close:
138139munmap:
139140 enter
140141 mov $MUNMAP, %rax
141- lea source_buffer, %rdi
142+ lea in , %rdi
143+ mov siz(%rip ), %rsi
144+ syscall
145+ mov $MUNMAP, %rax
146+ lea out , %rdi
142147 mov siz(%rip ), %rsi
143148 syscall
144149 return
@@ -147,11 +152,11 @@ main:
147152 call open
148153 call stat
149154 call mmap
150- mov %rax , source_buffer (%rip )
155+ mov %rax , in (%rip )
151156 call read
152157 call mmap
153- mov %rax , out_buffer (%rip )
154- # call copy TODO
158+ mov %rax , out (%rip )
159+ call copy
155160 call write
156161 call close
157162 call munmap
Original file line number Diff line number Diff line change 88
99clean :
1010 @rm -f memcpy.o memcpy
11+
12+ check : build
13+ ./memcpy | grep -q ^0xa$ && printf " \033[1;32m[OK]\033[0m\n"
Original file line number Diff line number Diff line change 1- .file "draft.c"
1+ .bss
2+ out:
3+ .zero 8
4+ in:
5+ .zero 8
6+
27 .text
3- .globl get_zero
4- .type get_zero, @function
5- get_zero:
6- .LFB23:
7- .cfi_startproc
8- movl $128 , %edx
9- .L2:
10- movl %edx , %eax
11- shrl $31 , %eax
12- addl %edx , %eax
13- sarl %eax
14- movl %eax , %edx
15- cmpl $16 , %eax
16- jne .L2
17- movl $0 , %eax
18- ret
19- .cfi_endproc
20- .LFE23:
21- .size get_zero, .-get_zero
22- .globl get_one
23- .type get_one, @function
24- get_one:
25- .LFB24:
26- .cfi_startproc
27- movl $128 , %edx
28- .L4:
29- movl %edx , %eax
30- shrl $31 , %eax
31- addl %edx , %eax
32- sarl %eax
33- movl %eax , %edx
34- cmpl $8 , %eax
35- jne .L4
36- movl $1 , %eax
37- ret
38- .cfi_endproc
39- .LFE24:
40- .size get_one, .-get_one
41- .globl get_two
42- .type get_two, @function
43- get_two:
44- .LFB25:
45- .cfi_startproc
46- movl $128 , %edx
47- .L6:
48- movl %edx , %eax
49- shrl $31 , %eax
50- addl %edx , %eax
51- sarl %eax
52- movl %eax , %edx
53- cmpl $4 , %eax
54- jne .L6
55- movl $2 , %eax
56- ret
57- .cfi_endproc
58- .LFE25:
59- .size get_two, .-get_two
60- .globl get_three
61- .type get_three, @function
62- get_three:
63- .LFB26:
64- .cfi_startproc
65- movl $128 , %edx
66- .L8:
67- movl %edx , %eax
68- shrl $31 , %eax
69- addl %edx , %eax
70- sarl %eax
71- movl %eax , %edx
72- cmpl $32 , %eax
73- jne .L8
74- movl $3 , %eax
75- ret
76- .cfi_endproc
77- .LFE26:
78- .size get_three, .-get_three
798 .globl main
80- .type main, @function
9+
8110main:
82- .LFB27:
83- .cfi_startproc
84- pushq %rbp
85- .cfi_def_cfa_offset 16
86- .cfi_offset 6 , -16
87- movq %rsp , %rbp
88- .cfi_def_cfa_register 6
89- pushq %r13
90- pushq %r12
91- pushq %rbx
92- subq $8 , %rsp
93- .cfi_offset 13 , -24
94- .cfi_offset 12 , -32
95- .cfi_offset 3 , -40
96- movl $4 , %edi
11+ push %rbp
12+ mov %rsp , %rbp
13+ push %r13
14+ push %r12
15+ push %rbx
16+ sub $8 , %rsp
17+ mov $4 , %rdi
9718 call malloc@PLT
98- movq %rax , %rbx
99- movq %rax , in (%rip )
100- movl $4 , %edi
19+ mov %rax , %rbx
20+ mov %rax , in (%rip )
21+ mov $4 , %rdi
10122 call malloc@PLT
102- movq %rax , out (%rip )
23+ mov %rax , out (%rip )
10324 movb $48 , (%rbx )
104- movq in (%rip ), %rax
25+ mov in (%rip ), %rax
10526 movb $120 , 1 (%rax )
106- movq in (%rip ), %rax
27+ mov in (%rip ), %rax
10728 movb $97 , 2 (%rax )
108- movq in (%rip ), %rax
29+ mov in (%rip ), %rax
10930 movb $10 , 3 (%rax )
110- movl $0 , %r13d
111- movl $1 , %r12d
112- movl $2 , %ebx
113- movl $3 , %eax
114- movslq %r13d , %rdx
115- movq %rdx , %rcx
31+ mov $3 , %rax
32+ mov $0 , %rdx
33+ mov $0 , %rcx
11634 add out (%rip ), %rcx
117- movq in (%rip ), %rsi
118- movzbl (%rsi ,%rdx ), %edx
35+ mov in (%rip ), %rsi
36+ mov (%rsi , %rdx ), %rdx
11937 movb %dl , (%rcx )
120- movslq %r12d , %rdx
121- movq %rdx , %rcx
38+ mov $1 , %rdx
39+ mov %rdx , %rcx
12240 add out (%rip ), %rcx
123- movq in (%rip ), %rsi
124- movzbl (%rsi ,%rdx ), %edx
41+ mov (%rsi , %rdx ), %rdx
12542 movb %dl , (%rcx )
126- movslq %ebx , %rdx
127- movq %rdx , %rcx
43+ mov $2 , %rdx
44+ mov %rdx , %rcx
12845 add out (%rip ), %rcx
129- movq in (%rip ), %rsi
130- movzbl (%rsi ,%rdx ), %edx
46+ mov (%rsi , %rdx ), %rdx
13147 movb %dl , (%rcx )
132- cltq
133- movq %rax , %rdx
48+ mov $3 , %rdx
13449 add out (%rip ), %rdx
135- movq in (%rip ), %rcx
136- movzbl (%rcx ,%rax ), %eax
50+ mov in (%rip ), %rcx
51+ mov (%rcx , %rax ), %rax
13752 movb %al , (%rdx )
138- movl $4 , %ecx
53+ mov $4 , %rcx
13954 mov out (%rip ), %rdx
140- movl $1 , %esi
141- movl $1 , %edi
142- movl $0 , %eax
55+ mov $1 , %rsi
56+ mov $1 , %rdi
57+ mov $0 , %rax
14358 call syscall @PLT
144- movl $0 , %eax
59+ mov $0 , %rax
14560 add $8 , %rsp
14661 pop %rbx
14762 pop %r12
14863 pop %r13
14964 pop %rbp
150- .cfi_def_cfa 7 , 8
15165 ret
152- .cfi_endproc
153- .LFE27:
154- .size main, .-main
155- .globl out
156- .bss
157- .align 8
158- .type out , @object
159- .size out , 8
160- out:
161- .zero 8
162- .globl in
163- .align 8
164- .type in , @object
165- .size in , 8
166- in:
167- .zero 8
168- .ident "GCC: (Debian 14.2.0-19) 14.2.0"
169- .section .note.GNU-stack,"",@progbits
You can’t perform that action at this time.
0 commit comments