-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcat.asm
1276 lines (1206 loc) · 42.6 KB
/
cat.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
_cat: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
}
}
int
main(int argc, char *argv[])
{
0: 8d 4c 24 04 lea 0x4(%esp),%ecx
4: 83 e4 f0 and $0xfffffff0,%esp
7: ff 71 fc pushl -0x4(%ecx)
a: 55 push %ebp
b: 89 e5 mov %esp,%ebp
d: 57 push %edi
e: 56 push %esi
f: be 01 00 00 00 mov $0x1,%esi
14: 53 push %ebx
15: 51 push %ecx
16: 83 ec 18 sub $0x18,%esp
19: 8b 01 mov (%ecx),%eax
1b: 8b 59 04 mov 0x4(%ecx),%ebx
1e: 89 45 e4 mov %eax,-0x1c(%ebp)
21: 83 c3 04 add $0x4,%ebx
int fd, i;
if(argc <= 1){
24: 83 f8 01 cmp $0x1,%eax
27: 7e 54 jle 7d <main+0x7d>
29: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
cat(0);
exit();
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
30: 83 ec 08 sub $0x8,%esp
33: 6a 00 push $0x0
35: ff 33 pushl (%ebx)
37: e8 65 03 00 00 call 3a1 <open>
3c: 83 c4 10 add $0x10,%esp
3f: 89 c7 mov %eax,%edi
41: 85 c0 test %eax,%eax
43: 78 24 js 69 <main+0x69>
printf(1, "cat: cannot open %s\n", argv[i]);
exit();
}
cat(fd);
45: 83 ec 0c sub $0xc,%esp
for(i = 1; i < argc; i++){
48: 83 c6 01 add $0x1,%esi
4b: 83 c3 04 add $0x4,%ebx
cat(fd);
4e: 50 push %eax
4f: e8 3c 00 00 00 call 90 <cat>
close(fd);
54: 89 3c 24 mov %edi,(%esp)
57: e8 2d 03 00 00 call 389 <close>
for(i = 1; i < argc; i++){
5c: 83 c4 10 add $0x10,%esp
5f: 39 75 e4 cmp %esi,-0x1c(%ebp)
62: 75 cc jne 30 <main+0x30>
}
exit();
64: e8 f8 02 00 00 call 361 <exit>
printf(1, "cat: cannot open %s\n", argv[i]);
69: 50 push %eax
6a: ff 33 pushl (%ebx)
6c: 68 5b 08 00 00 push $0x85b
71: 6a 01 push $0x1
73: e8 58 04 00 00 call 4d0 <printf>
exit();
78: e8 e4 02 00 00 call 361 <exit>
cat(0);
7d: 83 ec 0c sub $0xc,%esp
80: 6a 00 push $0x0
82: e8 09 00 00 00 call 90 <cat>
exit();
87: e8 d5 02 00 00 call 361 <exit>
8c: 66 90 xchg %ax,%ax
8e: 66 90 xchg %ax,%ax
00000090 <cat>:
{
90: 55 push %ebp
91: 89 e5 mov %esp,%ebp
93: 56 push %esi
94: 8b 75 08 mov 0x8(%ebp),%esi
97: 53 push %ebx
while((n = read(fd, buf, sizeof(buf))) > 0) {
98: eb 1d jmp b7 <cat+0x27>
9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if (write(1, buf, n) != n) {
a0: 83 ec 04 sub $0x4,%esp
a3: 53 push %ebx
a4: 68 80 0b 00 00 push $0xb80
a9: 6a 01 push $0x1
ab: e8 d1 02 00 00 call 381 <write>
b0: 83 c4 10 add $0x10,%esp
b3: 39 d8 cmp %ebx,%eax
b5: 75 25 jne dc <cat+0x4c>
while((n = read(fd, buf, sizeof(buf))) > 0) {
b7: 83 ec 04 sub $0x4,%esp
ba: 68 00 02 00 00 push $0x200
bf: 68 80 0b 00 00 push $0xb80
c4: 56 push %esi
c5: e8 af 02 00 00 call 379 <read>
ca: 83 c4 10 add $0x10,%esp
cd: 89 c3 mov %eax,%ebx
cf: 85 c0 test %eax,%eax
d1: 7f cd jg a0 <cat+0x10>
if(n < 0){
d3: 75 1b jne f0 <cat+0x60>
}
d5: 8d 65 f8 lea -0x8(%ebp),%esp
d8: 5b pop %ebx
d9: 5e pop %esi
da: 5d pop %ebp
db: c3 ret
printf(1, "cat: write error\n");
dc: 83 ec 08 sub $0x8,%esp
df: 68 38 08 00 00 push $0x838
e4: 6a 01 push $0x1
e6: e8 e5 03 00 00 call 4d0 <printf>
exit();
eb: e8 71 02 00 00 call 361 <exit>
printf(1, "cat: read error\n");
f0: 50 push %eax
f1: 50 push %eax
f2: 68 4a 08 00 00 push $0x84a
f7: 6a 01 push $0x1
f9: e8 d2 03 00 00 call 4d0 <printf>
exit();
fe: e8 5e 02 00 00 call 361 <exit>
103: 66 90 xchg %ax,%ax
105: 66 90 xchg %ax,%ax
107: 66 90 xchg %ax,%ax
109: 66 90 xchg %ax,%ax
10b: 66 90 xchg %ax,%ax
10d: 66 90 xchg %ax,%ax
10f: 90 nop
00000110 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
110: 55 push %ebp
char *os;
os = s;
while((*s++ = *t++) != 0)
111: 31 d2 xor %edx,%edx
{
113: 89 e5 mov %esp,%ebp
115: 53 push %ebx
116: 8b 45 08 mov 0x8(%ebp),%eax
119: 8b 5d 0c mov 0xc(%ebp),%ebx
11c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
while((*s++ = *t++) != 0)
120: 0f b6 0c 13 movzbl (%ebx,%edx,1),%ecx
124: 88 0c 10 mov %cl,(%eax,%edx,1)
127: 83 c2 01 add $0x1,%edx
12a: 84 c9 test %cl,%cl
12c: 75 f2 jne 120 <strcpy+0x10>
;
return os;
}
12e: 5b pop %ebx
12f: 5d pop %ebp
130: c3 ret
131: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
138: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
13f: 90 nop
00000140 <strcmp>:
int
strcmp(const char *p, const char *q)
{
140: 55 push %ebp
141: 89 e5 mov %esp,%ebp
143: 56 push %esi
144: 53 push %ebx
145: 8b 5d 08 mov 0x8(%ebp),%ebx
148: 8b 75 0c mov 0xc(%ebp),%esi
while(*p && *p == *q)
14b: 0f b6 13 movzbl (%ebx),%edx
14e: 0f b6 0e movzbl (%esi),%ecx
151: 84 d2 test %dl,%dl
153: 74 1e je 173 <strcmp+0x33>
155: b8 01 00 00 00 mov $0x1,%eax
15a: 38 ca cmp %cl,%dl
15c: 74 09 je 167 <strcmp+0x27>
15e: eb 20 jmp 180 <strcmp+0x40>
160: 83 c0 01 add $0x1,%eax
163: 38 ca cmp %cl,%dl
165: 75 19 jne 180 <strcmp+0x40>
167: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx
16b: 0f b6 0c 06 movzbl (%esi,%eax,1),%ecx
16f: 84 d2 test %dl,%dl
171: 75 ed jne 160 <strcmp+0x20>
173: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
}
175: 5b pop %ebx
176: 5e pop %esi
return (uchar)*p - (uchar)*q;
177: 29 c8 sub %ecx,%eax
}
179: 5d pop %ebp
17a: c3 ret
17b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
17f: 90 nop
180: 0f b6 c2 movzbl %dl,%eax
183: 5b pop %ebx
184: 5e pop %esi
return (uchar)*p - (uchar)*q;
185: 29 c8 sub %ecx,%eax
}
187: 5d pop %ebp
188: c3 ret
189: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000190 <strlen>:
uint
strlen(const char *s)
{
190: 55 push %ebp
191: 89 e5 mov %esp,%ebp
193: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
196: 80 39 00 cmpb $0x0,(%ecx)
199: 74 15 je 1b0 <strlen+0x20>
19b: 31 d2 xor %edx,%edx
19d: 8d 76 00 lea 0x0(%esi),%esi
1a0: 83 c2 01 add $0x1,%edx
1a3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
1a7: 89 d0 mov %edx,%eax
1a9: 75 f5 jne 1a0 <strlen+0x10>
;
return n;
}
1ab: 5d pop %ebp
1ac: c3 ret
1ad: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
1b0: 31 c0 xor %eax,%eax
}
1b2: 5d pop %ebp
1b3: c3 ret
1b4: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1bb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1bf: 90 nop
000001c0 <memset>:
void*
memset(void *dst, int c, uint n)
{
1c0: 55 push %ebp
1c1: 89 e5 mov %esp,%ebp
1c3: 57 push %edi
1c4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
1c7: 8b 4d 10 mov 0x10(%ebp),%ecx
1ca: 8b 45 0c mov 0xc(%ebp),%eax
1cd: 89 d7 mov %edx,%edi
1cf: fc cld
1d0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
1d2: 89 d0 mov %edx,%eax
1d4: 5f pop %edi
1d5: 5d pop %ebp
1d6: c3 ret
1d7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1de: 66 90 xchg %ax,%ax
000001e0 <strchr>:
char*
strchr(const char *s, char c)
{
1e0: 55 push %ebp
1e1: 89 e5 mov %esp,%ebp
1e3: 53 push %ebx
1e4: 8b 45 08 mov 0x8(%ebp),%eax
1e7: 8b 55 0c mov 0xc(%ebp),%edx
for(; *s; s++)
1ea: 0f b6 18 movzbl (%eax),%ebx
1ed: 84 db test %bl,%bl
1ef: 74 1d je 20e <strchr+0x2e>
1f1: 89 d1 mov %edx,%ecx
if(*s == c)
1f3: 38 d3 cmp %dl,%bl
1f5: 75 0d jne 204 <strchr+0x24>
1f7: eb 17 jmp 210 <strchr+0x30>
1f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
200: 38 ca cmp %cl,%dl
202: 74 0c je 210 <strchr+0x30>
for(; *s; s++)
204: 83 c0 01 add $0x1,%eax
207: 0f b6 10 movzbl (%eax),%edx
20a: 84 d2 test %dl,%dl
20c: 75 f2 jne 200 <strchr+0x20>
return (char*)s;
return 0;
20e: 31 c0 xor %eax,%eax
}
210: 5b pop %ebx
211: 5d pop %ebp
212: c3 ret
213: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
21a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00000220 <gets>:
char*
gets(char *buf, int max)
{
220: 55 push %ebp
221: 89 e5 mov %esp,%ebp
223: 57 push %edi
224: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
225: 31 f6 xor %esi,%esi
{
227: 53 push %ebx
228: 89 f3 mov %esi,%ebx
22a: 83 ec 1c sub $0x1c,%esp
22d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
230: eb 2f jmp 261 <gets+0x41>
232: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
238: 83 ec 04 sub $0x4,%esp
23b: 8d 45 e7 lea -0x19(%ebp),%eax
23e: 6a 01 push $0x1
240: 50 push %eax
241: 6a 00 push $0x0
243: e8 31 01 00 00 call 379 <read>
if(cc < 1)
248: 83 c4 10 add $0x10,%esp
24b: 85 c0 test %eax,%eax
24d: 7e 1c jle 26b <gets+0x4b>
break;
buf[i++] = c;
24f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
253: 83 c7 01 add $0x1,%edi
256: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
259: 3c 0a cmp $0xa,%al
25b: 74 23 je 280 <gets+0x60>
25d: 3c 0d cmp $0xd,%al
25f: 74 1f je 280 <gets+0x60>
for(i=0; i+1 < max; ){
261: 83 c3 01 add $0x1,%ebx
264: 89 fe mov %edi,%esi
266: 3b 5d 0c cmp 0xc(%ebp),%ebx
269: 7c cd jl 238 <gets+0x18>
26b: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
26d: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
270: c6 03 00 movb $0x0,(%ebx)
}
273: 8d 65 f4 lea -0xc(%ebp),%esp
276: 5b pop %ebx
277: 5e pop %esi
278: 5f pop %edi
279: 5d pop %ebp
27a: c3 ret
27b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
27f: 90 nop
280: 8b 75 08 mov 0x8(%ebp),%esi
283: 8b 45 08 mov 0x8(%ebp),%eax
286: 01 de add %ebx,%esi
288: 89 f3 mov %esi,%ebx
buf[i] = '\0';
28a: c6 03 00 movb $0x0,(%ebx)
}
28d: 8d 65 f4 lea -0xc(%ebp),%esp
290: 5b pop %ebx
291: 5e pop %esi
292: 5f pop %edi
293: 5d pop %ebp
294: c3 ret
295: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
29c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
000002a0 <stat>:
int
stat(const char *n, struct stat *st)
{
2a0: 55 push %ebp
2a1: 89 e5 mov %esp,%ebp
2a3: 56 push %esi
2a4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
2a5: 83 ec 08 sub $0x8,%esp
2a8: 6a 00 push $0x0
2aa: ff 75 08 pushl 0x8(%ebp)
2ad: e8 ef 00 00 00 call 3a1 <open>
if(fd < 0)
2b2: 83 c4 10 add $0x10,%esp
2b5: 85 c0 test %eax,%eax
2b7: 78 27 js 2e0 <stat+0x40>
return -1;
r = fstat(fd, st);
2b9: 83 ec 08 sub $0x8,%esp
2bc: ff 75 0c pushl 0xc(%ebp)
2bf: 89 c3 mov %eax,%ebx
2c1: 50 push %eax
2c2: e8 f2 00 00 00 call 3b9 <fstat>
close(fd);
2c7: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
2ca: 89 c6 mov %eax,%esi
close(fd);
2cc: e8 b8 00 00 00 call 389 <close>
return r;
2d1: 83 c4 10 add $0x10,%esp
}
2d4: 8d 65 f8 lea -0x8(%ebp),%esp
2d7: 89 f0 mov %esi,%eax
2d9: 5b pop %ebx
2da: 5e pop %esi
2db: 5d pop %ebp
2dc: c3 ret
2dd: 8d 76 00 lea 0x0(%esi),%esi
return -1;
2e0: be ff ff ff ff mov $0xffffffff,%esi
2e5: eb ed jmp 2d4 <stat+0x34>
2e7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
2ee: 66 90 xchg %ax,%ax
000002f0 <atoi>:
int
atoi(const char *s)
{
2f0: 55 push %ebp
2f1: 89 e5 mov %esp,%ebp
2f3: 53 push %ebx
2f4: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
2f7: 0f be 11 movsbl (%ecx),%edx
2fa: 8d 42 d0 lea -0x30(%edx),%eax
2fd: 3c 09 cmp $0x9,%al
n = 0;
2ff: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
304: 77 1f ja 325 <atoi+0x35>
306: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
30d: 8d 76 00 lea 0x0(%esi),%esi
n = n*10 + *s++ - '0';
310: 83 c1 01 add $0x1,%ecx
313: 8d 04 80 lea (%eax,%eax,4),%eax
316: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
31a: 0f be 11 movsbl (%ecx),%edx
31d: 8d 5a d0 lea -0x30(%edx),%ebx
320: 80 fb 09 cmp $0x9,%bl
323: 76 eb jbe 310 <atoi+0x20>
return n;
}
325: 5b pop %ebx
326: 5d pop %ebp
327: c3 ret
328: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
32f: 90 nop
00000330 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 57 push %edi
334: 8b 55 10 mov 0x10(%ebp),%edx
337: 8b 45 08 mov 0x8(%ebp),%eax
33a: 56 push %esi
33b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
33e: 85 d2 test %edx,%edx
340: 7e 13 jle 355 <memmove+0x25>
342: 01 c2 add %eax,%edx
dst = vdst;
344: 89 c7 mov %eax,%edi
346: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
34d: 8d 76 00 lea 0x0(%esi),%esi
*dst++ = *src++;
350: a4 movsb %ds:(%esi),%es:(%edi)
while(n-- > 0)
351: 39 fa cmp %edi,%edx
353: 75 fb jne 350 <memmove+0x20>
return vdst;
}
355: 5e pop %esi
356: 5f pop %edi
357: 5d pop %ebp
358: c3 ret
00000359 <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
359: b8 01 00 00 00 mov $0x1,%eax
35e: cd 40 int $0x40
360: c3 ret
00000361 <exit>:
SYSCALL(exit)
361: b8 02 00 00 00 mov $0x2,%eax
366: cd 40 int $0x40
368: c3 ret
00000369 <wait>:
SYSCALL(wait)
369: b8 03 00 00 00 mov $0x3,%eax
36e: cd 40 int $0x40
370: c3 ret
00000371 <pipe>:
SYSCALL(pipe)
371: b8 04 00 00 00 mov $0x4,%eax
376: cd 40 int $0x40
378: c3 ret
00000379 <read>:
SYSCALL(read)
379: b8 05 00 00 00 mov $0x5,%eax
37e: cd 40 int $0x40
380: c3 ret
00000381 <write>:
SYSCALL(write)
381: b8 10 00 00 00 mov $0x10,%eax
386: cd 40 int $0x40
388: c3 ret
00000389 <close>:
SYSCALL(close)
389: b8 15 00 00 00 mov $0x15,%eax
38e: cd 40 int $0x40
390: c3 ret
00000391 <kill>:
SYSCALL(kill)
391: b8 06 00 00 00 mov $0x6,%eax
396: cd 40 int $0x40
398: c3 ret
00000399 <exec>:
SYSCALL(exec)
399: b8 07 00 00 00 mov $0x7,%eax
39e: cd 40 int $0x40
3a0: c3 ret
000003a1 <open>:
SYSCALL(open)
3a1: b8 0f 00 00 00 mov $0xf,%eax
3a6: cd 40 int $0x40
3a8: c3 ret
000003a9 <mknod>:
SYSCALL(mknod)
3a9: b8 11 00 00 00 mov $0x11,%eax
3ae: cd 40 int $0x40
3b0: c3 ret
000003b1 <unlink>:
SYSCALL(unlink)
3b1: b8 12 00 00 00 mov $0x12,%eax
3b6: cd 40 int $0x40
3b8: c3 ret
000003b9 <fstat>:
SYSCALL(fstat)
3b9: b8 08 00 00 00 mov $0x8,%eax
3be: cd 40 int $0x40
3c0: c3 ret
000003c1 <link>:
SYSCALL(link)
3c1: b8 13 00 00 00 mov $0x13,%eax
3c6: cd 40 int $0x40
3c8: c3 ret
000003c9 <mkdir>:
SYSCALL(mkdir)
3c9: b8 14 00 00 00 mov $0x14,%eax
3ce: cd 40 int $0x40
3d0: c3 ret
000003d1 <chdir>:
SYSCALL(chdir)
3d1: b8 09 00 00 00 mov $0x9,%eax
3d6: cd 40 int $0x40
3d8: c3 ret
000003d9 <dup>:
SYSCALL(dup)
3d9: b8 0a 00 00 00 mov $0xa,%eax
3de: cd 40 int $0x40
3e0: c3 ret
000003e1 <getpid>:
SYSCALL(getpid)
3e1: b8 0b 00 00 00 mov $0xb,%eax
3e6: cd 40 int $0x40
3e8: c3 ret
000003e9 <sbrk>:
SYSCALL(sbrk)
3e9: b8 0c 00 00 00 mov $0xc,%eax
3ee: cd 40 int $0x40
3f0: c3 ret
000003f1 <sleep>:
SYSCALL(sleep)
3f1: b8 0d 00 00 00 mov $0xd,%eax
3f6: cd 40 int $0x40
3f8: c3 ret
000003f9 <uptime>:
SYSCALL(uptime)
3f9: b8 0e 00 00 00 mov $0xe,%eax
3fe: cd 40 int $0x40
400: c3 ret
00000401 <waitpid>:
SYSCALL(waitpid)
401: b8 16 00 00 00 mov $0x16,%eax
406: cd 40 int $0x40
408: c3 ret
409: 66 90 xchg %ax,%ax
40b: 66 90 xchg %ax,%ax
40d: 66 90 xchg %ax,%ax
40f: 90 nop
00000410 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
410: 55 push %ebp
411: 89 e5 mov %esp,%ebp
413: 57 push %edi
414: 56 push %esi
415: 53 push %ebx
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
416: 89 d3 mov %edx,%ebx
{
418: 83 ec 3c sub $0x3c,%esp
41b: 89 45 bc mov %eax,-0x44(%ebp)
if(sgn && xx < 0){
41e: 85 d2 test %edx,%edx
420: 0f 89 92 00 00 00 jns 4b8 <printint+0xa8>
426: f6 45 08 01 testb $0x1,0x8(%ebp)
42a: 0f 84 88 00 00 00 je 4b8 <printint+0xa8>
neg = 1;
430: c7 45 c0 01 00 00 00 movl $0x1,-0x40(%ebp)
x = -xx;
437: f7 db neg %ebx
} else {
x = xx;
}
i = 0;
439: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
440: 8d 75 d7 lea -0x29(%ebp),%esi
443: eb 08 jmp 44d <printint+0x3d>
445: 8d 76 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
448: 89 7d c4 mov %edi,-0x3c(%ebp)
}while((x /= base) != 0);
44b: 89 c3 mov %eax,%ebx
buf[i++] = digits[x % base];
44d: 89 d8 mov %ebx,%eax
44f: 31 d2 xor %edx,%edx
451: 8b 7d c4 mov -0x3c(%ebp),%edi
454: f7 f1 div %ecx
456: 83 c7 01 add $0x1,%edi
459: 0f b6 92 78 08 00 00 movzbl 0x878(%edx),%edx
460: 88 14 3e mov %dl,(%esi,%edi,1)
}while((x /= base) != 0);
463: 39 d9 cmp %ebx,%ecx
465: 76 e1 jbe 448 <printint+0x38>
if(neg)
467: 8b 45 c0 mov -0x40(%ebp),%eax
46a: 85 c0 test %eax,%eax
46c: 74 0d je 47b <printint+0x6b>
buf[i++] = '-';
46e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
473: ba 2d 00 00 00 mov $0x2d,%edx
buf[i++] = digits[x % base];
478: 89 7d c4 mov %edi,-0x3c(%ebp)
47b: 8b 45 c4 mov -0x3c(%ebp),%eax
47e: 8b 7d bc mov -0x44(%ebp),%edi
481: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx
485: eb 0f jmp 496 <printint+0x86>
487: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
48e: 66 90 xchg %ax,%ax
490: 0f b6 13 movzbl (%ebx),%edx
493: 83 eb 01 sub $0x1,%ebx
write(fd, &c, 1);
496: 83 ec 04 sub $0x4,%esp
499: 88 55 d7 mov %dl,-0x29(%ebp)
49c: 6a 01 push $0x1
49e: 56 push %esi
49f: 57 push %edi
4a0: e8 dc fe ff ff call 381 <write>
while(--i >= 0)
4a5: 83 c4 10 add $0x10,%esp
4a8: 39 de cmp %ebx,%esi
4aa: 75 e4 jne 490 <printint+0x80>
putc(fd, buf[i]);
}
4ac: 8d 65 f4 lea -0xc(%ebp),%esp
4af: 5b pop %ebx
4b0: 5e pop %esi
4b1: 5f pop %edi
4b2: 5d pop %ebp
4b3: c3 ret
4b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
4b8: c7 45 c0 00 00 00 00 movl $0x0,-0x40(%ebp)
4bf: e9 75 ff ff ff jmp 439 <printint+0x29>
4c4: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
4cb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
4cf: 90 nop
000004d0 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
4d0: 55 push %ebp
4d1: 89 e5 mov %esp,%ebp
4d3: 57 push %edi
4d4: 56 push %esi
4d5: 53 push %ebx
4d6: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4d9: 8b 75 0c mov 0xc(%ebp),%esi
4dc: 0f b6 1e movzbl (%esi),%ebx
4df: 84 db test %bl,%bl
4e1: 0f 84 b9 00 00 00 je 5a0 <printf+0xd0>
ap = (uint*)(void*)&fmt + 1;
4e7: 8d 45 10 lea 0x10(%ebp),%eax
4ea: 83 c6 01 add $0x1,%esi
write(fd, &c, 1);
4ed: 8d 7d e7 lea -0x19(%ebp),%edi
state = 0;
4f0: 31 d2 xor %edx,%edx
ap = (uint*)(void*)&fmt + 1;
4f2: 89 45 d0 mov %eax,-0x30(%ebp)
4f5: eb 38 jmp 52f <printf+0x5f>
4f7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
4fe: 66 90 xchg %ax,%ax
500: 89 55 d4 mov %edx,-0x2c(%ebp)
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
state = '%';
503: ba 25 00 00 00 mov $0x25,%edx
if(c == '%'){
508: 83 f8 25 cmp $0x25,%eax
50b: 74 17 je 524 <printf+0x54>
write(fd, &c, 1);
50d: 83 ec 04 sub $0x4,%esp
510: 88 5d e7 mov %bl,-0x19(%ebp)
513: 6a 01 push $0x1
515: 57 push %edi
516: ff 75 08 pushl 0x8(%ebp)
519: e8 63 fe ff ff call 381 <write>
51e: 8b 55 d4 mov -0x2c(%ebp),%edx
} else {
putc(fd, c);
521: 83 c4 10 add $0x10,%esp
524: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
527: 0f b6 5e ff movzbl -0x1(%esi),%ebx
52b: 84 db test %bl,%bl
52d: 74 71 je 5a0 <printf+0xd0>
c = fmt[i] & 0xff;
52f: 0f be cb movsbl %bl,%ecx
532: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
535: 85 d2 test %edx,%edx
537: 74 c7 je 500 <printf+0x30>
}
} else if(state == '%'){
539: 83 fa 25 cmp $0x25,%edx
53c: 75 e6 jne 524 <printf+0x54>
if(c == 'd'){
53e: 83 f8 64 cmp $0x64,%eax
541: 0f 84 99 00 00 00 je 5e0 <printf+0x110>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
547: 81 e1 f7 00 00 00 and $0xf7,%ecx
54d: 83 f9 70 cmp $0x70,%ecx
550: 74 5e je 5b0 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
552: 83 f8 73 cmp $0x73,%eax
555: 0f 84 d5 00 00 00 je 630 <printf+0x160>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
55b: 83 f8 63 cmp $0x63,%eax
55e: 0f 84 8c 00 00 00 je 5f0 <printf+0x120>
putc(fd, *ap);
ap++;
} else if(c == '%'){
564: 83 f8 25 cmp $0x25,%eax
567: 0f 84 b3 00 00 00 je 620 <printf+0x150>
write(fd, &c, 1);
56d: 83 ec 04 sub $0x4,%esp
570: c6 45 e7 25 movb $0x25,-0x19(%ebp)
574: 6a 01 push $0x1
576: 57 push %edi
577: ff 75 08 pushl 0x8(%ebp)
57a: e8 02 fe ff ff call 381 <write>
putc(fd, c);
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
57f: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
582: 83 c4 0c add $0xc,%esp
585: 6a 01 push $0x1
587: 83 c6 01 add $0x1,%esi
58a: 57 push %edi
58b: ff 75 08 pushl 0x8(%ebp)
58e: e8 ee fd ff ff call 381 <write>
for(i = 0; fmt[i]; i++){
593: 0f b6 5e ff movzbl -0x1(%esi),%ebx
putc(fd, c);
597: 83 c4 10 add $0x10,%esp
}
state = 0;
59a: 31 d2 xor %edx,%edx
for(i = 0; fmt[i]; i++){
59c: 84 db test %bl,%bl
59e: 75 8f jne 52f <printf+0x5f>
}
}
}
5a0: 8d 65 f4 lea -0xc(%ebp),%esp
5a3: 5b pop %ebx
5a4: 5e pop %esi
5a5: 5f pop %edi
5a6: 5d pop %ebp
5a7: c3 ret
5a8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
5af: 90 nop
printint(fd, *ap, 16, 0);
5b0: 83 ec 0c sub $0xc,%esp
5b3: b9 10 00 00 00 mov $0x10,%ecx
5b8: 6a 00 push $0x0
5ba: 8b 5d d0 mov -0x30(%ebp),%ebx
5bd: 8b 45 08 mov 0x8(%ebp),%eax
5c0: 8b 13 mov (%ebx),%edx
5c2: e8 49 fe ff ff call 410 <printint>
ap++;
5c7: 89 d8 mov %ebx,%eax
5c9: 83 c4 10 add $0x10,%esp
state = 0;
5cc: 31 d2 xor %edx,%edx
ap++;
5ce: 83 c0 04 add $0x4,%eax
5d1: 89 45 d0 mov %eax,-0x30(%ebp)
5d4: e9 4b ff ff ff jmp 524 <printf+0x54>
5d9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
printint(fd, *ap, 10, 1);
5e0: 83 ec 0c sub $0xc,%esp
5e3: b9 0a 00 00 00 mov $0xa,%ecx
5e8: 6a 01 push $0x1
5ea: eb ce jmp 5ba <printf+0xea>
5ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
putc(fd, *ap);
5f0: 8b 5d d0 mov -0x30(%ebp),%ebx
write(fd, &c, 1);
5f3: 83 ec 04 sub $0x4,%esp
putc(fd, *ap);
5f6: 8b 03 mov (%ebx),%eax
write(fd, &c, 1);
5f8: 6a 01 push $0x1
ap++;
5fa: 83 c3 04 add $0x4,%ebx
write(fd, &c, 1);
5fd: 57 push %edi
5fe: ff 75 08 pushl 0x8(%ebp)
putc(fd, *ap);
601: 88 45 e7 mov %al,-0x19(%ebp)
write(fd, &c, 1);
604: e8 78 fd ff ff call 381 <write>
ap++;
609: 89 5d d0 mov %ebx,-0x30(%ebp)
60c: 83 c4 10 add $0x10,%esp
state = 0;
60f: 31 d2 xor %edx,%edx
611: e9 0e ff ff ff jmp 524 <printf+0x54>
616: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
61d: 8d 76 00 lea 0x0(%esi),%esi
putc(fd, c);
620: 88 5d e7 mov %bl,-0x19(%ebp)
write(fd, &c, 1);
623: 83 ec 04 sub $0x4,%esp
626: e9 5a ff ff ff jmp 585 <printf+0xb5>
62b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
62f: 90 nop
s = (char*)*ap;
630: 8b 45 d0 mov -0x30(%ebp),%eax
633: 8b 18 mov (%eax),%ebx
ap++;
635: 83 c0 04 add $0x4,%eax
638: 89 45 d0 mov %eax,-0x30(%ebp)
if(s == 0)
63b: 85 db test %ebx,%ebx
63d: 74 17 je 656 <printf+0x186>
while(*s != 0){
63f: 0f b6 03 movzbl (%ebx),%eax
state = 0;
642: 31 d2 xor %edx,%edx
while(*s != 0){
644: 84 c0 test %al,%al
646: 0f 84 d8 fe ff ff je 524 <printf+0x54>
64c: 89 75 d4 mov %esi,-0x2c(%ebp)
64f: 89 de mov %ebx,%esi
651: 8b 5d 08 mov 0x8(%ebp),%ebx
654: eb 1a jmp 670 <printf+0x1a0>
s = "(null)";
656: bb 70 08 00 00 mov $0x870,%ebx
while(*s != 0){
65b: 89 75 d4 mov %esi,-0x2c(%ebp)
65e: b8 28 00 00 00 mov $0x28,%eax