forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrep.asm
2036 lines (1900 loc) · 61 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 01 mov (%ecx),%eax
16: 8b 59 04 mov 0x4(%ecx),%ebx
int fd, i;
char *pattern;
if(argc <= 1){
19: 83 f8 01 cmp $0x1,%eax
}
}
int
main(int argc, char *argv[])
{
1c: 89 45 e4 mov %eax,-0x1c(%ebp)
int fd, i;
char *pattern;
if(argc <= 1){
1f: 7e 76 jle 97 <main+0x97>
printf(2, "usage: grep pattern [file ...]\n");
exit();
}
pattern = argv[1];
21: 8b 43 04 mov 0x4(%ebx),%eax
24: 83 c3 08 add $0x8,%ebx
if(argc <= 2){
27: 83 7d e4 02 cmpl $0x2,-0x1c(%ebp)
2b: be 02 00 00 00 mov $0x2,%esi
if(argc <= 1){
printf(2, "usage: grep pattern [file ...]\n");
exit();
}
pattern = argv[1];
30: 89 45 e0 mov %eax,-0x20(%ebp)
if(argc <= 2){
33: 74 53 je 88 <main+0x88>
35: 8d 76 00 lea 0x0(%esi),%esi
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
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 5e 05 00 00 call 5a2 <open>
44: 83 c4 10 add $0x10,%esp
47: 85 c0 test %eax,%eax
49: 89 c7 mov %eax,%edi
4b: 78 27 js 74 <main+0x74>
printf(1, "grep: cannot open %s\n", argv[i]);
exit();
}
grep(pattern, fd);
4d: 83 ec 08 sub $0x8,%esp
if(argc <= 2){
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
50: 83 c6 01 add $0x1,%esi
53: 83 c3 04 add $0x4,%ebx
if((fd = open(argv[i], 0)) < 0){
printf(1, "grep: cannot open %s\n", argv[i]);
exit();
}
grep(pattern, fd);
56: 50 push %eax
57: ff 75 e0 pushl -0x20(%ebp)
5a: e8 c1 01 00 00 call 220 <grep>
close(fd);
5f: 89 3c 24 mov %edi,(%esp)
62: e8 23 05 00 00 call 58a <close>
if(argc <= 2){
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
67: 83 c4 10 add $0x10,%esp
6a: 39 75 e4 cmp %esi,-0x1c(%ebp)
6d: 7f c9 jg 38 <main+0x38>
exit();
}
grep(pattern, fd);
close(fd);
}
exit();
6f: e8 ee 04 00 00 call 562 <exit>
exit();
}
for(i = 2; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "grep: cannot open %s\n", argv[i]);
74: 50 push %eax
75: ff 33 pushl (%ebx)
77: 68 00 0a 00 00 push $0xa00
7c: 6a 01 push $0x1
7e: e8 3d 06 00 00 call 6c0 <printf>
exit();
83: e8 da 04 00 00 call 562 <exit>
exit();
}
pattern = argv[1];
if(argc <= 2){
grep(pattern, 0);
88: 52 push %edx
89: 52 push %edx
8a: 6a 00 push $0x0
8c: 50 push %eax
8d: e8 8e 01 00 00 call 220 <grep>
exit();
92: e8 cb 04 00 00 call 562 <exit>
{
int fd, i;
char *pattern;
if(argc <= 1){
printf(2, "usage: grep pattern [file ...]\n");
97: 51 push %ecx
98: 51 push %ecx
99: 68 e0 09 00 00 push $0x9e0
9e: 6a 02 push $0x2
a0: e8 1b 06 00 00 call 6c0 <printf>
exit();
a5: e8 b8 04 00 00 call 562 <exit>
aa: 66 90 xchg %ax,%ax
ac: 66 90 xchg %ax,%ax
ae: 66 90 xchg %ax,%ax
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 75 08 mov 0x8(%ebp),%esi
bc: 8b 7d 0c mov 0xc(%ebp),%edi
bf: 8b 5d 10 mov 0x10(%ebp),%ebx
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: 53 push %ebx
cc: 57 push %edi
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 13 movsbl (%ebx),%edx
dc: 84 d2 test %dl,%dl
de: 74 0c je ec <matchstar+0x3c>
e0: 83 c3 01 add $0x1,%ebx
e3: 83 fe 2e cmp $0x2e,%esi
e6: 74 e0 je c8 <matchstar+0x18>
e8: 39 f2 cmp %esi,%edx
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
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
do{ // a * matches zero or more instances
if(matchhere(re, text))
return 1;
fb: b8 01 00 00 00 mov $0x1,%eax
}while(*text!='\0' && (*text++==c || c=='.'));
return 0;
}
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>:
return 0;
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
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
119: 8b 45 08 mov 0x8(%ebp),%eax
11c: 8b 7d 0c mov 0xc(%ebp),%edi
if(re[0] == '\0')
11f: 0f b6 18 movzbl (%eax),%ebx
122: 84 db test %bl,%bl
124: 74 63 je 189 <matchhere+0x79>
return 1;
if(re[1] == '*')
126: 0f be 50 01 movsbl 0x1(%eax),%edx
12a: 80 fa 2a cmp $0x2a,%dl
12d: 74 7b je 1aa <matchhere+0x9a>
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
12f: 80 fb 24 cmp $0x24,%bl
132: 75 08 jne 13c <matchhere+0x2c>
134: 84 d2 test %dl,%dl
136: 0f 84 8a 00 00 00 je 1c6 <matchhere+0xb6>
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
13c: 0f b6 37 movzbl (%edi),%esi
13f: 89 f1 mov %esi,%ecx
141: 84 c9 test %cl,%cl
143: 74 5b je 1a0 <matchhere+0x90>
145: 38 cb cmp %cl,%bl
147: 74 05 je 14e <matchhere+0x3e>
149: 80 fb 2e cmp $0x2e,%bl
14c: 75 52 jne 1a0 <matchhere+0x90>
return matchhere(re+1, text+1);
14e: 83 c7 01 add $0x1,%edi
151: 83 c0 01 add $0x1,%eax
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
154: 84 d2 test %dl,%dl
156: 74 31 je 189 <matchhere+0x79>
return 1;
if(re[1] == '*')
158: 0f b6 58 01 movzbl 0x1(%eax),%ebx
15c: 80 fb 2a cmp $0x2a,%bl
15f: 74 4c je 1ad <matchhere+0x9d>
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
161: 80 fa 24 cmp $0x24,%dl
164: 75 04 jne 16a <matchhere+0x5a>
166: 84 db test %bl,%bl
168: 74 5c je 1c6 <matchhere+0xb6>
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
16a: 0f b6 37 movzbl (%edi),%esi
16d: 89 f1 mov %esi,%ecx
16f: 84 c9 test %cl,%cl
171: 74 2d je 1a0 <matchhere+0x90>
173: 80 fa 2e cmp $0x2e,%dl
176: 74 04 je 17c <matchhere+0x6c>
178: 38 d1 cmp %dl,%cl
17a: 75 24 jne 1a0 <matchhere+0x90>
17c: 0f be d3 movsbl %bl,%edx
return matchhere(re+1, text+1);
17f: 83 c7 01 add $0x1,%edi
182: 83 c0 01 add $0x1,%eax
}
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
185: 84 d2 test %dl,%dl
187: 75 cf jne 158 <matchhere+0x48>
return 1;
189: b8 01 00 00 00 mov $0x1,%eax
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
return 0;
}
18e: 8d 65 f4 lea -0xc(%ebp),%esp
191: 5b pop %ebx
192: 5e pop %esi
193: 5f pop %edi
194: 5d pop %ebp
195: c3 ret
196: 8d 76 00 lea 0x0(%esi),%esi
199: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
1a0: 8d 65 f4 lea -0xc(%ebp),%esp
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
return 0;
1a3: 31 c0 xor %eax,%eax
}
1a5: 5b pop %ebx
1a6: 5e pop %esi
1a7: 5f pop %edi
1a8: 5d pop %ebp
1a9: c3 ret
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
if(re[0] == '\0')
return 1;
if(re[1] == '*')
1aa: 0f be d3 movsbl %bl,%edx
return matchstar(re[0], re+2, text);
1ad: 83 ec 04 sub $0x4,%esp
1b0: 83 c0 02 add $0x2,%eax
1b3: 57 push %edi
1b4: 50 push %eax
1b5: 52 push %edx
1b6: e8 f5 fe ff ff call b0 <matchstar>
1bb: 83 c4 10 add $0x10,%esp
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
return matchhere(re+1, text+1);
return 0;
}
1be: 8d 65 f4 lea -0xc(%ebp),%esp
1c1: 5b pop %ebx
1c2: 5e pop %esi
1c3: 5f pop %edi
1c4: 5d pop %ebp
1c5: c3 ret
if(re[0] == '\0')
return 1;
if(re[1] == '*')
return matchstar(re[0], re+2, text);
if(re[0] == '$' && re[1] == '\0')
return *text == '\0';
1c6: 31 c0 xor %eax,%eax
1c8: 80 3f 00 cmpb $0x0,(%edi)
1cb: 0f 94 c0 sete %al
1ce: eb be jmp 18e <matchhere+0x7e>
000001d0 <match>:
int matchhere(char*, char*);
int matchstar(int, char*, char*);
int
match(char *re, char *text)
{
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 2c jmp 20e <match+0x3e>
1e2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
return matchhere(re+1, text);
do{ // must look at empty string
if(matchhere(re, text))
return 1;
}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>
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
do{ // must look at empty string
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
}while(*text++ != '\0');
return 0;
}
207: 8d 65 f8 lea -0x8(%ebp),%esp
20a: 5b pop %ebx
20b: 5e pop %esi
20c: 5d pop %ebp
20d: c3 ret
int
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
20e: 83 c6 01 add $0x1,%esi
211: 89 75 08 mov %esi,0x8(%ebp)
do{ // must look at empty string
if(matchhere(re, text))
return 1;
}while(*text++ != '\0');
return 0;
}
214: 8d 65 f8 lea -0x8(%ebp),%esp
217: 5b pop %ebx
218: 5e pop %esi
219: 5d pop %ebp
int
match(char *re, char *text)
{
if(re[0] == '^')
return matchhere(re+1, text);
21a: e9 f1 fe ff ff jmp 110 <matchhere>
21f: 90 nop
00000220 <grep>:
char buf[1024];
int match(char*, char*);
void
grep(char *pattern, int fd)
{
220: 55 push %ebp
221: 89 e5 mov %esp,%ebp
223: 57 push %edi
224: 56 push %esi
225: 53 push %ebx
226: 83 ec 1c sub $0x1c,%esp
229: 8b 75 08 mov 0x8(%ebp),%esi
int n, m;
char *p, *q;
m = 0;
22c: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
233: 90 nop
234: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
238: 8b 4d e4 mov -0x1c(%ebp),%ecx
23b: b8 ff 03 00 00 mov $0x3ff,%eax
240: 83 ec 04 sub $0x4,%esp
243: 29 c8 sub %ecx,%eax
245: 50 push %eax
246: 8d 81 e0 0d 00 00 lea 0xde0(%ecx),%eax
24c: 50 push %eax
24d: ff 75 0c pushl 0xc(%ebp)
250: e8 25 03 00 00 call 57a <read>
255: 83 c4 10 add $0x10,%esp
258: 85 c0 test %eax,%eax
25a: 0f 8e ac 00 00 00 jle 30c <grep+0xec>
m += n;
260: 01 45 e4 add %eax,-0x1c(%ebp)
buf[m] = '\0';
p = buf;
263: bb e0 0d 00 00 mov $0xde0,%ebx
int n, m;
char *p, *q;
m = 0;
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
m += n;
268: 8b 55 e4 mov -0x1c(%ebp),%edx
buf[m] = '\0';
26b: c6 82 e0 0d 00 00 00 movb $0x0,0xde0(%edx)
272: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
p = buf;
while((q = strchr(p, '\n')) != 0){
278: 83 ec 08 sub $0x8,%esp
27b: 6a 0a push $0xa
27d: 53 push %ebx
27e: e8 6d 01 00 00 call 3f0 <strchr>
283: 83 c4 10 add $0x10,%esp
286: 85 c0 test %eax,%eax
288: 89 c7 mov %eax,%edi
28a: 74 3c je 2c8 <grep+0xa8>
*q = 0;
if(match(pattern, p)){
28c: 83 ec 08 sub $0x8,%esp
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
m += n;
buf[m] = '\0';
p = buf;
while((q = strchr(p, '\n')) != 0){
*q = 0;
28f: c6 07 00 movb $0x0,(%edi)
if(match(pattern, p)){
292: 53 push %ebx
293: 56 push %esi
294: e8 37 ff ff ff call 1d0 <match>
299: 83 c4 10 add $0x10,%esp
29c: 85 c0 test %eax,%eax
29e: 75 08 jne 2a8 <grep+0x88>
2a0: 8d 5f 01 lea 0x1(%edi),%ebx
2a3: eb d3 jmp 278 <grep+0x58>
2a5: 8d 76 00 lea 0x0(%esi),%esi
*q = '\n';
2a8: c6 07 0a movb $0xa,(%edi)
write(1, p, q+1 - p);
2ab: 83 c7 01 add $0x1,%edi
2ae: 83 ec 04 sub $0x4,%esp
2b1: 89 f8 mov %edi,%eax
2b3: 29 d8 sub %ebx,%eax
2b5: 50 push %eax
2b6: 53 push %ebx
2b7: 89 fb mov %edi,%ebx
2b9: 6a 01 push $0x1
2bb: e8 c2 02 00 00 call 582 <write>
2c0: 83 c4 10 add $0x10,%esp
2c3: eb b3 jmp 278 <grep+0x58>
2c5: 8d 76 00 lea 0x0(%esi),%esi
}
p = q+1;
}
if(p == buf)
2c8: 81 fb e0 0d 00 00 cmp $0xde0,%ebx
2ce: 74 30 je 300 <grep+0xe0>
m = 0;
if(m > 0){
2d0: 8b 45 e4 mov -0x1c(%ebp),%eax
2d3: 85 c0 test %eax,%eax
2d5: 0f 8e 5d ff ff ff jle 238 <grep+0x18>
m -= p - buf;
2db: 89 d8 mov %ebx,%eax
memmove(buf, p, m);
2dd: 83 ec 04 sub $0x4,%esp
p = q+1;
}
if(p == buf)
m = 0;
if(m > 0){
m -= p - buf;
2e0: 2d e0 0d 00 00 sub $0xde0,%eax
2e5: 29 45 e4 sub %eax,-0x1c(%ebp)
2e8: 8b 4d e4 mov -0x1c(%ebp),%ecx
memmove(buf, p, m);
2eb: 51 push %ecx
2ec: 53 push %ebx
2ed: 68 e0 0d 00 00 push $0xde0
2f2: e8 39 02 00 00 call 530 <memmove>
2f7: 83 c4 10 add $0x10,%esp
2fa: e9 39 ff ff ff jmp 238 <grep+0x18>
2ff: 90 nop
write(1, p, q+1 - p);
}
p = q+1;
}
if(p == buf)
m = 0;
300: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
307: e9 2c ff ff ff jmp 238 <grep+0x18>
if(m > 0){
m -= p - buf;
memmove(buf, p, m);
}
}
}
30c: 8d 65 f4 lea -0xc(%ebp),%esp
30f: 5b pop %ebx
310: 5e pop %esi
311: 5f pop %edi
312: 5d pop %ebp
313: c3 ret
314: 66 90 xchg %ax,%ax
316: 66 90 xchg %ax,%ax
318: 66 90 xchg %ax,%ax
31a: 66 90 xchg %ax,%ax
31c: 66 90 xchg %ax,%ax
31e: 66 90 xchg %ax,%ax
00000320 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
320: 55 push %ebp
321: 89 e5 mov %esp,%ebp
323: 53 push %ebx
324: 8b 45 08 mov 0x8(%ebp),%eax
327: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
32a: 89 c2 mov %eax,%edx
32c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
330: 83 c1 01 add $0x1,%ecx
333: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
337: 83 c2 01 add $0x1,%edx
33a: 84 db test %bl,%bl
33c: 88 5a ff mov %bl,-0x1(%edx)
33f: 75 ef jne 330 <strcpy+0x10>
;
return os;
}
341: 5b pop %ebx
342: 5d pop %ebp
343: c3 ret
344: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
34a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000350 <strcmp>:
int
strcmp(const char *p, const char *q)
{
350: 55 push %ebp
351: 89 e5 mov %esp,%ebp
353: 56 push %esi
354: 53 push %ebx
355: 8b 55 08 mov 0x8(%ebp),%edx
358: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
35b: 0f b6 02 movzbl (%edx),%eax
35e: 0f b6 19 movzbl (%ecx),%ebx
361: 84 c0 test %al,%al
363: 75 1e jne 383 <strcmp+0x33>
365: eb 29 jmp 390 <strcmp+0x40>
367: 89 f6 mov %esi,%esi
369: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
370: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
373: 0f b6 02 movzbl (%edx),%eax
p++, q++;
376: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
379: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
37d: 84 c0 test %al,%al
37f: 74 0f je 390 <strcmp+0x40>
381: 89 f1 mov %esi,%ecx
383: 38 d8 cmp %bl,%al
385: 74 e9 je 370 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
387: 29 d8 sub %ebx,%eax
}
389: 5b pop %ebx
38a: 5e pop %esi
38b: 5d pop %ebp
38c: c3 ret
38d: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
390: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
392: 29 d8 sub %ebx,%eax
}
394: 5b pop %ebx
395: 5e pop %esi
396: 5d pop %ebp
397: c3 ret
398: 90 nop
399: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000003a0 <strlen>:
uint
strlen(char *s)
{
3a0: 55 push %ebp
3a1: 89 e5 mov %esp,%ebp
3a3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
3a6: 80 39 00 cmpb $0x0,(%ecx)
3a9: 74 12 je 3bd <strlen+0x1d>
3ab: 31 d2 xor %edx,%edx
3ad: 8d 76 00 lea 0x0(%esi),%esi
3b0: 83 c2 01 add $0x1,%edx
3b3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
3b7: 89 d0 mov %edx,%eax
3b9: 75 f5 jne 3b0 <strlen+0x10>
;
return n;
}
3bb: 5d pop %ebp
3bc: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
3bd: 31 c0 xor %eax,%eax
;
return n;
}
3bf: 5d pop %ebp
3c0: c3 ret
3c1: eb 0d jmp 3d0 <memset>
3c3: 90 nop
3c4: 90 nop
3c5: 90 nop
3c6: 90 nop
3c7: 90 nop
3c8: 90 nop
3c9: 90 nop
3ca: 90 nop
3cb: 90 nop
3cc: 90 nop
3cd: 90 nop
3ce: 90 nop
3cf: 90 nop
000003d0 <memset>:
void*
memset(void *dst, int c, uint n)
{
3d0: 55 push %ebp
3d1: 89 e5 mov %esp,%ebp
3d3: 57 push %edi
3d4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
3d7: 8b 4d 10 mov 0x10(%ebp),%ecx
3da: 8b 45 0c mov 0xc(%ebp),%eax
3dd: 89 d7 mov %edx,%edi
3df: fc cld
3e0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
3e2: 89 d0 mov %edx,%eax
3e4: 5f pop %edi
3e5: 5d pop %ebp
3e6: c3 ret
3e7: 89 f6 mov %esi,%esi
3e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000003f0 <strchr>:
char*
strchr(const char *s, char c)
{
3f0: 55 push %ebp
3f1: 89 e5 mov %esp,%ebp
3f3: 53 push %ebx
3f4: 8b 45 08 mov 0x8(%ebp),%eax
3f7: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
3fa: 0f b6 10 movzbl (%eax),%edx
3fd: 84 d2 test %dl,%dl
3ff: 74 1d je 41e <strchr+0x2e>
if(*s == c)
401: 38 d3 cmp %dl,%bl
403: 89 d9 mov %ebx,%ecx
405: 75 0d jne 414 <strchr+0x24>
407: eb 17 jmp 420 <strchr+0x30>
409: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
410: 38 ca cmp %cl,%dl
412: 74 0c je 420 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
414: 83 c0 01 add $0x1,%eax
417: 0f b6 10 movzbl (%eax),%edx
41a: 84 d2 test %dl,%dl
41c: 75 f2 jne 410 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
41e: 31 c0 xor %eax,%eax
}
420: 5b pop %ebx
421: 5d pop %ebp
422: c3 ret
423: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
429: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000430 <gets>:
char*
gets(char *buf, int max)
{
430: 55 push %ebp
431: 89 e5 mov %esp,%ebp
433: 57 push %edi
434: 56 push %esi
435: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
436: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
438: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
43b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
43e: eb 29 jmp 469 <gets+0x39>
cc = read(0, &c, 1);
440: 83 ec 04 sub $0x4,%esp
443: 6a 01 push $0x1
445: 57 push %edi
446: 6a 00 push $0x0
448: e8 2d 01 00 00 call 57a <read>
if(cc < 1)
44d: 83 c4 10 add $0x10,%esp
450: 85 c0 test %eax,%eax
452: 7e 1d jle 471 <gets+0x41>
break;
buf[i++] = c;
454: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
458: 8b 55 08 mov 0x8(%ebp),%edx
45b: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
45d: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
45f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
463: 74 1b je 480 <gets+0x50>
465: 3c 0d cmp $0xd,%al
467: 74 17 je 480 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
469: 8d 5e 01 lea 0x1(%esi),%ebx
46c: 3b 5d 0c cmp 0xc(%ebp),%ebx
46f: 7c cf jl 440 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
471: 8b 45 08 mov 0x8(%ebp),%eax
474: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
478: 8d 65 f4 lea -0xc(%ebp),%esp
47b: 5b pop %ebx
47c: 5e pop %esi
47d: 5f pop %edi
47e: 5d pop %ebp
47f: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
480: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
483: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
485: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
489: 8d 65 f4 lea -0xc(%ebp),%esp
48c: 5b pop %ebx
48d: 5e pop %esi
48e: 5f pop %edi
48f: 5d pop %ebp
490: c3 ret
491: eb 0d jmp 4a0 <stat>
493: 90 nop
494: 90 nop
495: 90 nop
496: 90 nop
497: 90 nop
498: 90 nop
499: 90 nop
49a: 90 nop
49b: 90 nop
49c: 90 nop
49d: 90 nop
49e: 90 nop
49f: 90 nop
000004a0 <stat>:
int
stat(char *n, struct stat *st)
{
4a0: 55 push %ebp
4a1: 89 e5 mov %esp,%ebp
4a3: 56 push %esi
4a4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
4a5: 83 ec 08 sub $0x8,%esp
4a8: 6a 00 push $0x0
4aa: ff 75 08 pushl 0x8(%ebp)
4ad: e8 f0 00 00 00 call 5a2 <open>
if(fd < 0)
4b2: 83 c4 10 add $0x10,%esp
4b5: 85 c0 test %eax,%eax
4b7: 78 27 js 4e0 <stat+0x40>
return -1;
r = fstat(fd, st);
4b9: 83 ec 08 sub $0x8,%esp
4bc: ff 75 0c pushl 0xc(%ebp)
4bf: 89 c3 mov %eax,%ebx
4c1: 50 push %eax
4c2: e8 f3 00 00 00 call 5ba <fstat>
4c7: 89 c6 mov %eax,%esi
close(fd);
4c9: 89 1c 24 mov %ebx,(%esp)
4cc: e8 b9 00 00 00 call 58a <close>
return r;
4d1: 83 c4 10 add $0x10,%esp
4d4: 89 f0 mov %esi,%eax
}
4d6: 8d 65 f8 lea -0x8(%ebp),%esp
4d9: 5b pop %ebx
4da: 5e pop %esi
4db: 5d pop %ebp
4dc: c3 ret
4dd: 8d 76 00 lea 0x0(%esi),%esi
int fd;