-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrep.asm
1572 lines (1495 loc) · 53.6 KB
/
grep.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
_grep: 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: 53 push %ebx
10: 51 push %ecx
11: 83 ec 18 sub $0x18,%esp
14: 8b 39 mov (%ecx),%edi
16: 8b 59 04 mov 0x4(%ecx),%ebx
int fd, i;
char *pattern;
if(argc <= 1){
19: 83 ff 01 cmp $0x1,%edi
1c: 7e 7c jle 9a <main+0x9a>
printf(2, "usage: grep pattern [file ...]\n");
exit();
}
pattern = argv[1];
1e: 8b 43 04 mov 0x4(%ebx),%eax
21: 83 c3 08 add $0x8,%ebx
if(argc <= 2){
24: 83 ff 02 cmp $0x2,%edi
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
27: be 02 00 00 00 mov $0x2,%esi
pattern = argv[1];
2c: 89 45 e0 mov %eax,-0x20(%ebp)
if(argc <= 2){
2f: 74 46 je 77 <main+0x77>
31: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
if((fd = open(argv[i], 0)) < 0){
38: 83 ec 08 sub $0x8,%esp
3b: 6a 00 push $0x0
3d: ff 33 pushl (%ebx)
3f: e8 7e 05 00 00 call 5c2 <open>
44: 83 c4 10 add $0x10,%esp
47: 85 c0 test %eax,%eax
49: 78 3b js 86 <main+0x86>
printf(1, "grep: cannot open %s\n", argv[i]);
exit();
}
grep(pattern, fd);
4b: 83 ec 08 sub $0x8,%esp
4e: 89 45 e4 mov %eax,-0x1c(%ebp)
for(i = 2; i < argc; i++){
51: 83 c6 01 add $0x1,%esi
grep(pattern, fd);
54: 50 push %eax
55: ff 75 e0 pushl -0x20(%ebp)
58: 83 c3 04 add $0x4,%ebx
5b: e8 d0 01 00 00 call 230 <grep>
close(fd);
60: 8b 45 e4 mov -0x1c(%ebp),%eax
63: 89 04 24 mov %eax,(%esp)
66: e8 3f 05 00 00 call 5aa <close>
for(i = 2; i < argc; i++){
6b: 83 c4 10 add $0x10,%esp
6e: 39 f7 cmp %esi,%edi
70: 7f c6 jg 38 <main+0x38>
}
exit();
72: e8 0b 05 00 00 call 582 <exit>
grep(pattern, 0);
77: 52 push %edx
78: 52 push %edx
79: 6a 00 push $0x0
7b: 50 push %eax
7c: e8 af 01 00 00 call 230 <grep>
exit();
81: e8 fc 04 00 00 call 582 <exit>
printf(1, "grep: cannot open %s\n", argv[i]);
86: 50 push %eax
87: ff 33 pushl (%ebx)
89: 68 58 0a 00 00 push $0xa58
8e: 6a 01 push $0x1
90: e8 4b 06 00 00 call 6e0 <printf>
exit();
95: e8 e8 04 00 00 call 582 <exit>
printf(2, "usage: grep pattern [file ...]\n");
9a: 51 push %ecx
9b: 51 push %ecx
9c: 68 38 0a 00 00 push $0xa38
a1: 6a 02 push $0x2
a3: e8 38 06 00 00 call 6e0 <printf>
exit();
a8: e8 d5 04 00 00 call 582 <exit>
ad: 66 90 xchg %ax,%ax
af: 90 nop
000000b0 <matchstar>:
return 0;
}
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
b0: 55 push %ebp
b1: 89 e5 mov %esp,%ebp
b3: 57 push %edi
b4: 56 push %esi
b5: 53 push %ebx
b6: 83 ec 0c sub $0xc,%esp
b9: 8b 5d 08 mov 0x8(%ebp),%ebx
bc: 8b 75 0c mov 0xc(%ebp),%esi
bf: 8b 7d 10 mov 0x10(%ebp),%edi
c2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{ // a * matches zero or more instances
if(matchhere(re, text))
c8: 83 ec 08 sub $0x8,%esp
cb: 57 push %edi
cc: 56 push %esi
cd: e8 3e 00 00 00 call 110 <matchhere>
d2: 83 c4 10 add $0x10,%esp
d5: 85 c0 test %eax,%eax
d7: 75 1f jne f8 <matchstar+0x48>
return 1;
}while(*text!='\0' && (*text++==c || c=='.'));
d9: 0f be 17 movsbl (%edi),%edx
dc: 84 d2 test %dl,%dl
de: 74 0c je ec <matchstar+0x3c>
e0: 83 c7 01 add $0x1,%edi
e3: 39 da cmp %ebx,%edx
e5: 74 e1 je c8 <matchstar+0x18>
e7: 83 fb 2e cmp $0x2e,%ebx
ea: 74 dc je c8 <matchstar+0x18>
return 0;
}
ec: 8d 65 f4 lea -0xc(%ebp),%esp
ef: 5b pop %ebx
f0: 5e pop %esi
f1: 5f pop %edi
f2: 5d pop %ebp
f3: c3 ret
f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
f8: 8d 65 f4 lea -0xc(%ebp),%esp
return 1;
fb: b8 01 00 00 00 mov $0x1,%eax
}
100: 5b pop %ebx
101: 5e pop %esi
102: 5f pop %edi
103: 5d pop %ebp
104: c3 ret
105: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
109: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000110 <matchhere>:
{
110: 55 push %ebp
111: 89 e5 mov %esp,%ebp
113: 57 push %edi
114: 56 push %esi
115: 53 push %ebx
116: 83 ec 0c sub $0xc,%esp
if(re[0] == '\0')
119: 8b 45 08 mov 0x8(%ebp),%eax
{
11c: 8b 7d 0c mov 0xc(%ebp),%edi
if(re[0] == '\0')
11f: 0f b6 08 movzbl (%eax),%ecx
122: 84 c9 test %cl,%cl
124: 74 67 je 18d <matchhere+0x7d>
if(re[1] == '*')
126: 0f be 40 01 movsbl 0x1(%eax),%eax
12a: 3c 2a cmp $0x2a,%al
12c: 74 6c je 19a <matchhere+0x8a>
if(re[0] == '$' && re[1] == '\0')
12e: 80 f9 24 cmp $0x24,%cl
131: 0f b6 1f movzbl (%edi),%ebx
134: 75 08 jne 13e <matchhere+0x2e>
136: 84 c0 test %al,%al
138: 0f 84 81 00 00 00 je 1bf <matchhere+0xaf>
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
13e: 84 db test %bl,%bl
140: 74 09 je 14b <matchhere+0x3b>
142: 38 d9 cmp %bl,%cl
144: 74 3c je 182 <matchhere+0x72>
146: 80 f9 2e cmp $0x2e,%cl
149: 74 37 je 182 <matchhere+0x72>
}
14b: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
14e: 31 c0 xor %eax,%eax
}
150: 5b pop %ebx
151: 5e pop %esi
152: 5f pop %edi
153: 5d pop %ebp
154: c3 ret
155: 8d 76 00 lea 0x0(%esi),%esi
if(re[1] == '*')
158: 8b 75 08 mov 0x8(%ebp),%esi
15b: 0f b6 4e 01 movzbl 0x1(%esi),%ecx
15f: 80 f9 2a cmp $0x2a,%cl
162: 74 3b je 19f <matchhere+0x8f>
if(re[0] == '$' && re[1] == '\0')
164: 3c 24 cmp $0x24,%al
166: 75 04 jne 16c <matchhere+0x5c>
168: 84 c9 test %cl,%cl
16a: 74 4f je 1bb <matchhere+0xab>
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
16c: 0f b6 33 movzbl (%ebx),%esi
16f: 89 f2 mov %esi,%edx
171: 84 d2 test %dl,%dl
173: 74 d6 je 14b <matchhere+0x3b>
175: 3c 2e cmp $0x2e,%al
177: 89 df mov %ebx,%edi
179: 74 04 je 17f <matchhere+0x6f>
17b: 38 c2 cmp %al,%dl
17d: 75 cc jne 14b <matchhere+0x3b>
17f: 0f be c1 movsbl %cl,%eax
return matchhere(re+1, text+1);
182: 83 45 08 01 addl $0x1,0x8(%ebp)
if(re[0] == '\0')
186: 84 c0 test %al,%al
return matchhere(re+1, text+1);
188: 8d 5f 01 lea 0x1(%edi),%ebx
if(re[0] == '\0')
18b: 75 cb jne 158 <matchhere+0x48>
return 1;
18d: b8 01 00 00 00 mov $0x1,%eax
}
192: 8d 65 f4 lea -0xc(%ebp),%esp
195: 5b pop %ebx
196: 5e pop %esi
197: 5f pop %edi
198: 5d pop %ebp
199: c3 ret
if(re[1] == '*')
19a: 89 fb mov %edi,%ebx
19c: 0f be c1 movsbl %cl,%eax
return matchstar(re[0], re+2, text);
19f: 8b 7d 08 mov 0x8(%ebp),%edi
1a2: 83 ec 04 sub $0x4,%esp
1a5: 53 push %ebx
1a6: 8d 57 02 lea 0x2(%edi),%edx
1a9: 52 push %edx
1aa: 50 push %eax
1ab: e8 00 ff ff ff call b0 <matchstar>
1b0: 83 c4 10 add $0x10,%esp
}
1b3: 8d 65 f4 lea -0xc(%ebp),%esp
1b6: 5b pop %ebx
1b7: 5e pop %esi
1b8: 5f pop %edi
1b9: 5d pop %ebp
1ba: c3 ret
1bb: 0f b6 5f 01 movzbl 0x1(%edi),%ebx
return *text == '\0';
1bf: 31 c0 xor %eax,%eax
1c1: 84 db test %bl,%bl
1c3: 0f 94 c0 sete %al
1c6: eb ca jmp 192 <matchhere+0x82>
1c8: 90 nop
1c9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000001d0 <match>:
{
1d0: 55 push %ebp
1d1: 89 e5 mov %esp,%ebp
1d3: 56 push %esi
1d4: 53 push %ebx
1d5: 8b 75 08 mov 0x8(%ebp),%esi
1d8: 8b 5d 0c mov 0xc(%ebp),%ebx
if(re[0] == '^')
1db: 80 3e 5e cmpb $0x5e,(%esi)
1de: 75 11 jne 1f1 <match+0x21>
1e0: eb 2e jmp 210 <match+0x40>
1e2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
}while(*text++ != '\0');
1e8: 83 c3 01 add $0x1,%ebx
1eb: 80 7b ff 00 cmpb $0x0,-0x1(%ebx)
1ef: 74 16 je 207 <match+0x37>
if(matchhere(re, text))
1f1: 83 ec 08 sub $0x8,%esp
1f4: 53 push %ebx
1f5: 56 push %esi
1f6: e8 15 ff ff ff call 110 <matchhere>
1fb: 83 c4 10 add $0x10,%esp
1fe: 85 c0 test %eax,%eax
200: 74 e6 je 1e8 <match+0x18>
return 1;
202: b8 01 00 00 00 mov $0x1,%eax
}
207: 8d 65 f8 lea -0x8(%ebp),%esp
20a: 5b pop %ebx
20b: 5e pop %esi
20c: 5d pop %ebp
20d: c3 ret
20e: 66 90 xchg %ax,%ax
return matchhere(re+1, text);
210: 83 c6 01 add $0x1,%esi
213: 89 75 08 mov %esi,0x8(%ebp)
}
216: 8d 65 f8 lea -0x8(%ebp),%esp
219: 5b pop %ebx
21a: 5e pop %esi
21b: 5d pop %ebp
return matchhere(re+1, text);
21c: e9 ef fe ff ff jmp 110 <matchhere>
221: eb 0d jmp 230 <grep>
223: 90 nop
224: 90 nop
225: 90 nop
226: 90 nop
227: 90 nop
228: 90 nop
229: 90 nop
22a: 90 nop
22b: 90 nop
22c: 90 nop
22d: 90 nop
22e: 90 nop
22f: 90 nop
00000230 <grep>:
{
230: 55 push %ebp
231: 89 e5 mov %esp,%ebp
233: 57 push %edi
234: 56 push %esi
235: 53 push %ebx
m = 0;
236: 31 f6 xor %esi,%esi
{
238: 83 ec 1c sub $0x1c,%esp
23b: 90 nop
23c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
240: b8 ff 03 00 00 mov $0x3ff,%eax
245: 83 ec 04 sub $0x4,%esp
248: 29 f0 sub %esi,%eax
24a: 50 push %eax
24b: 8d 86 40 61 07 00 lea 0x76140(%esi),%eax
251: 50 push %eax
252: ff 75 0c pushl 0xc(%ebp)
255: e8 40 03 00 00 call 59a <read>
25a: 83 c4 10 add $0x10,%esp
25d: 85 c0 test %eax,%eax
25f: 0f 8e bb 00 00 00 jle 320 <grep+0xf0>
m += n;
265: 01 c6 add %eax,%esi
p = buf;
267: bb 40 61 07 00 mov $0x76140,%ebx
buf[m] = '\0';
26c: c6 86 40 61 07 00 00 movb $0x0,0x76140(%esi)
273: 89 75 e4 mov %esi,-0x1c(%ebp)
276: 8d 76 00 lea 0x0(%esi),%esi
279: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
while((q = strchr(p, '\n')) != 0){
280: 83 ec 08 sub $0x8,%esp
283: 6a 0a push $0xa
285: 53 push %ebx
286: e8 75 01 00 00 call 400 <strchr>
28b: 83 c4 10 add $0x10,%esp
28e: 85 c0 test %eax,%eax
290: 89 c6 mov %eax,%esi
292: 74 44 je 2d8 <grep+0xa8>
if(match(pattern, p)){
294: 83 ec 08 sub $0x8,%esp
*q = 0;
297: c6 06 00 movb $0x0,(%esi)
29a: 8d 7e 01 lea 0x1(%esi),%edi
if(match(pattern, p)){
29d: 53 push %ebx
29e: ff 75 08 pushl 0x8(%ebp)
2a1: e8 2a ff ff ff call 1d0 <match>
2a6: 83 c4 10 add $0x10,%esp
2a9: 85 c0 test %eax,%eax
2ab: 75 0b jne 2b8 <grep+0x88>
p = q+1;
2ad: 89 fb mov %edi,%ebx
2af: eb cf jmp 280 <grep+0x50>
2b1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
write(1, p, q+1 - p);
2b8: 89 f8 mov %edi,%eax
2ba: 83 ec 04 sub $0x4,%esp
*q = '\n';
2bd: c6 06 0a movb $0xa,(%esi)
write(1, p, q+1 - p);
2c0: 29 d8 sub %ebx,%eax
2c2: 50 push %eax
2c3: 53 push %ebx
p = q+1;
2c4: 89 fb mov %edi,%ebx
write(1, p, q+1 - p);
2c6: 6a 01 push $0x1
2c8: e8 d5 02 00 00 call 5a2 <write>
2cd: 83 c4 10 add $0x10,%esp
2d0: eb ae jmp 280 <grep+0x50>
2d2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if(p == buf)
2d8: 81 fb 40 61 07 00 cmp $0x76140,%ebx
2de: 8b 75 e4 mov -0x1c(%ebp),%esi
2e1: 74 2d je 310 <grep+0xe0>
if(m > 0){
2e3: 85 f6 test %esi,%esi
2e5: 0f 8e 55 ff ff ff jle 240 <grep+0x10>
m -= p - buf;
2eb: 89 d8 mov %ebx,%eax
memmove(buf, p, m);
2ed: 83 ec 04 sub $0x4,%esp
m -= p - buf;
2f0: 2d 40 61 07 00 sub $0x76140,%eax
2f5: 29 c6 sub %eax,%esi
memmove(buf, p, m);
2f7: 56 push %esi
2f8: 53 push %ebx
2f9: 68 40 61 07 00 push $0x76140
2fe: e8 4d 02 00 00 call 550 <memmove>
303: 83 c4 10 add $0x10,%esp
306: e9 35 ff ff ff jmp 240 <grep+0x10>
30b: 90 nop
30c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
m = 0;
310: 31 f6 xor %esi,%esi
312: e9 29 ff ff ff jmp 240 <grep+0x10>
317: 89 f6 mov %esi,%esi
319: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
}
320: 8d 65 f4 lea -0xc(%ebp),%esp
323: 5b pop %ebx
324: 5e pop %esi
325: 5f pop %edi
326: 5d pop %ebp
327: c3 ret
328: 66 90 xchg %ax,%ax
32a: 66 90 xchg %ax,%ax
32c: 66 90 xchg %ax,%ax
32e: 66 90 xchg %ax,%ax
00000330 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 53 push %ebx
334: 8b 45 08 mov 0x8(%ebp),%eax
337: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
33a: 89 c2 mov %eax,%edx
33c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
340: 83 c1 01 add $0x1,%ecx
343: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
347: 83 c2 01 add $0x1,%edx
34a: 84 db test %bl,%bl
34c: 88 5a ff mov %bl,-0x1(%edx)
34f: 75 ef jne 340 <strcpy+0x10>
;
return os;
}
351: 5b pop %ebx
352: 5d pop %ebp
353: c3 ret
354: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
35a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000360 <strcmp>:
int
strcmp(const char *p, const char *q)
{
360: 55 push %ebp
361: 89 e5 mov %esp,%ebp
363: 53 push %ebx
364: 8b 55 08 mov 0x8(%ebp),%edx
367: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
36a: 0f b6 02 movzbl (%edx),%eax
36d: 0f b6 19 movzbl (%ecx),%ebx
370: 84 c0 test %al,%al
372: 75 1c jne 390 <strcmp+0x30>
374: eb 2a jmp 3a0 <strcmp+0x40>
376: 8d 76 00 lea 0x0(%esi),%esi
379: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
380: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
383: 0f b6 02 movzbl (%edx),%eax
p++, q++;
386: 83 c1 01 add $0x1,%ecx
389: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
38c: 84 c0 test %al,%al
38e: 74 10 je 3a0 <strcmp+0x40>
390: 38 d8 cmp %bl,%al
392: 74 ec je 380 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
394: 29 d8 sub %ebx,%eax
}
396: 5b pop %ebx
397: 5d pop %ebp
398: c3 ret
399: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
3a0: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
3a2: 29 d8 sub %ebx,%eax
}
3a4: 5b pop %ebx
3a5: 5d pop %ebp
3a6: c3 ret
3a7: 89 f6 mov %esi,%esi
3a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000003b0 <strlen>:
uint
strlen(const char *s)
{
3b0: 55 push %ebp
3b1: 89 e5 mov %esp,%ebp
3b3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
3b6: 80 39 00 cmpb $0x0,(%ecx)
3b9: 74 15 je 3d0 <strlen+0x20>
3bb: 31 d2 xor %edx,%edx
3bd: 8d 76 00 lea 0x0(%esi),%esi
3c0: 83 c2 01 add $0x1,%edx
3c3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
3c7: 89 d0 mov %edx,%eax
3c9: 75 f5 jne 3c0 <strlen+0x10>
;
return n;
}
3cb: 5d pop %ebp
3cc: c3 ret
3cd: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
3d0: 31 c0 xor %eax,%eax
}
3d2: 5d pop %ebp
3d3: c3 ret
3d4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
3da: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000003e0 <memset>:
void*
memset(void *dst, int c, uint n)
{
3e0: 55 push %ebp
3e1: 89 e5 mov %esp,%ebp
3e3: 57 push %edi
3e4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
3e7: 8b 4d 10 mov 0x10(%ebp),%ecx
3ea: 8b 45 0c mov 0xc(%ebp),%eax
3ed: 89 d7 mov %edx,%edi
3ef: fc cld
3f0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
3f2: 89 d0 mov %edx,%eax
3f4: 5f pop %edi
3f5: 5d pop %ebp
3f6: c3 ret
3f7: 89 f6 mov %esi,%esi
3f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000400 <strchr>:
char*
strchr(const char *s, char c)
{
400: 55 push %ebp
401: 89 e5 mov %esp,%ebp
403: 53 push %ebx
404: 8b 45 08 mov 0x8(%ebp),%eax
407: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
40a: 0f b6 10 movzbl (%eax),%edx
40d: 84 d2 test %dl,%dl
40f: 74 1d je 42e <strchr+0x2e>
if(*s == c)
411: 38 d3 cmp %dl,%bl
413: 89 d9 mov %ebx,%ecx
415: 75 0d jne 424 <strchr+0x24>
417: eb 17 jmp 430 <strchr+0x30>
419: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
420: 38 ca cmp %cl,%dl
422: 74 0c je 430 <strchr+0x30>
for(; *s; s++)
424: 83 c0 01 add $0x1,%eax
427: 0f b6 10 movzbl (%eax),%edx
42a: 84 d2 test %dl,%dl
42c: 75 f2 jne 420 <strchr+0x20>
return (char*)s;
return 0;
42e: 31 c0 xor %eax,%eax
}
430: 5b pop %ebx
431: 5d pop %ebp
432: c3 ret
433: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
439: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000440 <gets>:
char*
gets(char *buf, int max)
{
440: 55 push %ebp
441: 89 e5 mov %esp,%ebp
443: 57 push %edi
444: 56 push %esi
445: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
446: 31 f6 xor %esi,%esi
448: 89 f3 mov %esi,%ebx
{
44a: 83 ec 1c sub $0x1c,%esp
44d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
450: eb 2f jmp 481 <gets+0x41>
452: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
458: 8d 45 e7 lea -0x19(%ebp),%eax
45b: 83 ec 04 sub $0x4,%esp
45e: 6a 01 push $0x1
460: 50 push %eax
461: 6a 00 push $0x0
463: e8 32 01 00 00 call 59a <read>
if(cc < 1)
468: 83 c4 10 add $0x10,%esp
46b: 85 c0 test %eax,%eax
46d: 7e 1c jle 48b <gets+0x4b>
break;
buf[i++] = c;
46f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
473: 83 c7 01 add $0x1,%edi
476: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
479: 3c 0a cmp $0xa,%al
47b: 74 23 je 4a0 <gets+0x60>
47d: 3c 0d cmp $0xd,%al
47f: 74 1f je 4a0 <gets+0x60>
for(i=0; i+1 < max; ){
481: 83 c3 01 add $0x1,%ebx
484: 3b 5d 0c cmp 0xc(%ebp),%ebx
487: 89 fe mov %edi,%esi
489: 7c cd jl 458 <gets+0x18>
48b: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
48d: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
490: c6 03 00 movb $0x0,(%ebx)
}
493: 8d 65 f4 lea -0xc(%ebp),%esp
496: 5b pop %ebx
497: 5e pop %esi
498: 5f pop %edi
499: 5d pop %ebp
49a: c3 ret
49b: 90 nop
49c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
4a0: 8b 75 08 mov 0x8(%ebp),%esi
4a3: 8b 45 08 mov 0x8(%ebp),%eax
4a6: 01 de add %ebx,%esi
4a8: 89 f3 mov %esi,%ebx
buf[i] = '\0';
4aa: c6 03 00 movb $0x0,(%ebx)
}
4ad: 8d 65 f4 lea -0xc(%ebp),%esp
4b0: 5b pop %ebx
4b1: 5e pop %esi
4b2: 5f pop %edi
4b3: 5d pop %ebp
4b4: c3 ret
4b5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
4b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000004c0 <stat>:
int
stat(const 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>
close(fd);
4e7: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
4ea: 89 c6 mov %eax,%esi
close(fd);
4ec: e8 b9 00 00 00 call 5aa <close>
return r;
4f1: 83 c4 10 add $0x10,%esp
}
4f4: 8d 65 f8 lea -0x8(%ebp),%esp
4f7: 89 f0 mov %esi,%eax
4f9: 5b pop %ebx
4fa: 5e pop %esi
4fb: 5d pop %ebp
4fc: c3 ret
4fd: 8d 76 00 lea 0x0(%esi),%esi
return -1;
500: be ff ff ff ff mov $0xffffffff,%esi
505: eb ed jmp 4f4 <stat+0x34>
507: 89 f6 mov %esi,%esi
509: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000510 <atoi>:
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
n = 0;
51f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
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
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>
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, const 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;
const char *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
while(n-- > 0)
572: 39 d3 cmp %edx,%ebx
574: 75 f2 jne 568 <memmove+0x18>
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
5d1: c3 ret
000005d2 <unlink>:
SYSCALL(unlink)
5d2: b8 12 00 00 00 mov $0x12,%eax
5d7: cd 40 int $0x40
5d9: c3 ret
000005da <fstat>:
SYSCALL(fstat)
5da: b8 08 00 00 00 mov $0x8,%eax
5df: cd 40 int $0x40
5e1: c3 ret
000005e2 <link>:
SYSCALL(link)
5e2: b8 13 00 00 00 mov $0x13,%eax
5e7: cd 40 int $0x40
5e9: c3 ret
000005ea <mkdir>:
SYSCALL(mkdir)
5ea: b8 14 00 00 00 mov $0x14,%eax
5ef: cd 40 int $0x40
5f1: c3 ret
000005f2 <chdir>:
SYSCALL(chdir)
5f2: b8 09 00 00 00 mov $0x9,%eax
5f7: cd 40 int $0x40
5f9: c3 ret
000005fa <dup>:
SYSCALL(dup)
5fa: b8 0a 00 00 00 mov $0xa,%eax
5ff: cd 40 int $0x40
601: c3 ret
00000602 <getpid>:
SYSCALL(getpid)
602: b8 0b 00 00 00 mov $0xb,%eax
607: cd 40 int $0x40
609: c3 ret
0000060a <sbrk>:
SYSCALL(sbrk)
60a: b8 0c 00 00 00 mov $0xc,%eax
60f: cd 40 int $0x40
611: c3 ret
00000612 <sleep>:
SYSCALL(sleep)
612: b8 0d 00 00 00 mov $0xd,%eax
617: cd 40 int $0x40
619: c3 ret
0000061a <uptime>:
SYSCALL(uptime)
61a: b8 0e 00 00 00 mov $0xe,%eax
61f: cd 40 int $0x40
621: c3 ret
00000622 <waitx>:
SYSCALL(waitx)
622: b8 16 00 00 00 mov $0x16,%eax
627: cd 40 int $0x40
629: c3 ret
0000062a <set_priority>:
SYSCALL(set_priority)
62a: b8 17 00 00 00 mov $0x17,%eax
62f: cd 40 int $0x40
631: c3 ret
00000632 <getpinfo>:
SYSCALL(getpinfo)
632: b8 18 00 00 00 mov $0x18,%eax
637: cd 40 int $0x40
639: c3 ret
63a: 66 90 xchg %ax,%ax
63c: 66 90 xchg %ax,%ax
63e: 66 90 xchg %ax,%ax
00000640 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
640: 55 push %ebp
641: 89 e5 mov %esp,%ebp