-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls.asm
3632 lines (3409 loc) · 127 KB
/
ls.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
_ls: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
close(fd);
}
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: 53 push %ebx
10: 51 push %ecx
11: bb 01 00 00 00 mov $0x1,%ebx
16: 83 ec 08 sub $0x8,%esp
19: 8b 31 mov (%ecx),%esi
1b: 8b 79 04 mov 0x4(%ecx),%edi
int i;
if(argc < 2){
1e: 83 fe 01 cmp $0x1,%esi
21: 7e 1f jle 42 <main+0x42>
23: 90 nop
24: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
ls(".");
exit();
}
for(i=1; i<argc; i++)
ls(argv[i]);
28: 83 ec 0c sub $0xc,%esp
2b: ff 34 9f pushl (%edi,%ebx,4)
if(argc < 2){
ls(".");
exit();
}
for(i=1; i<argc; i++)
2e: 83 c3 01 add $0x1,%ebx
ls(argv[i]);
31: e8 ca 00 00 00 call 100 <ls>
if(argc < 2){
ls(".");
exit();
}
for(i=1; i<argc; i++)
36: 83 c4 10 add $0x10,%esp
39: 39 de cmp %ebx,%esi
3b: 75 eb jne 28 <main+0x28>
ls(argv[i]);
exit();
3d: e8 40 05 00 00 call 582 <exit>
main(int argc, char *argv[])
{
int i;
if(argc < 2){
ls(".");
42: 83 ec 0c sub $0xc,%esp
45: 68 24 15 00 00 push $0x1524
4a: e8 b1 00 00 00 call 100 <ls>
exit();
4f: e8 2e 05 00 00 call 582 <exit>
54: 66 90 xchg %ax,%ax
56: 66 90 xchg %ax,%ax
58: 66 90 xchg %ax,%ax
5a: 66 90 xchg %ax,%ax
5c: 66 90 xchg %ax,%ax
5e: 66 90 xchg %ax,%ax
00000060 <fmtname>:
#include "user.h"
#include "fs.h"
char*
fmtname(char *path)
{
60: 55 push %ebp
61: 89 e5 mov %esp,%ebp
63: 56 push %esi
64: 53 push %ebx
65: 8b 5d 08 mov 0x8(%ebp),%ebx
static char buf[DIRSIZ+1];
char *p;
// Find first character after last slash.
for(p=path+strlen(path); p >= path && *p != '/'; p--)
68: 83 ec 0c sub $0xc,%esp
6b: 53 push %ebx
6c: e8 4f 03 00 00 call 3c0 <strlen>
71: 83 c4 10 add $0x10,%esp
74: 01 d8 add %ebx,%eax
76: 73 0f jae 87 <fmtname+0x27>
78: eb 12 jmp 8c <fmtname+0x2c>
7a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
80: 83 e8 01 sub $0x1,%eax
83: 39 c3 cmp %eax,%ebx
85: 77 05 ja 8c <fmtname+0x2c>
87: 80 38 2f cmpb $0x2f,(%eax)
8a: 75 f4 jne 80 <fmtname+0x20>
;
p++;
8c: 8d 58 01 lea 0x1(%eax),%ebx
// Return blank-padded name.
if(strlen(p) >= DIRSIZ)
8f: 83 ec 0c sub $0xc,%esp
92: 53 push %ebx
93: e8 28 03 00 00 call 3c0 <strlen>
98: 83 c4 10 add $0x10,%esp
9b: 83 f8 0d cmp $0xd,%eax
9e: 77 4a ja ea <fmtname+0x8a>
return p;
memmove(buf, p, strlen(p));
a0: 83 ec 0c sub $0xc,%esp
a3: 53 push %ebx
a4: e8 17 03 00 00 call 3c0 <strlen>
a9: 83 c4 0c add $0xc,%esp
ac: 50 push %eax
ad: 53 push %ebx
ae: 68 00 1d 00 00 push $0x1d00
b3: e8 98 04 00 00 call 550 <memmove>
memset(buf+strlen(p), ' ', DIRSIZ-strlen(p));
b8: 89 1c 24 mov %ebx,(%esp)
bb: e8 00 03 00 00 call 3c0 <strlen>
c0: 89 1c 24 mov %ebx,(%esp)
c3: 89 c6 mov %eax,%esi
return buf;
c5: bb 00 1d 00 00 mov $0x1d00,%ebx
// Return blank-padded name.
if(strlen(p) >= DIRSIZ)
return p;
memmove(buf, p, strlen(p));
memset(buf+strlen(p), ' ', DIRSIZ-strlen(p));
ca: e8 f1 02 00 00 call 3c0 <strlen>
cf: ba 0e 00 00 00 mov $0xe,%edx
d4: 83 c4 0c add $0xc,%esp
d7: 05 00 1d 00 00 add $0x1d00,%eax
dc: 29 f2 sub %esi,%edx
de: 52 push %edx
df: 6a 20 push $0x20
e1: 50 push %eax
e2: e8 09 03 00 00 call 3f0 <memset>
return buf;
e7: 83 c4 10 add $0x10,%esp
}
ea: 8d 65 f8 lea -0x8(%ebp),%esp
ed: 89 d8 mov %ebx,%eax
ef: 5b pop %ebx
f0: 5e pop %esi
f1: 5d pop %ebp
f2: c3 ret
f3: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000100 <ls>:
void
ls(char *path)
{
100: 55 push %ebp
101: 89 e5 mov %esp,%ebp
103: 57 push %edi
104: 56 push %esi
105: 53 push %ebx
106: 81 ec 64 02 00 00 sub $0x264,%esp
10c: 8b 7d 08 mov 0x8(%ebp),%edi
char buf[512], *p;
int fd;
struct dirent de;
struct stat st;
if((fd = open(path, 0)) < 0){
10f: 6a 00 push $0x0
111: 57 push %edi
112: e8 ab 04 00 00 call 5c2 <open>
117: 83 c4 10 add $0x10,%esp
11a: 85 c0 test %eax,%eax
11c: 0f 88 9e 01 00 00 js 2c0 <ls+0x1c0>
printf(2, "ls: cannot open %s\n", path);
return;
}
if(fstat(fd, &st) < 0){
122: 8d b5 d4 fd ff ff lea -0x22c(%ebp),%esi
128: 83 ec 08 sub $0x8,%esp
12b: 89 c3 mov %eax,%ebx
12d: 56 push %esi
12e: 50 push %eax
12f: e8 a6 04 00 00 call 5da <fstat>
134: 83 c4 10 add $0x10,%esp
137: 85 c0 test %eax,%eax
139: 0f 88 c1 01 00 00 js 300 <ls+0x200>
printf(2, "ls: cannot stat %s\n", path);
close(fd);
return;
}
switch(st.type){
13f: 0f b7 85 d4 fd ff ff movzwl -0x22c(%ebp),%eax
146: 66 83 f8 01 cmp $0x1,%ax
14a: 74 54 je 1a0 <ls+0xa0>
14c: 66 83 f8 02 cmp $0x2,%ax
150: 75 37 jne 189 <ls+0x89>
case T_FILE:
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
152: 83 ec 0c sub $0xc,%esp
155: 8b 95 e4 fd ff ff mov -0x21c(%ebp),%edx
15b: 8b b5 dc fd ff ff mov -0x224(%ebp),%esi
161: 57 push %edi
162: 89 95 b4 fd ff ff mov %edx,-0x24c(%ebp)
168: e8 f3 fe ff ff call 60 <fmtname>
16d: 8b 95 b4 fd ff ff mov -0x24c(%ebp),%edx
173: 59 pop %ecx
174: 5f pop %edi
175: 52 push %edx
176: 56 push %esi
177: 6a 02 push $0x2
179: 50 push %eax
17a: 68 04 15 00 00 push $0x1504
17f: 6a 01 push $0x1
181: e8 6a 05 00 00 call 6f0 <printf>
break;
186: 83 c4 20 add $0x20,%esp
}
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
}
break;
}
close(fd);
189: 83 ec 0c sub $0xc,%esp
18c: 53 push %ebx
18d: e8 18 04 00 00 call 5aa <close>
192: 83 c4 10 add $0x10,%esp
}
195: 8d 65 f4 lea -0xc(%ebp),%esp
198: 5b pop %ebx
199: 5e pop %esi
19a: 5f pop %edi
19b: 5d pop %ebp
19c: c3 ret
19d: 8d 76 00 lea 0x0(%esi),%esi
case T_FILE:
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
break;
case T_DIR:
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
1a0: 83 ec 0c sub $0xc,%esp
1a3: 57 push %edi
1a4: e8 17 02 00 00 call 3c0 <strlen>
1a9: 83 c0 10 add $0x10,%eax
1ac: 83 c4 10 add $0x10,%esp
1af: 3d 00 02 00 00 cmp $0x200,%eax
1b4: 0f 87 26 01 00 00 ja 2e0 <ls+0x1e0>
printf(1, "ls: path too long\n");
break;
}
strcpy(buf, path);
1ba: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
1c0: 83 ec 08 sub $0x8,%esp
1c3: 57 push %edi
1c4: 8d bd c4 fd ff ff lea -0x23c(%ebp),%edi
1ca: 50 push %eax
1cb: e8 70 01 00 00 call 340 <strcpy>
p = buf+strlen(buf);
1d0: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
1d6: 89 04 24 mov %eax,(%esp)
1d9: e8 e2 01 00 00 call 3c0 <strlen>
1de: 8d 95 e8 fd ff ff lea -0x218(%ebp),%edx
*p++ = '/';
while(read(fd, &de, sizeof(de)) == sizeof(de)){
1e4: 83 c4 10 add $0x10,%esp
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
printf(1, "ls: path too long\n");
break;
}
strcpy(buf, path);
p = buf+strlen(buf);
1e7: 8d 0c 02 lea (%edx,%eax,1),%ecx
*p++ = '/';
1ea: 8d 84 05 e9 fd ff ff lea -0x217(%ebp,%eax,1),%eax
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
printf(1, "ls: path too long\n");
break;
}
strcpy(buf, path);
p = buf+strlen(buf);
1f1: 89 8d a8 fd ff ff mov %ecx,-0x258(%ebp)
*p++ = '/';
1f7: 89 85 a4 fd ff ff mov %eax,-0x25c(%ebp)
1fd: c6 01 2f movb $0x2f,(%ecx)
while(read(fd, &de, sizeof(de)) == sizeof(de)){
200: 83 ec 04 sub $0x4,%esp
203: 6a 10 push $0x10
205: 57 push %edi
206: 53 push %ebx
207: e8 8e 03 00 00 call 59a <read>
20c: 83 c4 10 add $0x10,%esp
20f: 83 f8 10 cmp $0x10,%eax
212: 0f 85 71 ff ff ff jne 189 <ls+0x89>
if(de.inum == 0)
218: 66 83 bd c4 fd ff ff cmpw $0x0,-0x23c(%ebp)
21f: 00
220: 74 de je 200 <ls+0x100>
continue;
memmove(p, de.name, DIRSIZ);
222: 8d 85 c6 fd ff ff lea -0x23a(%ebp),%eax
228: 83 ec 04 sub $0x4,%esp
22b: 6a 0e push $0xe
22d: 50 push %eax
22e: ff b5 a4 fd ff ff pushl -0x25c(%ebp)
234: e8 17 03 00 00 call 550 <memmove>
p[DIRSIZ] = 0;
239: 8b 85 a8 fd ff ff mov -0x258(%ebp),%eax
23f: c6 40 0f 00 movb $0x0,0xf(%eax)
if(stat(buf, &st) < 0){
243: 58 pop %eax
244: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
24a: 5a pop %edx
24b: 56 push %esi
24c: 50 push %eax
24d: e8 6e 02 00 00 call 4c0 <stat>
252: 83 c4 10 add $0x10,%esp
255: 85 c0 test %eax,%eax
257: 0f 88 c3 00 00 00 js 320 <ls+0x220>
printf(1, "ls: cannot stat %s\n", buf);
continue;
}
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
25d: 8b 8d e4 fd ff ff mov -0x21c(%ebp),%ecx
263: 0f bf 85 d4 fd ff ff movswl -0x22c(%ebp),%eax
26a: 83 ec 0c sub $0xc,%esp
26d: 8b 95 dc fd ff ff mov -0x224(%ebp),%edx
273: 89 8d ac fd ff ff mov %ecx,-0x254(%ebp)
279: 8d 8d e8 fd ff ff lea -0x218(%ebp),%ecx
27f: 89 95 b0 fd ff ff mov %edx,-0x250(%ebp)
285: 89 85 b4 fd ff ff mov %eax,-0x24c(%ebp)
28b: 51 push %ecx
28c: e8 cf fd ff ff call 60 <fmtname>
291: 5a pop %edx
292: 8b 95 b0 fd ff ff mov -0x250(%ebp),%edx
298: 59 pop %ecx
299: 8b 8d ac fd ff ff mov -0x254(%ebp),%ecx
29f: 51 push %ecx
2a0: 52 push %edx
2a1: ff b5 b4 fd ff ff pushl -0x24c(%ebp)
2a7: 50 push %eax
2a8: 68 04 15 00 00 push $0x1504
2ad: 6a 01 push $0x1
2af: e8 3c 04 00 00 call 6f0 <printf>
2b4: 83 c4 20 add $0x20,%esp
2b7: e9 44 ff ff ff jmp 200 <ls+0x100>
2bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
int fd;
struct dirent de;
struct stat st;
if((fd = open(path, 0)) < 0){
printf(2, "ls: cannot open %s\n", path);
2c0: 83 ec 04 sub $0x4,%esp
2c3: 57 push %edi
2c4: 68 dc 14 00 00 push $0x14dc
2c9: 6a 02 push $0x2
2cb: e8 20 04 00 00 call 6f0 <printf>
return;
2d0: 83 c4 10 add $0x10,%esp
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
}
break;
}
close(fd);
}
2d3: 8d 65 f4 lea -0xc(%ebp),%esp
2d6: 5b pop %ebx
2d7: 5e pop %esi
2d8: 5f pop %edi
2d9: 5d pop %ebp
2da: c3 ret
2db: 90 nop
2dc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
break;
case T_DIR:
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
printf(1, "ls: path too long\n");
2e0: 83 ec 08 sub $0x8,%esp
2e3: 68 11 15 00 00 push $0x1511
2e8: 6a 01 push $0x1
2ea: e8 01 04 00 00 call 6f0 <printf>
break;
2ef: 83 c4 10 add $0x10,%esp
2f2: e9 92 fe ff ff jmp 189 <ls+0x89>
2f7: 89 f6 mov %esi,%esi
2f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
printf(2, "ls: cannot open %s\n", path);
return;
}
if(fstat(fd, &st) < 0){
printf(2, "ls: cannot stat %s\n", path);
300: 83 ec 04 sub $0x4,%esp
303: 57 push %edi
304: 68 f0 14 00 00 push $0x14f0
309: 6a 02 push $0x2
30b: e8 e0 03 00 00 call 6f0 <printf>
close(fd);
310: 89 1c 24 mov %ebx,(%esp)
313: e8 92 02 00 00 call 5aa <close>
return;
318: 83 c4 10 add $0x10,%esp
31b: e9 75 fe ff ff jmp 195 <ls+0x95>
if(de.inum == 0)
continue;
memmove(p, de.name, DIRSIZ);
p[DIRSIZ] = 0;
if(stat(buf, &st) < 0){
printf(1, "ls: cannot stat %s\n", buf);
320: 8d 85 e8 fd ff ff lea -0x218(%ebp),%eax
326: 83 ec 04 sub $0x4,%esp
329: 50 push %eax
32a: 68 f0 14 00 00 push $0x14f0
32f: 6a 01 push $0x1
331: e8 ba 03 00 00 call 6f0 <printf>
continue;
336: 83 c4 10 add $0x10,%esp
339: e9 c2 fe ff ff jmp 200 <ls+0x100>
33e: 66 90 xchg %ax,%ax
00000340 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
340: 55 push %ebp
341: 89 e5 mov %esp,%ebp
343: 53 push %ebx
344: 8b 45 08 mov 0x8(%ebp),%eax
347: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
34a: 89 c2 mov %eax,%edx
34c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
350: 83 c1 01 add $0x1,%ecx
353: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
357: 83 c2 01 add $0x1,%edx
35a: 84 db test %bl,%bl
35c: 88 5a ff mov %bl,-0x1(%edx)
35f: 75 ef jne 350 <strcpy+0x10>
;
return os;
}
361: 5b pop %ebx
362: 5d pop %ebp
363: c3 ret
364: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
36a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000370 <strcmp>:
int
strcmp(const char *p, const char *q)
{
370: 55 push %ebp
371: 89 e5 mov %esp,%ebp
373: 56 push %esi
374: 53 push %ebx
375: 8b 55 08 mov 0x8(%ebp),%edx
378: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
37b: 0f b6 02 movzbl (%edx),%eax
37e: 0f b6 19 movzbl (%ecx),%ebx
381: 84 c0 test %al,%al
383: 75 1e jne 3a3 <strcmp+0x33>
385: eb 29 jmp 3b0 <strcmp+0x40>
387: 89 f6 mov %esi,%esi
389: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
390: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
393: 0f b6 02 movzbl (%edx),%eax
p++, q++;
396: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
399: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
39d: 84 c0 test %al,%al
39f: 74 0f je 3b0 <strcmp+0x40>
3a1: 89 f1 mov %esi,%ecx
3a3: 38 d8 cmp %bl,%al
3a5: 74 e9 je 390 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
3a7: 29 d8 sub %ebx,%eax
}
3a9: 5b pop %ebx
3aa: 5e pop %esi
3ab: 5d pop %ebp
3ac: c3 ret
3ad: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
3b0: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
3b2: 29 d8 sub %ebx,%eax
}
3b4: 5b pop %ebx
3b5: 5e pop %esi
3b6: 5d pop %ebp
3b7: c3 ret
3b8: 90 nop
3b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000003c0 <strlen>:
uint
strlen(char *s)
{
3c0: 55 push %ebp
3c1: 89 e5 mov %esp,%ebp
3c3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
3c6: 80 39 00 cmpb $0x0,(%ecx)
3c9: 74 12 je 3dd <strlen+0x1d>
3cb: 31 d2 xor %edx,%edx
3cd: 8d 76 00 lea 0x0(%esi),%esi
3d0: 83 c2 01 add $0x1,%edx
3d3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
3d7: 89 d0 mov %edx,%eax
3d9: 75 f5 jne 3d0 <strlen+0x10>
;
return n;
}
3db: 5d pop %ebp
3dc: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
3dd: 31 c0 xor %eax,%eax
;
return n;
}
3df: 5d pop %ebp
3e0: c3 ret
3e1: eb 0d jmp 3f0 <memset>
3e3: 90 nop
3e4: 90 nop
3e5: 90 nop
3e6: 90 nop
3e7: 90 nop
3e8: 90 nop
3e9: 90 nop
3ea: 90 nop
3eb: 90 nop
3ec: 90 nop
3ed: 90 nop
3ee: 90 nop
3ef: 90 nop
000003f0 <memset>:
void*
memset(void *dst, int c, uint n)
{
3f0: 55 push %ebp
3f1: 89 e5 mov %esp,%ebp
3f3: 57 push %edi
3f4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
3f7: 8b 4d 10 mov 0x10(%ebp),%ecx
3fa: 8b 45 0c mov 0xc(%ebp),%eax
3fd: 89 d7 mov %edx,%edi
3ff: fc cld
400: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
402: 89 d0 mov %edx,%eax
404: 5f pop %edi
405: 5d pop %ebp
406: c3 ret
407: 89 f6 mov %esi,%esi
409: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000410 <strchr>:
char*
strchr(const char *s, char c)
{
410: 55 push %ebp
411: 89 e5 mov %esp,%ebp
413: 53 push %ebx
414: 8b 45 08 mov 0x8(%ebp),%eax
417: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
41a: 0f b6 10 movzbl (%eax),%edx
41d: 84 d2 test %dl,%dl
41f: 74 1d je 43e <strchr+0x2e>
if(*s == c)
421: 38 d3 cmp %dl,%bl
423: 89 d9 mov %ebx,%ecx
425: 75 0d jne 434 <strchr+0x24>
427: eb 17 jmp 440 <strchr+0x30>
429: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
430: 38 ca cmp %cl,%dl
432: 74 0c je 440 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
434: 83 c0 01 add $0x1,%eax
437: 0f b6 10 movzbl (%eax),%edx
43a: 84 d2 test %dl,%dl
43c: 75 f2 jne 430 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
43e: 31 c0 xor %eax,%eax
}
440: 5b pop %ebx
441: 5d pop %ebp
442: c3 ret
443: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000450 <gets>:
char*
gets(char *buf, int max)
{
450: 55 push %ebp
451: 89 e5 mov %esp,%ebp
453: 57 push %edi
454: 56 push %esi
455: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
456: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
458: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
45b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
45e: eb 29 jmp 489 <gets+0x39>
cc = read(0, &c, 1);
460: 83 ec 04 sub $0x4,%esp
463: 6a 01 push $0x1
465: 57 push %edi
466: 6a 00 push $0x0
468: e8 2d 01 00 00 call 59a <read>
if(cc < 1)
46d: 83 c4 10 add $0x10,%esp
470: 85 c0 test %eax,%eax
472: 7e 1d jle 491 <gets+0x41>
break;
buf[i++] = c;
474: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
478: 8b 55 08 mov 0x8(%ebp),%edx
47b: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
47d: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
47f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
483: 74 1b je 4a0 <gets+0x50>
485: 3c 0d cmp $0xd,%al
487: 74 17 je 4a0 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
489: 8d 5e 01 lea 0x1(%esi),%ebx
48c: 3b 5d 0c cmp 0xc(%ebp),%ebx
48f: 7c cf jl 460 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
491: 8b 45 08 mov 0x8(%ebp),%eax
494: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
498: 8d 65 f4 lea -0xc(%ebp),%esp
49b: 5b pop %ebx
49c: 5e pop %esi
49d: 5f pop %edi
49e: 5d pop %ebp
49f: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
4a0: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
4a3: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
4a5: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
4a9: 8d 65 f4 lea -0xc(%ebp),%esp
4ac: 5b pop %ebx
4ad: 5e pop %esi
4ae: 5f pop %edi
4af: 5d pop %ebp
4b0: c3 ret
4b1: eb 0d jmp 4c0 <stat>
4b3: 90 nop
4b4: 90 nop
4b5: 90 nop
4b6: 90 nop
4b7: 90 nop
4b8: 90 nop
4b9: 90 nop
4ba: 90 nop
4bb: 90 nop
4bc: 90 nop
4bd: 90 nop
4be: 90 nop
4bf: 90 nop
000004c0 <stat>:
int
stat(char *n, struct stat *st)
{
4c0: 55 push %ebp
4c1: 89 e5 mov %esp,%ebp
4c3: 56 push %esi
4c4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
4c5: 83 ec 08 sub $0x8,%esp
4c8: 6a 00 push $0x0
4ca: ff 75 08 pushl 0x8(%ebp)
4cd: e8 f0 00 00 00 call 5c2 <open>
if(fd < 0)
4d2: 83 c4 10 add $0x10,%esp
4d5: 85 c0 test %eax,%eax
4d7: 78 27 js 500 <stat+0x40>
return -1;
r = fstat(fd, st);
4d9: 83 ec 08 sub $0x8,%esp
4dc: ff 75 0c pushl 0xc(%ebp)
4df: 89 c3 mov %eax,%ebx
4e1: 50 push %eax
4e2: e8 f3 00 00 00 call 5da <fstat>
4e7: 89 c6 mov %eax,%esi
close(fd);
4e9: 89 1c 24 mov %ebx,(%esp)
4ec: e8 b9 00 00 00 call 5aa <close>
return r;
4f1: 83 c4 10 add $0x10,%esp
4f4: 89 f0 mov %esi,%eax
}
4f6: 8d 65 f8 lea -0x8(%ebp),%esp
4f9: 5b pop %ebx
4fa: 5e pop %esi
4fb: 5d pop %ebp
4fc: c3 ret
4fd: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
500: b8 ff ff ff ff mov $0xffffffff,%eax
505: eb ef jmp 4f6 <stat+0x36>
507: 89 f6 mov %esi,%esi
509: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000510 <atoi>:
return r;
}
int
atoi(const char *s)
{
510: 55 push %ebp
511: 89 e5 mov %esp,%ebp
513: 53 push %ebx
514: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
517: 0f be 11 movsbl (%ecx),%edx
51a: 8d 42 d0 lea -0x30(%edx),%eax
51d: 3c 09 cmp $0x9,%al
51f: b8 00 00 00 00 mov $0x0,%eax
524: 77 1f ja 545 <atoi+0x35>
526: 8d 76 00 lea 0x0(%esi),%esi
529: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
530: 8d 04 80 lea (%eax,%eax,4),%eax
533: 83 c1 01 add $0x1,%ecx
536: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
53a: 0f be 11 movsbl (%ecx),%edx
53d: 8d 5a d0 lea -0x30(%edx),%ebx
540: 80 fb 09 cmp $0x9,%bl
543: 76 eb jbe 530 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
545: 5b pop %ebx
546: 5d pop %ebp
547: c3 ret
548: 90 nop
549: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000550 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
550: 55 push %ebp
551: 89 e5 mov %esp,%ebp
553: 56 push %esi
554: 53 push %ebx
555: 8b 5d 10 mov 0x10(%ebp),%ebx
558: 8b 45 08 mov 0x8(%ebp),%eax
55b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
55e: 85 db test %ebx,%ebx
560: 7e 14 jle 576 <memmove+0x26>
562: 31 d2 xor %edx,%edx
564: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
568: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
56c: 88 0c 10 mov %cl,(%eax,%edx,1)
56f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
572: 39 da cmp %ebx,%edx
574: 75 f2 jne 568 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
576: 5b pop %ebx
577: 5e pop %esi
578: 5d pop %ebp
579: c3 ret
0000057a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
57a: b8 01 00 00 00 mov $0x1,%eax
57f: cd 40 int $0x40
581: c3 ret
00000582 <exit>:
SYSCALL(exit)
582: b8 02 00 00 00 mov $0x2,%eax
587: cd 40 int $0x40
589: c3 ret
0000058a <wait>:
SYSCALL(wait)
58a: b8 03 00 00 00 mov $0x3,%eax
58f: cd 40 int $0x40
591: c3 ret
00000592 <pipe>:
SYSCALL(pipe)
592: b8 04 00 00 00 mov $0x4,%eax
597: cd 40 int $0x40
599: c3 ret
0000059a <read>:
SYSCALL(read)
59a: b8 05 00 00 00 mov $0x5,%eax
59f: cd 40 int $0x40
5a1: c3 ret
000005a2 <write>:
SYSCALL(write)
5a2: b8 10 00 00 00 mov $0x10,%eax
5a7: cd 40 int $0x40
5a9: c3 ret
000005aa <close>:
SYSCALL(close)
5aa: b8 15 00 00 00 mov $0x15,%eax
5af: cd 40 int $0x40
5b1: c3 ret
000005b2 <kill>:
SYSCALL(kill)
5b2: b8 06 00 00 00 mov $0x6,%eax
5b7: cd 40 int $0x40
5b9: c3 ret
000005ba <exec>:
SYSCALL(exec)
5ba: b8 07 00 00 00 mov $0x7,%eax
5bf: cd 40 int $0x40
5c1: c3 ret
000005c2 <open>:
SYSCALL(open)
5c2: b8 0f 00 00 00 mov $0xf,%eax
5c7: cd 40 int $0x40
5c9: c3 ret
000005ca <mknod>:
SYSCALL(mknod)
5ca: b8 11 00 00 00 mov $0x11,%eax
5cf: cd 40 int $0x40