-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls.asm
1505 lines (1413 loc) · 51.7 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 <fmtname>:
#include "user.h"
#include "fs.h"
char*
fmtname(char *path)
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 53 push %ebx
4: 83 ec 14 sub $0x14,%esp
static char buf[DIRSIZ+1];
char *p;
// Find first character after last slash.
for(p=path+strlen(path); p >= path && *p != '/'; p--)
7: 83 ec 0c sub $0xc,%esp
a: ff 75 08 pushl 0x8(%ebp)
d: e8 c9 03 00 00 call 3db <strlen>
12: 83 c4 10 add $0x10,%esp
15: 89 c2 mov %eax,%edx
17: 8b 45 08 mov 0x8(%ebp),%eax
1a: 01 d0 add %edx,%eax
1c: 89 45 f4 mov %eax,-0xc(%ebp)
1f: eb 04 jmp 25 <fmtname+0x25>
21: 83 6d f4 01 subl $0x1,-0xc(%ebp)
25: 8b 45 f4 mov -0xc(%ebp),%eax
28: 3b 45 08 cmp 0x8(%ebp),%eax
2b: 72 0a jb 37 <fmtname+0x37>
2d: 8b 45 f4 mov -0xc(%ebp),%eax
30: 0f b6 00 movzbl (%eax),%eax
33: 3c 2f cmp $0x2f,%al
35: 75 ea jne 21 <fmtname+0x21>
;
p++;
37: 83 45 f4 01 addl $0x1,-0xc(%ebp)
// Return blank-padded name.
if(strlen(p) >= DIRSIZ)
3b: 83 ec 0c sub $0xc,%esp
3e: ff 75 f4 pushl -0xc(%ebp)
41: e8 95 03 00 00 call 3db <strlen>
46: 83 c4 10 add $0x10,%esp
49: 83 f8 0d cmp $0xd,%eax
4c: 76 05 jbe 53 <fmtname+0x53>
return p;
4e: 8b 45 f4 mov -0xc(%ebp),%eax
51: eb 60 jmp b3 <fmtname+0xb3>
memmove(buf, p, strlen(p));
53: 83 ec 0c sub $0xc,%esp
56: ff 75 f4 pushl -0xc(%ebp)
59: e8 7d 03 00 00 call 3db <strlen>
5e: 83 c4 10 add $0x10,%esp
61: 83 ec 04 sub $0x4,%esp
64: 50 push %eax
65: ff 75 f4 pushl -0xc(%ebp)
68: 68 d0 0d 00 00 push $0xdd0
6d: e8 e6 04 00 00 call 558 <memmove>
72: 83 c4 10 add $0x10,%esp
memset(buf+strlen(p), ' ', DIRSIZ-strlen(p));
75: 83 ec 0c sub $0xc,%esp
78: ff 75 f4 pushl -0xc(%ebp)
7b: e8 5b 03 00 00 call 3db <strlen>
80: 83 c4 10 add $0x10,%esp
83: ba 0e 00 00 00 mov $0xe,%edx
88: 89 d3 mov %edx,%ebx
8a: 29 c3 sub %eax,%ebx
8c: 83 ec 0c sub $0xc,%esp
8f: ff 75 f4 pushl -0xc(%ebp)
92: e8 44 03 00 00 call 3db <strlen>
97: 83 c4 10 add $0x10,%esp
9a: 05 d0 0d 00 00 add $0xdd0,%eax
9f: 83 ec 04 sub $0x4,%esp
a2: 53 push %ebx
a3: 6a 20 push $0x20
a5: 50 push %eax
a6: e8 57 03 00 00 call 402 <memset>
ab: 83 c4 10 add $0x10,%esp
return buf;
ae: b8 d0 0d 00 00 mov $0xdd0,%eax
}
b3: 8b 5d fc mov -0x4(%ebp),%ebx
b6: c9 leave
b7: c3 ret
000000b8 <ls>:
void
ls(char *path)
{
b8: 55 push %ebp
b9: 89 e5 mov %esp,%ebp
bb: 57 push %edi
bc: 56 push %esi
bd: 53 push %ebx
be: 81 ec 3c 02 00 00 sub $0x23c,%esp
char buf[512], *p;
int fd;
struct dirent de;
struct stat st;
if((fd = open(path, 0)) < 0){
c4: 83 ec 08 sub $0x8,%esp
c7: 6a 00 push $0x0
c9: ff 75 08 pushl 0x8(%ebp)
cc: e8 0c 05 00 00 call 5dd <open>
d1: 83 c4 10 add $0x10,%esp
d4: 89 45 e4 mov %eax,-0x1c(%ebp)
d7: 83 7d e4 00 cmpl $0x0,-0x1c(%ebp)
db: 79 1a jns f7 <ls+0x3f>
printf(2, "ls: cannot open %s\n", path);
dd: 83 ec 04 sub $0x4,%esp
e0: ff 75 08 pushl 0x8(%ebp)
e3: 68 ca 0a 00 00 push $0xaca
e8: 6a 02 push $0x2
ea: e8 25 06 00 00 call 714 <printf>
ef: 83 c4 10 add $0x10,%esp
return;
f2: e9 e3 01 00 00 jmp 2da <ls+0x222>
}
if(fstat(fd, &st) < 0){
f7: 83 ec 08 sub $0x8,%esp
fa: 8d 85 bc fd ff ff lea -0x244(%ebp),%eax
100: 50 push %eax
101: ff 75 e4 pushl -0x1c(%ebp)
104: e8 ec 04 00 00 call 5f5 <fstat>
109: 83 c4 10 add $0x10,%esp
10c: 85 c0 test %eax,%eax
10e: 79 28 jns 138 <ls+0x80>
printf(2, "ls: cannot stat %s\n", path);
110: 83 ec 04 sub $0x4,%esp
113: ff 75 08 pushl 0x8(%ebp)
116: 68 de 0a 00 00 push $0xade
11b: 6a 02 push $0x2
11d: e8 f2 05 00 00 call 714 <printf>
122: 83 c4 10 add $0x10,%esp
close(fd);
125: 83 ec 0c sub $0xc,%esp
128: ff 75 e4 pushl -0x1c(%ebp)
12b: e8 95 04 00 00 call 5c5 <close>
130: 83 c4 10 add $0x10,%esp
return;
133: e9 a2 01 00 00 jmp 2da <ls+0x222>
}
switch(st.type){
138: 0f b7 85 bc fd ff ff movzwl -0x244(%ebp),%eax
13f: 98 cwtl
140: 83 f8 01 cmp $0x1,%eax
143: 74 48 je 18d <ls+0xd5>
145: 83 f8 02 cmp $0x2,%eax
148: 0f 85 7e 01 00 00 jne 2cc <ls+0x214>
case T_FILE:
printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size);
14e: 8b bd cc fd ff ff mov -0x234(%ebp),%edi
154: 8b b5 c4 fd ff ff mov -0x23c(%ebp),%esi
15a: 0f b7 85 bc fd ff ff movzwl -0x244(%ebp),%eax
161: 0f bf d8 movswl %ax,%ebx
164: 83 ec 0c sub $0xc,%esp
167: ff 75 08 pushl 0x8(%ebp)
16a: e8 91 fe ff ff call 0 <fmtname>
16f: 83 c4 10 add $0x10,%esp
172: 83 ec 08 sub $0x8,%esp
175: 57 push %edi
176: 56 push %esi
177: 53 push %ebx
178: 50 push %eax
179: 68 f2 0a 00 00 push $0xaf2
17e: 6a 01 push $0x1
180: e8 8f 05 00 00 call 714 <printf>
185: 83 c4 20 add $0x20,%esp
break;
188: e9 3f 01 00 00 jmp 2cc <ls+0x214>
case T_DIR:
if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){
18d: 83 ec 0c sub $0xc,%esp
190: ff 75 08 pushl 0x8(%ebp)
193: e8 43 02 00 00 call 3db <strlen>
198: 83 c4 10 add $0x10,%esp
19b: 83 c0 10 add $0x10,%eax
19e: 3d 00 02 00 00 cmp $0x200,%eax
1a3: 76 17 jbe 1bc <ls+0x104>
printf(1, "ls: path too long\n");
1a5: 83 ec 08 sub $0x8,%esp
1a8: 68 ff 0a 00 00 push $0xaff
1ad: 6a 01 push $0x1
1af: e8 60 05 00 00 call 714 <printf>
1b4: 83 c4 10 add $0x10,%esp
break;
1b7: e9 10 01 00 00 jmp 2cc <ls+0x214>
}
strcpy(buf, path);
1bc: 83 ec 08 sub $0x8,%esp
1bf: ff 75 08 pushl 0x8(%ebp)
1c2: 8d 85 e0 fd ff ff lea -0x220(%ebp),%eax
1c8: 50 push %eax
1c9: e8 9e 01 00 00 call 36c <strcpy>
1ce: 83 c4 10 add $0x10,%esp
p = buf+strlen(buf);
1d1: 83 ec 0c sub $0xc,%esp
1d4: 8d 85 e0 fd ff ff lea -0x220(%ebp),%eax
1da: 50 push %eax
1db: e8 fb 01 00 00 call 3db <strlen>
1e0: 83 c4 10 add $0x10,%esp
1e3: 89 c2 mov %eax,%edx
1e5: 8d 85 e0 fd ff ff lea -0x220(%ebp),%eax
1eb: 01 d0 add %edx,%eax
1ed: 89 45 e0 mov %eax,-0x20(%ebp)
*p++ = '/';
1f0: 8b 45 e0 mov -0x20(%ebp),%eax
1f3: 8d 50 01 lea 0x1(%eax),%edx
1f6: 89 55 e0 mov %edx,-0x20(%ebp)
1f9: c6 00 2f movb $0x2f,(%eax)
while(read(fd, &de, sizeof(de)) == sizeof(de)){
1fc: e9 aa 00 00 00 jmp 2ab <ls+0x1f3>
if(de.inum == 0)
201: 0f b7 85 d0 fd ff ff movzwl -0x230(%ebp),%eax
208: 66 85 c0 test %ax,%ax
20b: 75 05 jne 212 <ls+0x15a>
continue;
20d: e9 99 00 00 00 jmp 2ab <ls+0x1f3>
memmove(p, de.name, DIRSIZ);
212: 83 ec 04 sub $0x4,%esp
215: 6a 0e push $0xe
217: 8d 85 d0 fd ff ff lea -0x230(%ebp),%eax
21d: 83 c0 02 add $0x2,%eax
220: 50 push %eax
221: ff 75 e0 pushl -0x20(%ebp)
224: e8 2f 03 00 00 call 558 <memmove>
229: 83 c4 10 add $0x10,%esp
p[DIRSIZ] = 0;
22c: 8b 45 e0 mov -0x20(%ebp),%eax
22f: 83 c0 0e add $0xe,%eax
232: c6 00 00 movb $0x0,(%eax)
if(stat(buf, &st) < 0){
235: 83 ec 08 sub $0x8,%esp
238: 8d 85 bc fd ff ff lea -0x244(%ebp),%eax
23e: 50 push %eax
23f: 8d 85 e0 fd ff ff lea -0x220(%ebp),%eax
245: 50 push %eax
246: e8 73 02 00 00 call 4be <stat>
24b: 83 c4 10 add $0x10,%esp
24e: 85 c0 test %eax,%eax
250: 79 1b jns 26d <ls+0x1b5>
printf(1, "ls: cannot stat %s\n", buf);
252: 83 ec 04 sub $0x4,%esp
255: 8d 85 e0 fd ff ff lea -0x220(%ebp),%eax
25b: 50 push %eax
25c: 68 de 0a 00 00 push $0xade
261: 6a 01 push $0x1
263: e8 ac 04 00 00 call 714 <printf>
268: 83 c4 10 add $0x10,%esp
continue;
26b: eb 3e jmp 2ab <ls+0x1f3>
}
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
26d: 8b bd cc fd ff ff mov -0x234(%ebp),%edi
273: 8b b5 c4 fd ff ff mov -0x23c(%ebp),%esi
279: 0f b7 85 bc fd ff ff movzwl -0x244(%ebp),%eax
280: 0f bf d8 movswl %ax,%ebx
283: 83 ec 0c sub $0xc,%esp
286: 8d 85 e0 fd ff ff lea -0x220(%ebp),%eax
28c: 50 push %eax
28d: e8 6e fd ff ff call 0 <fmtname>
292: 83 c4 10 add $0x10,%esp
295: 83 ec 08 sub $0x8,%esp
298: 57 push %edi
299: 56 push %esi
29a: 53 push %ebx
29b: 50 push %eax
29c: 68 f2 0a 00 00 push $0xaf2
2a1: 6a 01 push $0x1
2a3: e8 6c 04 00 00 call 714 <printf>
2a8: 83 c4 20 add $0x20,%esp
break;
}
strcpy(buf, path);
p = buf+strlen(buf);
*p++ = '/';
while(read(fd, &de, sizeof(de)) == sizeof(de)){
2ab: 83 ec 04 sub $0x4,%esp
2ae: 6a 10 push $0x10
2b0: 8d 85 d0 fd ff ff lea -0x230(%ebp),%eax
2b6: 50 push %eax
2b7: ff 75 e4 pushl -0x1c(%ebp)
2ba: e8 f6 02 00 00 call 5b5 <read>
2bf: 83 c4 10 add $0x10,%esp
2c2: 83 f8 10 cmp $0x10,%eax
2c5: 0f 84 36 ff ff ff je 201 <ls+0x149>
printf(1, "ls: cannot stat %s\n", buf);
continue;
}
printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size);
}
break;
2cb: 90 nop
}
close(fd);
2cc: 83 ec 0c sub $0xc,%esp
2cf: ff 75 e4 pushl -0x1c(%ebp)
2d2: e8 ee 02 00 00 call 5c5 <close>
2d7: 83 c4 10 add $0x10,%esp
}
2da: 8d 65 f4 lea -0xc(%ebp),%esp
2dd: 5b pop %ebx
2de: 5e pop %esi
2df: 5f pop %edi
2e0: 5d pop %ebp
2e1: c3 ret
000002e2 <main>:
int
main(int argc, char *argv[])
{
2e2: 8d 4c 24 04 lea 0x4(%esp),%ecx
2e6: 83 e4 f0 and $0xfffffff0,%esp
2e9: ff 71 fc pushl -0x4(%ecx)
2ec: 55 push %ebp
2ed: 89 e5 mov %esp,%ebp
2ef: 53 push %ebx
2f0: 51 push %ecx
2f1: 83 ec 10 sub $0x10,%esp
2f4: 89 cb mov %ecx,%ebx
int i;
if(argc < 2){
2f6: 83 3b 01 cmpl $0x1,(%ebx)
2f9: 7f 15 jg 310 <main+0x2e>
ls(".");
2fb: 83 ec 0c sub $0xc,%esp
2fe: 68 12 0b 00 00 push $0xb12
303: e8 b0 fd ff ff call b8 <ls>
308: 83 c4 10 add $0x10,%esp
exit();
30b: e8 8d 02 00 00 call 59d <exit>
}
for(i=1; i<argc; i++)
310: c7 45 f4 01 00 00 00 movl $0x1,-0xc(%ebp)
317: eb 21 jmp 33a <main+0x58>
ls(argv[i]);
319: 8b 45 f4 mov -0xc(%ebp),%eax
31c: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx
323: 8b 43 04 mov 0x4(%ebx),%eax
326: 01 d0 add %edx,%eax
328: 8b 00 mov (%eax),%eax
32a: 83 ec 0c sub $0xc,%esp
32d: 50 push %eax
32e: e8 85 fd ff ff call b8 <ls>
333: 83 c4 10 add $0x10,%esp
if(argc < 2){
ls(".");
exit();
}
for(i=1; i<argc; i++)
336: 83 45 f4 01 addl $0x1,-0xc(%ebp)
33a: 8b 45 f4 mov -0xc(%ebp),%eax
33d: 3b 03 cmp (%ebx),%eax
33f: 7c d8 jl 319 <main+0x37>
ls(argv[i]);
exit();
341: e8 57 02 00 00 call 59d <exit>
00000346 <stosb>:
"cc");
}
static inline void
stosb(void *addr, int data, int cnt)
{
346: 55 push %ebp
347: 89 e5 mov %esp,%ebp
349: 57 push %edi
34a: 53 push %ebx
asm volatile("cld; rep stosb" :
34b: 8b 4d 08 mov 0x8(%ebp),%ecx
34e: 8b 55 10 mov 0x10(%ebp),%edx
351: 8b 45 0c mov 0xc(%ebp),%eax
354: 89 cb mov %ecx,%ebx
356: 89 df mov %ebx,%edi
358: 89 d1 mov %edx,%ecx
35a: fc cld
35b: f3 aa rep stos %al,%es:(%edi)
35d: 89 ca mov %ecx,%edx
35f: 89 fb mov %edi,%ebx
361: 89 5d 08 mov %ebx,0x8(%ebp)
364: 89 55 10 mov %edx,0x10(%ebp)
"=D" (addr), "=c" (cnt) :
"0" (addr), "1" (cnt), "a" (data) :
"memory", "cc");
}
367: 90 nop
368: 5b pop %ebx
369: 5f pop %edi
36a: 5d pop %ebp
36b: c3 ret
0000036c <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
36c: 55 push %ebp
36d: 89 e5 mov %esp,%ebp
36f: 83 ec 10 sub $0x10,%esp
char *os;
os = s;
372: 8b 45 08 mov 0x8(%ebp),%eax
375: 89 45 fc mov %eax,-0x4(%ebp)
while((*s++ = *t++) != 0)
378: 90 nop
379: 8b 45 08 mov 0x8(%ebp),%eax
37c: 8d 50 01 lea 0x1(%eax),%edx
37f: 89 55 08 mov %edx,0x8(%ebp)
382: 8b 55 0c mov 0xc(%ebp),%edx
385: 8d 4a 01 lea 0x1(%edx),%ecx
388: 89 4d 0c mov %ecx,0xc(%ebp)
38b: 0f b6 12 movzbl (%edx),%edx
38e: 88 10 mov %dl,(%eax)
390: 0f b6 00 movzbl (%eax),%eax
393: 84 c0 test %al,%al
395: 75 e2 jne 379 <strcpy+0xd>
;
return os;
397: 8b 45 fc mov -0x4(%ebp),%eax
}
39a: c9 leave
39b: c3 ret
0000039c <strcmp>:
int
strcmp(const char *p, const char *q)
{
39c: 55 push %ebp
39d: 89 e5 mov %esp,%ebp
while(*p && *p == *q)
39f: eb 08 jmp 3a9 <strcmp+0xd>
p++, q++;
3a1: 83 45 08 01 addl $0x1,0x8(%ebp)
3a5: 83 45 0c 01 addl $0x1,0xc(%ebp)
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
3a9: 8b 45 08 mov 0x8(%ebp),%eax
3ac: 0f b6 00 movzbl (%eax),%eax
3af: 84 c0 test %al,%al
3b1: 74 10 je 3c3 <strcmp+0x27>
3b3: 8b 45 08 mov 0x8(%ebp),%eax
3b6: 0f b6 10 movzbl (%eax),%edx
3b9: 8b 45 0c mov 0xc(%ebp),%eax
3bc: 0f b6 00 movzbl (%eax),%eax
3bf: 38 c2 cmp %al,%dl
3c1: 74 de je 3a1 <strcmp+0x5>
p++, q++;
return (uchar)*p - (uchar)*q;
3c3: 8b 45 08 mov 0x8(%ebp),%eax
3c6: 0f b6 00 movzbl (%eax),%eax
3c9: 0f b6 d0 movzbl %al,%edx
3cc: 8b 45 0c mov 0xc(%ebp),%eax
3cf: 0f b6 00 movzbl (%eax),%eax
3d2: 0f b6 c0 movzbl %al,%eax
3d5: 29 c2 sub %eax,%edx
3d7: 89 d0 mov %edx,%eax
}
3d9: 5d pop %ebp
3da: c3 ret
000003db <strlen>:
uint
strlen(char *s)
{
3db: 55 push %ebp
3dc: 89 e5 mov %esp,%ebp
3de: 83 ec 10 sub $0x10,%esp
int n;
for(n = 0; s[n]; n++)
3e1: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
3e8: eb 04 jmp 3ee <strlen+0x13>
3ea: 83 45 fc 01 addl $0x1,-0x4(%ebp)
3ee: 8b 55 fc mov -0x4(%ebp),%edx
3f1: 8b 45 08 mov 0x8(%ebp),%eax
3f4: 01 d0 add %edx,%eax
3f6: 0f b6 00 movzbl (%eax),%eax
3f9: 84 c0 test %al,%al
3fb: 75 ed jne 3ea <strlen+0xf>
;
return n;
3fd: 8b 45 fc mov -0x4(%ebp),%eax
}
400: c9 leave
401: c3 ret
00000402 <memset>:
void*
memset(void *dst, int c, uint n)
{
402: 55 push %ebp
403: 89 e5 mov %esp,%ebp
stosb(dst, c, n);
405: 8b 45 10 mov 0x10(%ebp),%eax
408: 50 push %eax
409: ff 75 0c pushl 0xc(%ebp)
40c: ff 75 08 pushl 0x8(%ebp)
40f: e8 32 ff ff ff call 346 <stosb>
414: 83 c4 0c add $0xc,%esp
return dst;
417: 8b 45 08 mov 0x8(%ebp),%eax
}
41a: c9 leave
41b: c3 ret
0000041c <strchr>:
char*
strchr(const char *s, char c)
{
41c: 55 push %ebp
41d: 89 e5 mov %esp,%ebp
41f: 83 ec 04 sub $0x4,%esp
422: 8b 45 0c mov 0xc(%ebp),%eax
425: 88 45 fc mov %al,-0x4(%ebp)
for(; *s; s++)
428: eb 14 jmp 43e <strchr+0x22>
if(*s == c)
42a: 8b 45 08 mov 0x8(%ebp),%eax
42d: 0f b6 00 movzbl (%eax),%eax
430: 3a 45 fc cmp -0x4(%ebp),%al
433: 75 05 jne 43a <strchr+0x1e>
return (char*)s;
435: 8b 45 08 mov 0x8(%ebp),%eax
438: eb 13 jmp 44d <strchr+0x31>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
43a: 83 45 08 01 addl $0x1,0x8(%ebp)
43e: 8b 45 08 mov 0x8(%ebp),%eax
441: 0f b6 00 movzbl (%eax),%eax
444: 84 c0 test %al,%al
446: 75 e2 jne 42a <strchr+0xe>
if(*s == c)
return (char*)s;
return 0;
448: b8 00 00 00 00 mov $0x0,%eax
}
44d: c9 leave
44e: c3 ret
0000044f <gets>:
char*
gets(char *buf, int max)
{
44f: 55 push %ebp
450: 89 e5 mov %esp,%ebp
452: 83 ec 18 sub $0x18,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
455: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
45c: eb 42 jmp 4a0 <gets+0x51>
cc = read(0, &c, 1);
45e: 83 ec 04 sub $0x4,%esp
461: 6a 01 push $0x1
463: 8d 45 ef lea -0x11(%ebp),%eax
466: 50 push %eax
467: 6a 00 push $0x0
469: e8 47 01 00 00 call 5b5 <read>
46e: 83 c4 10 add $0x10,%esp
471: 89 45 f0 mov %eax,-0x10(%ebp)
if(cc < 1)
474: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
478: 7e 33 jle 4ad <gets+0x5e>
break;
buf[i++] = c;
47a: 8b 45 f4 mov -0xc(%ebp),%eax
47d: 8d 50 01 lea 0x1(%eax),%edx
480: 89 55 f4 mov %edx,-0xc(%ebp)
483: 89 c2 mov %eax,%edx
485: 8b 45 08 mov 0x8(%ebp),%eax
488: 01 c2 add %eax,%edx
48a: 0f b6 45 ef movzbl -0x11(%ebp),%eax
48e: 88 02 mov %al,(%edx)
if(c == '\n' || c == '\r')
490: 0f b6 45 ef movzbl -0x11(%ebp),%eax
494: 3c 0a cmp $0xa,%al
496: 74 16 je 4ae <gets+0x5f>
498: 0f b6 45 ef movzbl -0x11(%ebp),%eax
49c: 3c 0d cmp $0xd,%al
49e: 74 0e je 4ae <gets+0x5f>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
4a0: 8b 45 f4 mov -0xc(%ebp),%eax
4a3: 83 c0 01 add $0x1,%eax
4a6: 3b 45 0c cmp 0xc(%ebp),%eax
4a9: 7c b3 jl 45e <gets+0xf>
4ab: eb 01 jmp 4ae <gets+0x5f>
cc = read(0, &c, 1);
if(cc < 1)
break;
4ad: 90 nop
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
4ae: 8b 55 f4 mov -0xc(%ebp),%edx
4b1: 8b 45 08 mov 0x8(%ebp),%eax
4b4: 01 d0 add %edx,%eax
4b6: c6 00 00 movb $0x0,(%eax)
return buf;
4b9: 8b 45 08 mov 0x8(%ebp),%eax
}
4bc: c9 leave
4bd: c3 ret
000004be <stat>:
int
stat(char *n, struct stat *st)
{
4be: 55 push %ebp
4bf: 89 e5 mov %esp,%ebp
4c1: 83 ec 18 sub $0x18,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
4c4: 83 ec 08 sub $0x8,%esp
4c7: 6a 00 push $0x0
4c9: ff 75 08 pushl 0x8(%ebp)
4cc: e8 0c 01 00 00 call 5dd <open>
4d1: 83 c4 10 add $0x10,%esp
4d4: 89 45 f4 mov %eax,-0xc(%ebp)
if(fd < 0)
4d7: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
4db: 79 07 jns 4e4 <stat+0x26>
return -1;
4dd: b8 ff ff ff ff mov $0xffffffff,%eax
4e2: eb 25 jmp 509 <stat+0x4b>
r = fstat(fd, st);
4e4: 83 ec 08 sub $0x8,%esp
4e7: ff 75 0c pushl 0xc(%ebp)
4ea: ff 75 f4 pushl -0xc(%ebp)
4ed: e8 03 01 00 00 call 5f5 <fstat>
4f2: 83 c4 10 add $0x10,%esp
4f5: 89 45 f0 mov %eax,-0x10(%ebp)
close(fd);
4f8: 83 ec 0c sub $0xc,%esp
4fb: ff 75 f4 pushl -0xc(%ebp)
4fe: e8 c2 00 00 00 call 5c5 <close>
503: 83 c4 10 add $0x10,%esp
return r;
506: 8b 45 f0 mov -0x10(%ebp),%eax
}
509: c9 leave
50a: c3 ret
0000050b <atoi>:
int
atoi(const char *s)
{
50b: 55 push %ebp
50c: 89 e5 mov %esp,%ebp
50e: 83 ec 10 sub $0x10,%esp
int n;
n = 0;
511: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
while('0' <= *s && *s <= '9')
518: eb 25 jmp 53f <atoi+0x34>
n = n*10 + *s++ - '0';
51a: 8b 55 fc mov -0x4(%ebp),%edx
51d: 89 d0 mov %edx,%eax
51f: c1 e0 02 shl $0x2,%eax
522: 01 d0 add %edx,%eax
524: 01 c0 add %eax,%eax
526: 89 c1 mov %eax,%ecx
528: 8b 45 08 mov 0x8(%ebp),%eax
52b: 8d 50 01 lea 0x1(%eax),%edx
52e: 89 55 08 mov %edx,0x8(%ebp)
531: 0f b6 00 movzbl (%eax),%eax
534: 0f be c0 movsbl %al,%eax
537: 01 c8 add %ecx,%eax
539: 83 e8 30 sub $0x30,%eax
53c: 89 45 fc mov %eax,-0x4(%ebp)
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
53f: 8b 45 08 mov 0x8(%ebp),%eax
542: 0f b6 00 movzbl (%eax),%eax
545: 3c 2f cmp $0x2f,%al
547: 7e 0a jle 553 <atoi+0x48>
549: 8b 45 08 mov 0x8(%ebp),%eax
54c: 0f b6 00 movzbl (%eax),%eax
54f: 3c 39 cmp $0x39,%al
551: 7e c7 jle 51a <atoi+0xf>
n = n*10 + *s++ - '0';
return n;
553: 8b 45 fc mov -0x4(%ebp),%eax
}
556: c9 leave
557: c3 ret
00000558 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
558: 55 push %ebp
559: 89 e5 mov %esp,%ebp
55b: 83 ec 10 sub $0x10,%esp
char *dst, *src;
dst = vdst;
55e: 8b 45 08 mov 0x8(%ebp),%eax
561: 89 45 fc mov %eax,-0x4(%ebp)
src = vsrc;
564: 8b 45 0c mov 0xc(%ebp),%eax
567: 89 45 f8 mov %eax,-0x8(%ebp)
while(n-- > 0)
56a: eb 17 jmp 583 <memmove+0x2b>
*dst++ = *src++;
56c: 8b 45 fc mov -0x4(%ebp),%eax
56f: 8d 50 01 lea 0x1(%eax),%edx
572: 89 55 fc mov %edx,-0x4(%ebp)
575: 8b 55 f8 mov -0x8(%ebp),%edx
578: 8d 4a 01 lea 0x1(%edx),%ecx
57b: 89 4d f8 mov %ecx,-0x8(%ebp)
57e: 0f b6 12 movzbl (%edx),%edx
581: 88 10 mov %dl,(%eax)
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
583: 8b 45 10 mov 0x10(%ebp),%eax
586: 8d 50 ff lea -0x1(%eax),%edx
589: 89 55 10 mov %edx,0x10(%ebp)
58c: 85 c0 test %eax,%eax
58e: 7f dc jg 56c <memmove+0x14>
*dst++ = *src++;
return vdst;
590: 8b 45 08 mov 0x8(%ebp),%eax
}
593: c9 leave
594: c3 ret
00000595 <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
595: b8 01 00 00 00 mov $0x1,%eax
59a: cd 40 int $0x40
59c: c3 ret
0000059d <exit>:
SYSCALL(exit)
59d: b8 02 00 00 00 mov $0x2,%eax
5a2: cd 40 int $0x40
5a4: c3 ret
000005a5 <wait>:
SYSCALL(wait)
5a5: b8 03 00 00 00 mov $0x3,%eax
5aa: cd 40 int $0x40
5ac: c3 ret
000005ad <pipe>:
SYSCALL(pipe)
5ad: b8 04 00 00 00 mov $0x4,%eax
5b2: cd 40 int $0x40
5b4: c3 ret
000005b5 <read>:
SYSCALL(read)
5b5: b8 05 00 00 00 mov $0x5,%eax
5ba: cd 40 int $0x40
5bc: c3 ret
000005bd <write>:
SYSCALL(write)
5bd: b8 10 00 00 00 mov $0x10,%eax
5c2: cd 40 int $0x40
5c4: c3 ret
000005c5 <close>:
SYSCALL(close)
5c5: b8 15 00 00 00 mov $0x15,%eax
5ca: cd 40 int $0x40
5cc: c3 ret
000005cd <kill>:
SYSCALL(kill)
5cd: b8 06 00 00 00 mov $0x6,%eax
5d2: cd 40 int $0x40
5d4: c3 ret
000005d5 <exec>:
SYSCALL(exec)
5d5: b8 07 00 00 00 mov $0x7,%eax
5da: cd 40 int $0x40
5dc: c3 ret
000005dd <open>:
SYSCALL(open)
5dd: b8 0f 00 00 00 mov $0xf,%eax
5e2: cd 40 int $0x40
5e4: c3 ret
000005e5 <mknod>:
SYSCALL(mknod)
5e5: b8 11 00 00 00 mov $0x11,%eax
5ea: cd 40 int $0x40
5ec: c3 ret
000005ed <unlink>:
SYSCALL(unlink)
5ed: b8 12 00 00 00 mov $0x12,%eax
5f2: cd 40 int $0x40
5f4: c3 ret
000005f5 <fstat>:
SYSCALL(fstat)
5f5: b8 08 00 00 00 mov $0x8,%eax
5fa: cd 40 int $0x40
5fc: c3 ret
000005fd <link>:
SYSCALL(link)
5fd: b8 13 00 00 00 mov $0x13,%eax
602: cd 40 int $0x40
604: c3 ret
00000605 <mkdir>:
SYSCALL(mkdir)
605: b8 14 00 00 00 mov $0x14,%eax
60a: cd 40 int $0x40
60c: c3 ret
0000060d <chdir>:
SYSCALL(chdir)
60d: b8 09 00 00 00 mov $0x9,%eax
612: cd 40 int $0x40
614: c3 ret
00000615 <dup>:
SYSCALL(dup)
615: b8 0a 00 00 00 mov $0xa,%eax
61a: cd 40 int $0x40
61c: c3 ret
0000061d <getpid>:
SYSCALL(getpid)
61d: b8 0b 00 00 00 mov $0xb,%eax
622: cd 40 int $0x40
624: c3 ret
00000625 <sbrk>:
SYSCALL(sbrk)
625: b8 0c 00 00 00 mov $0xc,%eax
62a: cd 40 int $0x40
62c: c3 ret
0000062d <sleep>:
SYSCALL(sleep)
62d: b8 0d 00 00 00 mov $0xd,%eax
632: cd 40 int $0x40
634: c3 ret
00000635 <uptime>:
SYSCALL(uptime)
635: b8 0e 00 00 00 mov $0xe,%eax
63a: cd 40 int $0x40
63c: c3 ret
0000063d <putc>:
#include "stat.h"
#include "user.h"
static void
putc(int fd, char c)
{
63d: 55 push %ebp
63e: 89 e5 mov %esp,%ebp
640: 83 ec 18 sub $0x18,%esp
643: 8b 45 0c mov 0xc(%ebp),%eax
646: 88 45 f4 mov %al,-0xc(%ebp)
write(fd, &c, 1);
649: 83 ec 04 sub $0x4,%esp
64c: 6a 01 push $0x1
64e: 8d 45 f4 lea -0xc(%ebp),%eax
651: 50 push %eax
652: ff 75 08 pushl 0x8(%ebp)
655: e8 63 ff ff ff call 5bd <write>
65a: 83 c4 10 add $0x10,%esp
}
65d: 90 nop
65e: c9 leave
65f: c3 ret
00000660 <printint>:
static void
printint(int fd, int xx, int base, int sgn)
{
660: 55 push %ebp
661: 89 e5 mov %esp,%ebp
663: 53 push %ebx
664: 83 ec 24 sub $0x24,%esp
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
667: c7 45 f0 00 00 00 00 movl $0x0,-0x10(%ebp)
if(sgn && xx < 0){
66e: 83 7d 14 00 cmpl $0x0,0x14(%ebp)
672: 74 17 je 68b <printint+0x2b>
674: 83 7d 0c 00 cmpl $0x0,0xc(%ebp)
678: 79 11 jns 68b <printint+0x2b>
neg = 1;
67a: c7 45 f0 01 00 00 00 movl $0x1,-0x10(%ebp)
x = -xx;
681: 8b 45 0c mov 0xc(%ebp),%eax
684: f7 d8 neg %eax
686: 89 45 ec mov %eax,-0x14(%ebp)
689: eb 06 jmp 691 <printint+0x31>
} else {
x = xx;
68b: 8b 45 0c mov 0xc(%ebp),%eax
68e: 89 45 ec mov %eax,-0x14(%ebp)
}
i = 0;
691: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
do{
buf[i++] = digits[x % base];
698: 8b 4d f4 mov -0xc(%ebp),%ecx
69b: 8d 41 01 lea 0x1(%ecx),%eax
69e: 89 45 f4 mov %eax,-0xc(%ebp)
6a1: 8b 5d 10 mov 0x10(%ebp),%ebx
6a4: 8b 45 ec mov -0x14(%ebp),%eax
6a7: ba 00 00 00 00 mov $0x0,%edx
6ac: f7 f3 div %ebx
6ae: 89 d0 mov %edx,%eax
6b0: 0f b6 80 bc 0d 00 00 movzbl 0xdbc(%eax),%eax
6b7: 88 44 0d dc mov %al,-0x24(%ebp,%ecx,1)
}while((x /= base) != 0);
6bb: 8b 5d 10 mov 0x10(%ebp),%ebx
6be: 8b 45 ec mov -0x14(%ebp),%eax
6c1: ba 00 00 00 00 mov $0x0,%edx
6c6: f7 f3 div %ebx
6c8: 89 45 ec mov %eax,-0x14(%ebp)
6cb: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
6cf: 75 c7 jne 698 <printint+0x38>
if(neg)
6d1: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
6d5: 74 2d je 704 <printint+0xa4>
buf[i++] = '-';
6d7: 8b 45 f4 mov -0xc(%ebp),%eax
6da: 8d 50 01 lea 0x1(%eax),%edx
6dd: 89 55 f4 mov %edx,-0xc(%ebp)
6e0: c6 44 05 dc 2d movb $0x2d,-0x24(%ebp,%eax,1)