This repository was archived by the owner on Apr 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrep.asm
More file actions
1737 lines (1642 loc) · 59.1 KB
/
Copy pathgrep.asm
File metadata and controls
1737 lines (1642 loc) · 59.1 KB
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: f3 0f 1e fb endbr32
4: 8d 4c 24 04 lea 0x4(%esp),%ecx
8: 83 e4 f0 and $0xfffffff0,%esp
b: ff 71 fc pushl -0x4(%ecx)
e: 55 push %ebp
f: 89 e5 mov %esp,%ebp
11: 57 push %edi
12: 56 push %esi
13: 53 push %ebx
14: 51 push %ecx
15: 83 ec 18 sub $0x18,%esp
18: 8b 01 mov (%ecx),%eax
1a: 8b 59 04 mov 0x4(%ecx),%ebx
1d: 89 45 e4 mov %eax,-0x1c(%ebp)
int fd, i;
char *pattern;
if(argc <= 1){
20: 83 f8 01 cmp $0x1,%eax
23: 7e 6b jle 90 <main+0x90>
printf(2, "usage: grep pattern [file ...]\n");
exit();
}
pattern = argv[1];
25: 8b 43 04 mov 0x4(%ebx),%eax
28: 83 c3 08 add $0x8,%ebx
if(argc <= 2){
2b: 83 7d e4 02 cmpl $0x2,-0x1c(%ebp)
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
2f: be 02 00 00 00 mov $0x2,%esi
pattern = argv[1];
34: 89 45 e0 mov %eax,-0x20(%ebp)
if(argc <= 2){
37: 75 29 jne 62 <main+0x62>
39: eb 68 jmp a3 <main+0xa3>
3b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
3f: 90 nop
if((fd = open(argv[i], 0)) < 0){
printf(1, "grep: cannot open %s\n", argv[i]);
exit();
}
grep(pattern, fd);
40: 83 ec 08 sub $0x8,%esp
for(i = 2; i < argc; i++){
43: 83 c6 01 add $0x1,%esi
46: 83 c3 04 add $0x4,%ebx
grep(pattern, fd);
49: 50 push %eax
4a: ff 75 e0 pushl -0x20(%ebp)
4d: e8 de 01 00 00 call 230 <grep>
close(fd);
52: 89 3c 24 mov %edi,(%esp)
55: e8 71 05 00 00 call 5cb <close>
for(i = 2; i < argc; i++){
5a: 83 c4 10 add $0x10,%esp
5d: 39 75 e4 cmp %esi,-0x1c(%ebp)
60: 7e 29 jle 8b <main+0x8b>
if((fd = open(argv[i], 0)) < 0){
62: 83 ec 08 sub $0x8,%esp
65: 6a 00 push $0x0
67: ff 33 pushl (%ebx)
69: e8 75 05 00 00 call 5e3 <open>
6e: 83 c4 10 add $0x10,%esp
71: 89 c7 mov %eax,%edi
73: 85 c0 test %eax,%eax
75: 79 c9 jns 40 <main+0x40>
printf(1, "grep: cannot open %s\n", argv[i]);
77: 50 push %eax
78: ff 33 pushl (%ebx)
7a: 68 84 0b 00 00 push $0xb84
7f: 6a 01 push $0x1
81: e8 da 06 00 00 call 760 <printf>
exit();
86: e8 18 05 00 00 call 5a3 <exit>
}
exit();
8b: e8 13 05 00 00 call 5a3 <exit>
printf(2, "usage: grep pattern [file ...]\n");
90: 51 push %ecx
91: 51 push %ecx
92: 68 64 0b 00 00 push $0xb64
97: 6a 02 push $0x2
99: e8 c2 06 00 00 call 760 <printf>
exit();
9e: e8 00 05 00 00 call 5a3 <exit>
grep(pattern, 0);
a3: 52 push %edx
a4: 52 push %edx
a5: 6a 00 push $0x0
a7: 50 push %eax
a8: e8 83 01 00 00 call 230 <grep>
exit();
ad: e8 f1 04 00 00 call 5a3 <exit>
b2: 66 90 xchg %ax,%ax
b4: 66 90 xchg %ax,%ax
b6: 66 90 xchg %ax,%ax
b8: 66 90 xchg %ax,%ax
ba: 66 90 xchg %ax,%ax
bc: 66 90 xchg %ax,%ax
be: 66 90 xchg %ax,%ax
000000c0 <matchstar>:
return 0;
}
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
c0: f3 0f 1e fb endbr32
c4: 55 push %ebp
c5: 89 e5 mov %esp,%ebp
c7: 57 push %edi
c8: 56 push %esi
c9: 53 push %ebx
ca: 83 ec 0c sub $0xc,%esp
cd: 8b 5d 08 mov 0x8(%ebp),%ebx
d0: 8b 75 0c mov 0xc(%ebp),%esi
d3: 8b 7d 10 mov 0x10(%ebp),%edi
d6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
dd: 8d 76 00 lea 0x0(%esi),%esi
do{ // a * matches zero or more instances
if(matchhere(re, text))
e0: 83 ec 08 sub $0x8,%esp
e3: 57 push %edi
e4: 56 push %esi
e5: e8 36 00 00 00 call 120 <matchhere>
ea: 83 c4 10 add $0x10,%esp
ed: 85 c0 test %eax,%eax
ef: 75 1f jne 110 <matchstar+0x50>
return 1;
}while(*text!='\0' && (*text++==c || c=='.'));
f1: 0f be 17 movsbl (%edi),%edx
f4: 84 d2 test %dl,%dl
f6: 74 0c je 104 <matchstar+0x44>
f8: 83 c7 01 add $0x1,%edi
fb: 39 da cmp %ebx,%edx
fd: 74 e1 je e0 <matchstar+0x20>
ff: 83 fb 2e cmp $0x2e,%ebx
102: 74 dc je e0 <matchstar+0x20>
return 0;
}
104: 8d 65 f4 lea -0xc(%ebp),%esp
107: 5b pop %ebx
108: 5e pop %esi
109: 5f pop %edi
10a: 5d pop %ebp
10b: c3 ret
10c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
110: 8d 65 f4 lea -0xc(%ebp),%esp
return 1;
113: b8 01 00 00 00 mov $0x1,%eax
}
118: 5b pop %ebx
119: 5e pop %esi
11a: 5f pop %edi
11b: 5d pop %ebp
11c: c3 ret
11d: 8d 76 00 lea 0x0(%esi),%esi
00000120 <matchhere>:
{
120: f3 0f 1e fb endbr32
124: 55 push %ebp
125: 89 e5 mov %esp,%ebp
127: 57 push %edi
128: 56 push %esi
129: 53 push %ebx
12a: 83 ec 0c sub $0xc,%esp
12d: 8b 4d 08 mov 0x8(%ebp),%ecx
130: 8b 7d 0c mov 0xc(%ebp),%edi
if(re[0] == '\0')
133: 0f b6 01 movzbl (%ecx),%eax
136: 84 c0 test %al,%al
138: 75 2b jne 165 <matchhere+0x45>
13a: eb 64 jmp 1a0 <matchhere+0x80>
13c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
if(re[0] == '$' && re[1] == '\0')
140: 0f b6 37 movzbl (%edi),%esi
143: 80 fa 24 cmp $0x24,%dl
146: 75 04 jne 14c <matchhere+0x2c>
148: 84 c0 test %al,%al
14a: 74 61 je 1ad <matchhere+0x8d>
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
14c: 89 f3 mov %esi,%ebx
14e: 84 db test %bl,%bl
150: 74 3e je 190 <matchhere+0x70>
152: 80 fa 2e cmp $0x2e,%dl
155: 74 04 je 15b <matchhere+0x3b>
157: 38 d3 cmp %dl,%bl
159: 75 35 jne 190 <matchhere+0x70>
return matchhere(re+1, text+1);
15b: 83 c7 01 add $0x1,%edi
15e: 83 c1 01 add $0x1,%ecx
if(re[0] == '\0')
161: 84 c0 test %al,%al
163: 74 3b je 1a0 <matchhere+0x80>
if(re[1] == '*')
165: 0f be d0 movsbl %al,%edx
168: 0f b6 41 01 movzbl 0x1(%ecx),%eax
16c: 3c 2a cmp $0x2a,%al
16e: 75 d0 jne 140 <matchhere+0x20>
return matchstar(re[0], re+2, text);
170: 83 ec 04 sub $0x4,%esp
173: 83 c1 02 add $0x2,%ecx
176: 57 push %edi
177: 51 push %ecx
178: 52 push %edx
179: e8 42 ff ff ff call c0 <matchstar>
17e: 83 c4 10 add $0x10,%esp
}
181: 8d 65 f4 lea -0xc(%ebp),%esp
184: 5b pop %ebx
185: 5e pop %esi
186: 5f pop %edi
187: 5d pop %ebp
188: c3 ret
189: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
190: 8d 65 f4 lea -0xc(%ebp),%esp
return 0;
193: 31 c0 xor %eax,%eax
}
195: 5b pop %ebx
196: 5e pop %esi
197: 5f pop %edi
198: 5d pop %ebp
199: c3 ret
19a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1a0: 8d 65 f4 lea -0xc(%ebp),%esp
return 1;
1a3: b8 01 00 00 00 mov $0x1,%eax
}
1a8: 5b pop %ebx
1a9: 5e pop %esi
1aa: 5f pop %edi
1ab: 5d pop %ebp
1ac: c3 ret
return *text == '\0';
1ad: 89 f0 mov %esi,%eax
1af: 84 c0 test %al,%al
1b1: 0f 94 c0 sete %al
1b4: 0f b6 c0 movzbl %al,%eax
1b7: eb c8 jmp 181 <matchhere+0x61>
1b9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000001c0 <match>:
{
1c0: f3 0f 1e fb endbr32
1c4: 55 push %ebp
1c5: 89 e5 mov %esp,%ebp
1c7: 56 push %esi
1c8: 53 push %ebx
1c9: 8b 5d 08 mov 0x8(%ebp),%ebx
1cc: 8b 75 0c mov 0xc(%ebp),%esi
if(re[0] == '^')
1cf: 80 3b 5e cmpb $0x5e,(%ebx)
1d2: 75 15 jne 1e9 <match+0x29>
1d4: eb 3a jmp 210 <match+0x50>
1d6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1dd: 8d 76 00 lea 0x0(%esi),%esi
}while(*text++ != '\0');
1e0: 83 c6 01 add $0x1,%esi
1e3: 80 7e ff 00 cmpb $0x0,-0x1(%esi)
1e7: 74 16 je 1ff <match+0x3f>
if(matchhere(re, text))
1e9: 83 ec 08 sub $0x8,%esp
1ec: 56 push %esi
1ed: 53 push %ebx
1ee: e8 2d ff ff ff call 120 <matchhere>
1f3: 83 c4 10 add $0x10,%esp
1f6: 85 c0 test %eax,%eax
1f8: 74 e6 je 1e0 <match+0x20>
return 1;
1fa: b8 01 00 00 00 mov $0x1,%eax
}
1ff: 8d 65 f8 lea -0x8(%ebp),%esp
202: 5b pop %ebx
203: 5e pop %esi
204: 5d pop %ebp
205: c3 ret
206: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
20d: 8d 76 00 lea 0x0(%esi),%esi
return matchhere(re+1, text);
210: 83 c3 01 add $0x1,%ebx
213: 89 5d 08 mov %ebx,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 ff fe ff ff jmp 120 <matchhere>
221: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
228: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
22f: 90 nop
00000230 <grep>:
{
230: f3 0f 1e fb endbr32
234: 55 push %ebp
235: 89 e5 mov %esp,%ebp
237: 57 push %edi
238: 56 push %esi
239: 53 push %ebx
23a: 83 ec 1c sub $0x1c,%esp
m = 0;
23d: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
{
244: 8b 75 08 mov 0x8(%ebp),%esi
247: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
24e: 66 90 xchg %ax,%ax
while((n = read(fd, buf+m, sizeof(buf)-m-1)) > 0){
250: 8b 4d e4 mov -0x1c(%ebp),%ecx
253: b8 ff 03 00 00 mov $0x3ff,%eax
258: 83 ec 04 sub $0x4,%esp
25b: 29 c8 sub %ecx,%eax
25d: 50 push %eax
25e: 8d 81 c0 0f 00 00 lea 0xfc0(%ecx),%eax
264: 50 push %eax
265: ff 75 0c pushl 0xc(%ebp)
268: e8 4e 03 00 00 call 5bb <read>
26d: 83 c4 10 add $0x10,%esp
270: 85 c0 test %eax,%eax
272: 0f 8e b8 00 00 00 jle 330 <grep+0x100>
m += n;
278: 01 45 e4 add %eax,-0x1c(%ebp)
27b: 8b 4d e4 mov -0x1c(%ebp),%ecx
p = buf;
27e: bb c0 0f 00 00 mov $0xfc0,%ebx
buf[m] = '\0';
283: c6 81 c0 0f 00 00 00 movb $0x0,0xfc0(%ecx)
while((q = strchr(p, '\n')) != 0){
28a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
290: 83 ec 08 sub $0x8,%esp
293: 6a 0a push $0xa
295: 53 push %ebx
296: e8 85 01 00 00 call 420 <strchr>
29b: 83 c4 10 add $0x10,%esp
29e: 89 c7 mov %eax,%edi
2a0: 85 c0 test %eax,%eax
2a2: 74 3c je 2e0 <grep+0xb0>
if(match(pattern, p)){
2a4: 83 ec 08 sub $0x8,%esp
*q = 0;
2a7: c6 07 00 movb $0x0,(%edi)
if(match(pattern, p)){
2aa: 53 push %ebx
2ab: 56 push %esi
2ac: e8 0f ff ff ff call 1c0 <match>
2b1: 83 c4 10 add $0x10,%esp
2b4: 8d 57 01 lea 0x1(%edi),%edx
2b7: 85 c0 test %eax,%eax
2b9: 75 05 jne 2c0 <grep+0x90>
p = q+1;
2bb: 89 d3 mov %edx,%ebx
2bd: eb d1 jmp 290 <grep+0x60>
2bf: 90 nop
write(1, p, q+1 - p);
2c0: 89 d0 mov %edx,%eax
2c2: 83 ec 04 sub $0x4,%esp
*q = '\n';
2c5: c6 07 0a movb $0xa,(%edi)
write(1, p, q+1 - p);
2c8: 29 d8 sub %ebx,%eax
2ca: 89 55 e0 mov %edx,-0x20(%ebp)
2cd: 50 push %eax
2ce: 53 push %ebx
2cf: 6a 01 push $0x1
2d1: e8 ed 02 00 00 call 5c3 <write>
2d6: 8b 55 e0 mov -0x20(%ebp),%edx
2d9: 83 c4 10 add $0x10,%esp
p = q+1;
2dc: 89 d3 mov %edx,%ebx
2de: eb b0 jmp 290 <grep+0x60>
if(p == buf)
2e0: 81 fb c0 0f 00 00 cmp $0xfc0,%ebx
2e6: 74 38 je 320 <grep+0xf0>
if(m > 0){
2e8: 8b 4d e4 mov -0x1c(%ebp),%ecx
2eb: 85 c9 test %ecx,%ecx
2ed: 0f 8e 5d ff ff ff jle 250 <grep+0x20>
m -= p - buf;
2f3: 89 d8 mov %ebx,%eax
memmove(buf, p, m);
2f5: 83 ec 04 sub $0x4,%esp
m -= p - buf;
2f8: 2d c0 0f 00 00 sub $0xfc0,%eax
2fd: 29 c1 sub %eax,%ecx
memmove(buf, p, m);
2ff: 51 push %ecx
300: 53 push %ebx
301: 68 c0 0f 00 00 push $0xfc0
m -= p - buf;
306: 89 4d e4 mov %ecx,-0x1c(%ebp)
memmove(buf, p, m);
309: e8 62 02 00 00 call 570 <memmove>
30e: 83 c4 10 add $0x10,%esp
311: e9 3a ff ff ff jmp 250 <grep+0x20>
316: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
31d: 8d 76 00 lea 0x0(%esi),%esi
m = 0;
320: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%ebp)
327: e9 24 ff ff ff jmp 250 <grep+0x20>
32c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
}
330: 8d 65 f4 lea -0xc(%ebp),%esp
333: 5b pop %ebx
334: 5e pop %esi
335: 5f pop %edi
336: 5d pop %ebp
337: c3 ret
338: 66 90 xchg %ax,%ax
33a: 66 90 xchg %ax,%ax
33c: 66 90 xchg %ax,%ax
33e: 66 90 xchg %ax,%ax
00000340 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
340: f3 0f 1e fb endbr32
344: 55 push %ebp
char *os;
os = s;
while((*s++ = *t++) != 0)
345: 31 c0 xor %eax,%eax
{
347: 89 e5 mov %esp,%ebp
349: 53 push %ebx
34a: 8b 4d 08 mov 0x8(%ebp),%ecx
34d: 8b 5d 0c mov 0xc(%ebp),%ebx
while((*s++ = *t++) != 0)
350: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx
354: 88 14 01 mov %dl,(%ecx,%eax,1)
357: 83 c0 01 add $0x1,%eax
35a: 84 d2 test %dl,%dl
35c: 75 f2 jne 350 <strcpy+0x10>
;
return os;
}
35e: 89 c8 mov %ecx,%eax
360: 5b pop %ebx
361: 5d pop %ebp
362: c3 ret
363: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
36a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00000370 <strcmp>:
int
strcmp(const char *p, const char *q)
{
370: f3 0f 1e fb endbr32
374: 55 push %ebp
375: 89 e5 mov %esp,%ebp
377: 53 push %ebx
378: 8b 4d 08 mov 0x8(%ebp),%ecx
37b: 8b 55 0c mov 0xc(%ebp),%edx
while(*p && *p == *q)
37e: 0f b6 01 movzbl (%ecx),%eax
381: 0f b6 1a movzbl (%edx),%ebx
384: 84 c0 test %al,%al
386: 75 19 jne 3a1 <strcmp+0x31>
388: eb 26 jmp 3b0 <strcmp+0x40>
38a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
390: 0f b6 41 01 movzbl 0x1(%ecx),%eax
p++, q++;
394: 83 c1 01 add $0x1,%ecx
397: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
39a: 0f b6 1a movzbl (%edx),%ebx
39d: 84 c0 test %al,%al
39f: 74 0f je 3b0 <strcmp+0x40>
3a1: 38 d8 cmp %bl,%al
3a3: 74 eb je 390 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
3a5: 29 d8 sub %ebx,%eax
}
3a7: 5b pop %ebx
3a8: 5d pop %ebp
3a9: c3 ret
3aa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
3b0: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
3b2: 29 d8 sub %ebx,%eax
}
3b4: 5b pop %ebx
3b5: 5d pop %ebp
3b6: c3 ret
3b7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
3be: 66 90 xchg %ax,%ax
000003c0 <strlen>:
uint
strlen(const char *s)
{
3c0: f3 0f 1e fb endbr32
3c4: 55 push %ebp
3c5: 89 e5 mov %esp,%ebp
3c7: 8b 55 08 mov 0x8(%ebp),%edx
int n;
for(n = 0; s[n]; n++)
3ca: 80 3a 00 cmpb $0x0,(%edx)
3cd: 74 21 je 3f0 <strlen+0x30>
3cf: 31 c0 xor %eax,%eax
3d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
3d8: 83 c0 01 add $0x1,%eax
3db: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1)
3df: 89 c1 mov %eax,%ecx
3e1: 75 f5 jne 3d8 <strlen+0x18>
;
return n;
}
3e3: 89 c8 mov %ecx,%eax
3e5: 5d pop %ebp
3e6: c3 ret
3e7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
3ee: 66 90 xchg %ax,%ax
for(n = 0; s[n]; n++)
3f0: 31 c9 xor %ecx,%ecx
}
3f2: 5d pop %ebp
3f3: 89 c8 mov %ecx,%eax
3f5: c3 ret
3f6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
3fd: 8d 76 00 lea 0x0(%esi),%esi
00000400 <memset>:
void*
memset(void *dst, int c, uint n)
{
400: f3 0f 1e fb endbr32
404: 55 push %ebp
405: 89 e5 mov %esp,%ebp
407: 57 push %edi
408: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
40b: 8b 4d 10 mov 0x10(%ebp),%ecx
40e: 8b 45 0c mov 0xc(%ebp),%eax
411: 89 d7 mov %edx,%edi
413: fc cld
414: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
416: 89 d0 mov %edx,%eax
418: 5f pop %edi
419: 5d pop %ebp
41a: c3 ret
41b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
41f: 90 nop
00000420 <strchr>:
char*
strchr(const char *s, char c)
{
420: f3 0f 1e fb endbr32
424: 55 push %ebp
425: 89 e5 mov %esp,%ebp
427: 8b 45 08 mov 0x8(%ebp),%eax
42a: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx
for(; *s; s++)
42e: 0f b6 10 movzbl (%eax),%edx
431: 84 d2 test %dl,%dl
433: 75 16 jne 44b <strchr+0x2b>
435: eb 21 jmp 458 <strchr+0x38>
437: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
43e: 66 90 xchg %ax,%ax
440: 0f b6 50 01 movzbl 0x1(%eax),%edx
444: 83 c0 01 add $0x1,%eax
447: 84 d2 test %dl,%dl
449: 74 0d je 458 <strchr+0x38>
if(*s == c)
44b: 38 d1 cmp %dl,%cl
44d: 75 f1 jne 440 <strchr+0x20>
return (char*)s;
return 0;
}
44f: 5d pop %ebp
450: c3 ret
451: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return 0;
458: 31 c0 xor %eax,%eax
}
45a: 5d pop %ebp
45b: c3 ret
45c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000460 <gets>:
char*
gets(char *buf, int max)
{
460: f3 0f 1e fb endbr32
464: 55 push %ebp
465: 89 e5 mov %esp,%ebp
467: 57 push %edi
468: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
469: 31 f6 xor %esi,%esi
{
46b: 53 push %ebx
46c: 89 f3 mov %esi,%ebx
46e: 83 ec 1c sub $0x1c,%esp
471: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
474: eb 33 jmp 4a9 <gets+0x49>
476: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
47d: 8d 76 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
480: 83 ec 04 sub $0x4,%esp
483: 8d 45 e7 lea -0x19(%ebp),%eax
486: 6a 01 push $0x1
488: 50 push %eax
489: 6a 00 push $0x0
48b: e8 2b 01 00 00 call 5bb <read>
if(cc < 1)
490: 83 c4 10 add $0x10,%esp
493: 85 c0 test %eax,%eax
495: 7e 1c jle 4b3 <gets+0x53>
break;
buf[i++] = c;
497: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
49b: 83 c7 01 add $0x1,%edi
49e: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
4a1: 3c 0a cmp $0xa,%al
4a3: 74 23 je 4c8 <gets+0x68>
4a5: 3c 0d cmp $0xd,%al
4a7: 74 1f je 4c8 <gets+0x68>
for(i=0; i+1 < max; ){
4a9: 83 c3 01 add $0x1,%ebx
4ac: 89 fe mov %edi,%esi
4ae: 3b 5d 0c cmp 0xc(%ebp),%ebx
4b1: 7c cd jl 480 <gets+0x20>
4b3: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
4b5: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
4b8: c6 03 00 movb $0x0,(%ebx)
}
4bb: 8d 65 f4 lea -0xc(%ebp),%esp
4be: 5b pop %ebx
4bf: 5e pop %esi
4c0: 5f pop %edi
4c1: 5d pop %ebp
4c2: c3 ret
4c3: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
4c7: 90 nop
4c8: 8b 75 08 mov 0x8(%ebp),%esi
4cb: 8b 45 08 mov 0x8(%ebp),%eax
4ce: 01 de add %ebx,%esi
4d0: 89 f3 mov %esi,%ebx
buf[i] = '\0';
4d2: c6 03 00 movb $0x0,(%ebx)
}
4d5: 8d 65 f4 lea -0xc(%ebp),%esp
4d8: 5b pop %ebx
4d9: 5e pop %esi
4da: 5f pop %edi
4db: 5d pop %ebp
4dc: c3 ret
4dd: 8d 76 00 lea 0x0(%esi),%esi
000004e0 <stat>:
int
stat(const char *n, struct stat *st)
{
4e0: f3 0f 1e fb endbr32
4e4: 55 push %ebp
4e5: 89 e5 mov %esp,%ebp
4e7: 56 push %esi
4e8: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
4e9: 83 ec 08 sub $0x8,%esp
4ec: 6a 00 push $0x0
4ee: ff 75 08 pushl 0x8(%ebp)
4f1: e8 ed 00 00 00 call 5e3 <open>
if(fd < 0)
4f6: 83 c4 10 add $0x10,%esp
4f9: 85 c0 test %eax,%eax
4fb: 78 2b js 528 <stat+0x48>
return -1;
r = fstat(fd, st);
4fd: 83 ec 08 sub $0x8,%esp
500: ff 75 0c pushl 0xc(%ebp)
503: 89 c3 mov %eax,%ebx
505: 50 push %eax
506: e8 f0 00 00 00 call 5fb <fstat>
close(fd);
50b: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
50e: 89 c6 mov %eax,%esi
close(fd);
510: e8 b6 00 00 00 call 5cb <close>
return r;
515: 83 c4 10 add $0x10,%esp
}
518: 8d 65 f8 lea -0x8(%ebp),%esp
51b: 89 f0 mov %esi,%eax
51d: 5b pop %ebx
51e: 5e pop %esi
51f: 5d pop %ebp
520: c3 ret
521: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
return -1;
528: be ff ff ff ff mov $0xffffffff,%esi
52d: eb e9 jmp 518 <stat+0x38>
52f: 90 nop
00000530 <atoi>:
int
atoi(const char *s)
{
530: f3 0f 1e fb endbr32
534: 55 push %ebp
535: 89 e5 mov %esp,%ebp
537: 53 push %ebx
538: 8b 55 08 mov 0x8(%ebp),%edx
int n;
n = 0;
while('0' <= *s && *s <= '9')
53b: 0f be 02 movsbl (%edx),%eax
53e: 8d 48 d0 lea -0x30(%eax),%ecx
541: 80 f9 09 cmp $0x9,%cl
n = 0;
544: b9 00 00 00 00 mov $0x0,%ecx
while('0' <= *s && *s <= '9')
549: 77 1a ja 565 <atoi+0x35>
54b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
54f: 90 nop
n = n*10 + *s++ - '0';
550: 83 c2 01 add $0x1,%edx
553: 8d 0c 89 lea (%ecx,%ecx,4),%ecx
556: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx
while('0' <= *s && *s <= '9')
55a: 0f be 02 movsbl (%edx),%eax
55d: 8d 58 d0 lea -0x30(%eax),%ebx
560: 80 fb 09 cmp $0x9,%bl
563: 76 eb jbe 550 <atoi+0x20>
return n;
}
565: 89 c8 mov %ecx,%eax
567: 5b pop %ebx
568: 5d pop %ebp
569: c3 ret
56a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00000570 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
570: f3 0f 1e fb endbr32
574: 55 push %ebp
575: 89 e5 mov %esp,%ebp
577: 57 push %edi
578: 8b 45 10 mov 0x10(%ebp),%eax
57b: 8b 55 08 mov 0x8(%ebp),%edx
57e: 56 push %esi
57f: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
582: 85 c0 test %eax,%eax
584: 7e 0f jle 595 <memmove+0x25>
586: 01 d0 add %edx,%eax
dst = vdst;
588: 89 d7 mov %edx,%edi
58a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
*dst++ = *src++;
590: a4 movsb %ds:(%esi),%es:(%edi)
while(n-- > 0)
591: 39 f8 cmp %edi,%eax
593: 75 fb jne 590 <memmove+0x20>
return vdst;
}
595: 5e pop %esi
596: 89 d0 mov %edx,%eax
598: 5f pop %edi
599: 5d pop %ebp
59a: c3 ret
0000059b <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
59b: b8 01 00 00 00 mov $0x1,%eax
5a0: cd 40 int $0x40
5a2: c3 ret
000005a3 <exit>:
SYSCALL(exit)
5a3: b8 02 00 00 00 mov $0x2,%eax
5a8: cd 40 int $0x40
5aa: c3 ret
000005ab <wait>:
SYSCALL(wait)
5ab: b8 03 00 00 00 mov $0x3,%eax
5b0: cd 40 int $0x40
5b2: c3 ret
000005b3 <pipe>:
SYSCALL(pipe)
5b3: b8 04 00 00 00 mov $0x4,%eax
5b8: cd 40 int $0x40
5ba: c3 ret
000005bb <read>:
SYSCALL(read)
5bb: b8 05 00 00 00 mov $0x5,%eax
5c0: cd 40 int $0x40
5c2: c3 ret
000005c3 <write>:
SYSCALL(write)
5c3: b8 10 00 00 00 mov $0x10,%eax
5c8: cd 40 int $0x40
5ca: c3 ret
000005cb <close>:
SYSCALL(close)
5cb: b8 15 00 00 00 mov $0x15,%eax
5d0: cd 40 int $0x40
5d2: c3 ret
000005d3 <kill>:
SYSCALL(kill)
5d3: b8 06 00 00 00 mov $0x6,%eax
5d8: cd 40 int $0x40
5da: c3 ret
000005db <exec>:
SYSCALL(exec)
5db: b8 07 00 00 00 mov $0x7,%eax
5e0: cd 40 int $0x40
5e2: c3 ret
000005e3 <open>:
SYSCALL(open)
5e3: b8 0f 00 00 00 mov $0xf,%eax
5e8: cd 40 int $0x40
5ea: c3 ret
000005eb <mknod>:
SYSCALL(mknod)
5eb: b8 11 00 00 00 mov $0x11,%eax
5f0: cd 40 int $0x40
5f2: c3 ret
000005f3 <unlink>:
SYSCALL(unlink)
5f3: b8 12 00 00 00 mov $0x12,%eax
5f8: cd 40 int $0x40
5fa: c3 ret
000005fb <fstat>:
SYSCALL(fstat)
5fb: b8 08 00 00 00 mov $0x8,%eax
600: cd 40 int $0x40
602: c3 ret
00000603 <link>:
SYSCALL(link)
603: b8 13 00 00 00 mov $0x13,%eax
608: cd 40 int $0x40
60a: c3 ret
0000060b <mkdir>:
SYSCALL(mkdir)
60b: b8 14 00 00 00 mov $0x14,%eax
610: cd 40 int $0x40
612: c3 ret
00000613 <chdir>:
SYSCALL(chdir)
613: b8 09 00 00 00 mov $0x9,%eax
618: cd 40 int $0x40
61a: c3 ret
0000061b <dup>:
SYSCALL(dup)
61b: b8 0a 00 00 00 mov $0xa,%eax
620: cd 40 int $0x40
622: c3 ret
00000623 <getpid>:
SYSCALL(getpid)
623: b8 0b 00 00 00 mov $0xb,%eax
628: cd 40 int $0x40
62a: c3 ret
0000062b <sbrk>:
SYSCALL(sbrk)
62b: b8 0c 00 00 00 mov $0xc,%eax
630: cd 40 int $0x40
632: c3 ret
00000633 <sleep>:
SYSCALL(sleep)
633: b8 0d 00 00 00 mov $0xd,%eax
638: cd 40 int $0x40
63a: c3 ret
0000063b <uptime>:
SYSCALL(uptime)
63b: b8 0e 00 00 00 mov $0xe,%eax
640: cd 40 int $0x40
642: c3 ret
00000643 <getHelloWorld>:
SYSCALL(getHelloWorld)
643: b8 16 00 00 00 mov $0x16,%eax
648: cd 40 int $0x40
64a: c3 ret
0000064b <getProcCount>:
SYSCALL(getProcCount)
64b: b8 17 00 00 00 mov $0x17,%eax
650: cd 40 int $0x40
652: c3 ret
00000653 <getReadCount>:
SYSCALL(getReadCount)
653: b8 18 00 00 00 mov $0x18,%eax
658: cd 40 int $0x40
65a: c3 ret
0000065b <thread_create>:
SYSCALL(thread_create)
65b: b8 19 00 00 00 mov $0x19,%eax
660: cd 40 int $0x40
662: c3 ret
00000663 <join>:
SYSCALL(join)
663: b8 1a 00 00 00 mov $0x1a,%eax
668: cd 40 int $0x40
66a: c3 ret
0000066b <getTurnaroundTime>:
SYSCALL(getTurnaroundTime)
66b: b8 1b 00 00 00 mov $0x1b,%eax
670: cd 40 int $0x40
672: c3 ret
00000673 <getWaitingTime>:
SYSCALL(getWaitingTime)
673: b8 1c 00 00 00 mov $0x1c,%eax
678: cd 40 int $0x40