-
Notifications
You must be signed in to change notification settings - Fork 2
/
grep.asm
1609 lines (1506 loc) · 54.8 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 <grep>:
char buf[1024];
int match(char*, char*);
void
grep(char *pattern, int fd)
{
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 18 sub $0x18,%esp
int n, m;
char *p, *q;
m = 0;
6: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){
d: e9 ab 00 00 00 jmp bd <grep+0xbd>
m += n;
12: 8b 45 ec mov -0x14(%ebp),%eax
15: 01 45 f4 add %eax,-0xc(%ebp)
p = buf;
18: c7 45 f0 80 0e 00 00 movl $0xe80,-0x10(%ebp)
while((q = strchr(p, '\n')) != 0){
1f: eb 4a jmp 6b <grep+0x6b>
*q = 0;
21: 8b 45 e8 mov -0x18(%ebp),%eax
24: c6 00 00 movb $0x0,(%eax)
if(match(pattern, p)){
27: 83 ec 08 sub $0x8,%esp
2a: ff 75 f0 pushl -0x10(%ebp)
2d: ff 75 08 pushl 0x8(%ebp)
30: e8 9a 01 00 00 call 1cf <match>
35: 83 c4 10 add $0x10,%esp
38: 85 c0 test %eax,%eax
3a: 74 26 je 62 <grep+0x62>
*q = '\n';
3c: 8b 45 e8 mov -0x18(%ebp),%eax
3f: c6 00 0a movb $0xa,(%eax)
write(1, p, q+1 - p);
42: 8b 45 e8 mov -0x18(%ebp),%eax
45: 83 c0 01 add $0x1,%eax
48: 89 c2 mov %eax,%edx
4a: 8b 45 f0 mov -0x10(%ebp),%eax
4d: 29 c2 sub %eax,%edx
4f: 89 d0 mov %edx,%eax
51: 83 ec 04 sub $0x4,%esp
54: 50 push %eax
55: ff 75 f0 pushl -0x10(%ebp)
58: 6a 01 push $0x1
5a: e8 73 05 00 00 call 5d2 <write>
5f: 83 c4 10 add $0x10,%esp
}
p = q+1;
62: 8b 45 e8 mov -0x18(%ebp),%eax
65: 83 c0 01 add $0x1,%eax
68: 89 45 f0 mov %eax,-0x10(%ebp)
m = 0;
while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){
m += n;
p = buf;
while((q = strchr(p, '\n')) != 0){
6b: 83 ec 08 sub $0x8,%esp
6e: 6a 0a push $0xa
70: ff 75 f0 pushl -0x10(%ebp)
73: e8 89 03 00 00 call 401 <strchr>
78: 83 c4 10 add $0x10,%esp
7b: 89 45 e8 mov %eax,-0x18(%ebp)
7e: 83 7d e8 00 cmpl $0x0,-0x18(%ebp)
82: 75 9d jne 21 <grep+0x21>
*q = '\n';
write(1, p, q+1 - p);
}
p = q+1;
}
if(p == buf)
84: 81 7d f0 80 0e 00 00 cmpl $0xe80,-0x10(%ebp)
8b: 75 07 jne 94 <grep+0x94>
m = 0;
8d: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
if(m > 0){
94: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
98: 7e 23 jle bd <grep+0xbd>
m -= p - buf;
9a: 8b 45 f0 mov -0x10(%ebp),%eax
9d: ba 80 0e 00 00 mov $0xe80,%edx
a2: 29 d0 sub %edx,%eax
a4: 29 45 f4 sub %eax,-0xc(%ebp)
memmove(buf, p, m);
a7: 83 ec 04 sub $0x4,%esp
aa: ff 75 f4 pushl -0xc(%ebp)
ad: ff 75 f0 pushl -0x10(%ebp)
b0: 68 80 0e 00 00 push $0xe80
b5: e8 83 04 00 00 call 53d <memmove>
ba: 83 c4 10 add $0x10,%esp
{
int n, m;
char *p, *q;
m = 0;
while((n = read(fd, buf+m, sizeof(buf)-m)) > 0){
bd: 8b 45 f4 mov -0xc(%ebp),%eax
c0: ba 00 04 00 00 mov $0x400,%edx
c5: 29 c2 sub %eax,%edx
c7: 89 d0 mov %edx,%eax
c9: 89 c2 mov %eax,%edx
cb: 8b 45 f4 mov -0xc(%ebp),%eax
ce: 05 80 0e 00 00 add $0xe80,%eax
d3: 83 ec 04 sub $0x4,%esp
d6: 52 push %edx
d7: 50 push %eax
d8: ff 75 0c pushl 0xc(%ebp)
db: e8 ea 04 00 00 call 5ca <read>
e0: 83 c4 10 add $0x10,%esp
e3: 89 45 ec mov %eax,-0x14(%ebp)
e6: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
ea: 0f 8f 22 ff ff ff jg 12 <grep+0x12>
if(m > 0){
m -= p - buf;
memmove(buf, p, m);
}
}
}
f0: 90 nop
f1: c9 leave
f2: c3 ret
000000f3 <main>:
int
main(int argc, char *argv[])
{
f3: 8d 4c 24 04 lea 0x4(%esp),%ecx
f7: 83 e4 f0 and $0xfffffff0,%esp
fa: ff 71 fc pushl -0x4(%ecx)
fd: 55 push %ebp
fe: 89 e5 mov %esp,%ebp
100: 53 push %ebx
101: 51 push %ecx
102: 83 ec 10 sub $0x10,%esp
105: 89 cb mov %ecx,%ebx
int fd, i;
char *pattern;
if(argc <= 1){
107: 83 3b 01 cmpl $0x1,(%ebx)
10a: 7f 17 jg 123 <main+0x30>
printf(2, "usage: grep pattern [file ...]\n");
10c: 83 ec 08 sub $0x8,%esp
10f: 68 08 0b 00 00 push $0xb08
114: 6a 02 push $0x2
116: e8 36 06 00 00 call 751 <printf>
11b: 83 c4 10 add $0x10,%esp
exit();
11e: e8 8f 04 00 00 call 5b2 <exit>
}
pattern = argv[1];
123: 8b 43 04 mov 0x4(%ebx),%eax
126: 8b 40 04 mov 0x4(%eax),%eax
129: 89 45 f0 mov %eax,-0x10(%ebp)
if(argc <= 2){
12c: 83 3b 02 cmpl $0x2,(%ebx)
12f: 7f 15 jg 146 <main+0x53>
grep(pattern, 0);
131: 83 ec 08 sub $0x8,%esp
134: 6a 00 push $0x0
136: ff 75 f0 pushl -0x10(%ebp)
139: e8 c2 fe ff ff call 0 <grep>
13e: 83 c4 10 add $0x10,%esp
exit();
141: e8 6c 04 00 00 call 5b2 <exit>
}
for(i = 2; i < argc; i++){
146: c7 45 f4 02 00 00 00 movl $0x2,-0xc(%ebp)
14d: eb 74 jmp 1c3 <main+0xd0>
if((fd = open(argv[i], 0)) < 0){
14f: 8b 45 f4 mov -0xc(%ebp),%eax
152: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx
159: 8b 43 04 mov 0x4(%ebx),%eax
15c: 01 d0 add %edx,%eax
15e: 8b 00 mov (%eax),%eax
160: 83 ec 08 sub $0x8,%esp
163: 6a 00 push $0x0
165: 50 push %eax
166: e8 87 04 00 00 call 5f2 <open>
16b: 83 c4 10 add $0x10,%esp
16e: 89 45 ec mov %eax,-0x14(%ebp)
171: 83 7d ec 00 cmpl $0x0,-0x14(%ebp)
175: 79 29 jns 1a0 <main+0xad>
printf(1, "grep: cannot open %s\n", argv[i]);
177: 8b 45 f4 mov -0xc(%ebp),%eax
17a: 8d 14 85 00 00 00 00 lea 0x0(,%eax,4),%edx
181: 8b 43 04 mov 0x4(%ebx),%eax
184: 01 d0 add %edx,%eax
186: 8b 00 mov (%eax),%eax
188: 83 ec 04 sub $0x4,%esp
18b: 50 push %eax
18c: 68 28 0b 00 00 push $0xb28
191: 6a 01 push $0x1
193: e8 b9 05 00 00 call 751 <printf>
198: 83 c4 10 add $0x10,%esp
exit();
19b: e8 12 04 00 00 call 5b2 <exit>
}
grep(pattern, fd);
1a0: 83 ec 08 sub $0x8,%esp
1a3: ff 75 ec pushl -0x14(%ebp)
1a6: ff 75 f0 pushl -0x10(%ebp)
1a9: e8 52 fe ff ff call 0 <grep>
1ae: 83 c4 10 add $0x10,%esp
close(fd);
1b1: 83 ec 0c sub $0xc,%esp
1b4: ff 75 ec pushl -0x14(%ebp)
1b7: e8 1e 04 00 00 call 5da <close>
1bc: 83 c4 10 add $0x10,%esp
if(argc <= 2){
grep(pattern, 0);
exit();
}
for(i = 2; i < argc; i++){
1bf: 83 45 f4 01 addl $0x1,-0xc(%ebp)
1c3: 8b 45 f4 mov -0xc(%ebp),%eax
1c6: 3b 03 cmp (%ebx),%eax
1c8: 7c 85 jl 14f <main+0x5c>
exit();
}
grep(pattern, fd);
close(fd);
}
exit();
1ca: e8 e3 03 00 00 call 5b2 <exit>
000001cf <match>:
int matchhere(char*, char*);
int matchstar(int, char*, char*);
int
match(char *re, char *text)
{
1cf: 55 push %ebp
1d0: 89 e5 mov %esp,%ebp
1d2: 83 ec 08 sub $0x8,%esp
if(re[0] == '^')
1d5: 8b 45 08 mov 0x8(%ebp),%eax
1d8: 0f b6 00 movzbl (%eax),%eax
1db: 3c 5e cmp $0x5e,%al
1dd: 75 17 jne 1f6 <match+0x27>
return matchhere(re+1, text);
1df: 8b 45 08 mov 0x8(%ebp),%eax
1e2: 83 c0 01 add $0x1,%eax
1e5: 83 ec 08 sub $0x8,%esp
1e8: ff 75 0c pushl 0xc(%ebp)
1eb: 50 push %eax
1ec: e8 38 00 00 00 call 229 <matchhere>
1f1: 83 c4 10 add $0x10,%esp
1f4: eb 31 jmp 227 <match+0x58>
do{ // must look at empty string
if(matchhere(re, text))
1f6: 83 ec 08 sub $0x8,%esp
1f9: ff 75 0c pushl 0xc(%ebp)
1fc: ff 75 08 pushl 0x8(%ebp)
1ff: e8 25 00 00 00 call 229 <matchhere>
204: 83 c4 10 add $0x10,%esp
207: 85 c0 test %eax,%eax
209: 74 07 je 212 <match+0x43>
return 1;
20b: b8 01 00 00 00 mov $0x1,%eax
210: eb 15 jmp 227 <match+0x58>
}while(*text++ != '\0');
212: 8b 45 0c mov 0xc(%ebp),%eax
215: 8d 50 01 lea 0x1(%eax),%edx
218: 89 55 0c mov %edx,0xc(%ebp)
21b: 0f b6 00 movzbl (%eax),%eax
21e: 84 c0 test %al,%al
220: 75 d4 jne 1f6 <match+0x27>
return 0;
222: b8 00 00 00 00 mov $0x0,%eax
}
227: c9 leave
228: c3 ret
00000229 <matchhere>:
// matchhere: search for re at beginning of text
int matchhere(char *re, char *text)
{
229: 55 push %ebp
22a: 89 e5 mov %esp,%ebp
22c: 83 ec 08 sub $0x8,%esp
if(re[0] == '\0')
22f: 8b 45 08 mov 0x8(%ebp),%eax
232: 0f b6 00 movzbl (%eax),%eax
235: 84 c0 test %al,%al
237: 75 0a jne 243 <matchhere+0x1a>
return 1;
239: b8 01 00 00 00 mov $0x1,%eax
23e: e9 99 00 00 00 jmp 2dc <matchhere+0xb3>
if(re[1] == '*')
243: 8b 45 08 mov 0x8(%ebp),%eax
246: 83 c0 01 add $0x1,%eax
249: 0f b6 00 movzbl (%eax),%eax
24c: 3c 2a cmp $0x2a,%al
24e: 75 21 jne 271 <matchhere+0x48>
return matchstar(re[0], re+2, text);
250: 8b 45 08 mov 0x8(%ebp),%eax
253: 8d 50 02 lea 0x2(%eax),%edx
256: 8b 45 08 mov 0x8(%ebp),%eax
259: 0f b6 00 movzbl (%eax),%eax
25c: 0f be c0 movsbl %al,%eax
25f: 83 ec 04 sub $0x4,%esp
262: ff 75 0c pushl 0xc(%ebp)
265: 52 push %edx
266: 50 push %eax
267: e8 72 00 00 00 call 2de <matchstar>
26c: 83 c4 10 add $0x10,%esp
26f: eb 6b jmp 2dc <matchhere+0xb3>
if(re[0] == '$' && re[1] == '\0')
271: 8b 45 08 mov 0x8(%ebp),%eax
274: 0f b6 00 movzbl (%eax),%eax
277: 3c 24 cmp $0x24,%al
279: 75 1d jne 298 <matchhere+0x6f>
27b: 8b 45 08 mov 0x8(%ebp),%eax
27e: 83 c0 01 add $0x1,%eax
281: 0f b6 00 movzbl (%eax),%eax
284: 84 c0 test %al,%al
286: 75 10 jne 298 <matchhere+0x6f>
return *text == '\0';
288: 8b 45 0c mov 0xc(%ebp),%eax
28b: 0f b6 00 movzbl (%eax),%eax
28e: 84 c0 test %al,%al
290: 0f 94 c0 sete %al
293: 0f b6 c0 movzbl %al,%eax
296: eb 44 jmp 2dc <matchhere+0xb3>
if(*text!='\0' && (re[0]=='.' || re[0]==*text))
298: 8b 45 0c mov 0xc(%ebp),%eax
29b: 0f b6 00 movzbl (%eax),%eax
29e: 84 c0 test %al,%al
2a0: 74 35 je 2d7 <matchhere+0xae>
2a2: 8b 45 08 mov 0x8(%ebp),%eax
2a5: 0f b6 00 movzbl (%eax),%eax
2a8: 3c 2e cmp $0x2e,%al
2aa: 74 10 je 2bc <matchhere+0x93>
2ac: 8b 45 08 mov 0x8(%ebp),%eax
2af: 0f b6 10 movzbl (%eax),%edx
2b2: 8b 45 0c mov 0xc(%ebp),%eax
2b5: 0f b6 00 movzbl (%eax),%eax
2b8: 38 c2 cmp %al,%dl
2ba: 75 1b jne 2d7 <matchhere+0xae>
return matchhere(re+1, text+1);
2bc: 8b 45 0c mov 0xc(%ebp),%eax
2bf: 8d 50 01 lea 0x1(%eax),%edx
2c2: 8b 45 08 mov 0x8(%ebp),%eax
2c5: 83 c0 01 add $0x1,%eax
2c8: 83 ec 08 sub $0x8,%esp
2cb: 52 push %edx
2cc: 50 push %eax
2cd: e8 57 ff ff ff call 229 <matchhere>
2d2: 83 c4 10 add $0x10,%esp
2d5: eb 05 jmp 2dc <matchhere+0xb3>
return 0;
2d7: b8 00 00 00 00 mov $0x0,%eax
}
2dc: c9 leave
2dd: c3 ret
000002de <matchstar>:
// matchstar: search for c*re at beginning of text
int matchstar(int c, char *re, char *text)
{
2de: 55 push %ebp
2df: 89 e5 mov %esp,%ebp
2e1: 83 ec 08 sub $0x8,%esp
do{ // a * matches zero or more instances
if(matchhere(re, text))
2e4: 83 ec 08 sub $0x8,%esp
2e7: ff 75 10 pushl 0x10(%ebp)
2ea: ff 75 0c pushl 0xc(%ebp)
2ed: e8 37 ff ff ff call 229 <matchhere>
2f2: 83 c4 10 add $0x10,%esp
2f5: 85 c0 test %eax,%eax
2f7: 74 07 je 300 <matchstar+0x22>
return 1;
2f9: b8 01 00 00 00 mov $0x1,%eax
2fe: eb 29 jmp 329 <matchstar+0x4b>
}while(*text!='\0' && (*text++==c || c=='.'));
300: 8b 45 10 mov 0x10(%ebp),%eax
303: 0f b6 00 movzbl (%eax),%eax
306: 84 c0 test %al,%al
308: 74 1a je 324 <matchstar+0x46>
30a: 8b 45 10 mov 0x10(%ebp),%eax
30d: 8d 50 01 lea 0x1(%eax),%edx
310: 89 55 10 mov %edx,0x10(%ebp)
313: 0f b6 00 movzbl (%eax),%eax
316: 0f be c0 movsbl %al,%eax
319: 3b 45 08 cmp 0x8(%ebp),%eax
31c: 74 c6 je 2e4 <matchstar+0x6>
31e: 83 7d 08 2e cmpl $0x2e,0x8(%ebp)
322: 74 c0 je 2e4 <matchstar+0x6>
return 0;
324: b8 00 00 00 00 mov $0x0,%eax
}
329: c9 leave
32a: c3 ret
0000032b <stosb>:
"cc");
}
static inline void
stosb(void *addr, int data, int cnt)
{
32b: 55 push %ebp
32c: 89 e5 mov %esp,%ebp
32e: 57 push %edi
32f: 53 push %ebx
asm volatile("cld; rep stosb" :
330: 8b 4d 08 mov 0x8(%ebp),%ecx
333: 8b 55 10 mov 0x10(%ebp),%edx
336: 8b 45 0c mov 0xc(%ebp),%eax
339: 89 cb mov %ecx,%ebx
33b: 89 df mov %ebx,%edi
33d: 89 d1 mov %edx,%ecx
33f: fc cld
340: f3 aa rep stos %al,%es:(%edi)
342: 89 ca mov %ecx,%edx
344: 89 fb mov %edi,%ebx
346: 89 5d 08 mov %ebx,0x8(%ebp)
349: 89 55 10 mov %edx,0x10(%ebp)
"=D" (addr), "=c" (cnt) :
"0" (addr), "1" (cnt), "a" (data) :
"memory", "cc");
}
34c: 90 nop
34d: 5b pop %ebx
34e: 5f pop %edi
34f: 5d pop %ebp
350: c3 ret
00000351 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
351: 55 push %ebp
352: 89 e5 mov %esp,%ebp
354: 83 ec 10 sub $0x10,%esp
char *os;
os = s;
357: 8b 45 08 mov 0x8(%ebp),%eax
35a: 89 45 fc mov %eax,-0x4(%ebp)
while((*s++ = *t++) != 0)
35d: 90 nop
35e: 8b 45 08 mov 0x8(%ebp),%eax
361: 8d 50 01 lea 0x1(%eax),%edx
364: 89 55 08 mov %edx,0x8(%ebp)
367: 8b 55 0c mov 0xc(%ebp),%edx
36a: 8d 4a 01 lea 0x1(%edx),%ecx
36d: 89 4d 0c mov %ecx,0xc(%ebp)
370: 0f b6 12 movzbl (%edx),%edx
373: 88 10 mov %dl,(%eax)
375: 0f b6 00 movzbl (%eax),%eax
378: 84 c0 test %al,%al
37a: 75 e2 jne 35e <strcpy+0xd>
;
return os;
37c: 8b 45 fc mov -0x4(%ebp),%eax
}
37f: c9 leave
380: c3 ret
00000381 <strcmp>:
int
strcmp(const char *p, const char *q)
{
381: 55 push %ebp
382: 89 e5 mov %esp,%ebp
while(*p && *p == *q)
384: eb 08 jmp 38e <strcmp+0xd>
p++, q++;
386: 83 45 08 01 addl $0x1,0x8(%ebp)
38a: 83 45 0c 01 addl $0x1,0xc(%ebp)
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
38e: 8b 45 08 mov 0x8(%ebp),%eax
391: 0f b6 00 movzbl (%eax),%eax
394: 84 c0 test %al,%al
396: 74 10 je 3a8 <strcmp+0x27>
398: 8b 45 08 mov 0x8(%ebp),%eax
39b: 0f b6 10 movzbl (%eax),%edx
39e: 8b 45 0c mov 0xc(%ebp),%eax
3a1: 0f b6 00 movzbl (%eax),%eax
3a4: 38 c2 cmp %al,%dl
3a6: 74 de je 386 <strcmp+0x5>
p++, q++;
return (uchar)*p - (uchar)*q;
3a8: 8b 45 08 mov 0x8(%ebp),%eax
3ab: 0f b6 00 movzbl (%eax),%eax
3ae: 0f b6 d0 movzbl %al,%edx
3b1: 8b 45 0c mov 0xc(%ebp),%eax
3b4: 0f b6 00 movzbl (%eax),%eax
3b7: 0f b6 c0 movzbl %al,%eax
3ba: 29 c2 sub %eax,%edx
3bc: 89 d0 mov %edx,%eax
}
3be: 5d pop %ebp
3bf: c3 ret
000003c0 <strlen>:
uint
strlen(char *s)
{
3c0: 55 push %ebp
3c1: 89 e5 mov %esp,%ebp
3c3: 83 ec 10 sub $0x10,%esp
int n;
for(n = 0; s[n]; n++)
3c6: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
3cd: eb 04 jmp 3d3 <strlen+0x13>
3cf: 83 45 fc 01 addl $0x1,-0x4(%ebp)
3d3: 8b 55 fc mov -0x4(%ebp),%edx
3d6: 8b 45 08 mov 0x8(%ebp),%eax
3d9: 01 d0 add %edx,%eax
3db: 0f b6 00 movzbl (%eax),%eax
3de: 84 c0 test %al,%al
3e0: 75 ed jne 3cf <strlen+0xf>
;
return n;
3e2: 8b 45 fc mov -0x4(%ebp),%eax
}
3e5: c9 leave
3e6: c3 ret
000003e7 <memset>:
void*
memset(void *dst, int c, uint n)
{
3e7: 55 push %ebp
3e8: 89 e5 mov %esp,%ebp
stosb(dst, c, n);
3ea: 8b 45 10 mov 0x10(%ebp),%eax
3ed: 50 push %eax
3ee: ff 75 0c pushl 0xc(%ebp)
3f1: ff 75 08 pushl 0x8(%ebp)
3f4: e8 32 ff ff ff call 32b <stosb>
3f9: 83 c4 0c add $0xc,%esp
return dst;
3fc: 8b 45 08 mov 0x8(%ebp),%eax
}
3ff: c9 leave
400: c3 ret
00000401 <strchr>:
char*
strchr(const char *s, char c)
{
401: 55 push %ebp
402: 89 e5 mov %esp,%ebp
404: 83 ec 04 sub $0x4,%esp
407: 8b 45 0c mov 0xc(%ebp),%eax
40a: 88 45 fc mov %al,-0x4(%ebp)
for(; *s; s++)
40d: eb 14 jmp 423 <strchr+0x22>
if(*s == c)
40f: 8b 45 08 mov 0x8(%ebp),%eax
412: 0f b6 00 movzbl (%eax),%eax
415: 3a 45 fc cmp -0x4(%ebp),%al
418: 75 05 jne 41f <strchr+0x1e>
return (char*)s;
41a: 8b 45 08 mov 0x8(%ebp),%eax
41d: eb 13 jmp 432 <strchr+0x31>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
41f: 83 45 08 01 addl $0x1,0x8(%ebp)
423: 8b 45 08 mov 0x8(%ebp),%eax
426: 0f b6 00 movzbl (%eax),%eax
429: 84 c0 test %al,%al
42b: 75 e2 jne 40f <strchr+0xe>
if(*s == c)
return (char*)s;
return 0;
42d: b8 00 00 00 00 mov $0x0,%eax
}
432: c9 leave
433: c3 ret
00000434 <gets>:
char*
gets(char *buf, int max)
{
434: 55 push %ebp
435: 89 e5 mov %esp,%ebp
437: 83 ec 18 sub $0x18,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
43a: c7 45 f4 00 00 00 00 movl $0x0,-0xc(%ebp)
441: eb 42 jmp 485 <gets+0x51>
cc = read(0, &c, 1);
443: 83 ec 04 sub $0x4,%esp
446: 6a 01 push $0x1
448: 8d 45 ef lea -0x11(%ebp),%eax
44b: 50 push %eax
44c: 6a 00 push $0x0
44e: e8 77 01 00 00 call 5ca <read>
453: 83 c4 10 add $0x10,%esp
456: 89 45 f0 mov %eax,-0x10(%ebp)
if(cc < 1)
459: 83 7d f0 00 cmpl $0x0,-0x10(%ebp)
45d: 7e 33 jle 492 <gets+0x5e>
break;
buf[i++] = c;
45f: 8b 45 f4 mov -0xc(%ebp),%eax
462: 8d 50 01 lea 0x1(%eax),%edx
465: 89 55 f4 mov %edx,-0xc(%ebp)
468: 89 c2 mov %eax,%edx
46a: 8b 45 08 mov 0x8(%ebp),%eax
46d: 01 c2 add %eax,%edx
46f: 0f b6 45 ef movzbl -0x11(%ebp),%eax
473: 88 02 mov %al,(%edx)
if(c == '\n' || c == '\r')
475: 0f b6 45 ef movzbl -0x11(%ebp),%eax
479: 3c 0a cmp $0xa,%al
47b: 74 16 je 493 <gets+0x5f>
47d: 0f b6 45 ef movzbl -0x11(%ebp),%eax
481: 3c 0d cmp $0xd,%al
483: 74 0e je 493 <gets+0x5f>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
485: 8b 45 f4 mov -0xc(%ebp),%eax
488: 83 c0 01 add $0x1,%eax
48b: 3b 45 0c cmp 0xc(%ebp),%eax
48e: 7c b3 jl 443 <gets+0xf>
490: eb 01 jmp 493 <gets+0x5f>
cc = read(0, &c, 1);
if(cc < 1)
break;
492: 90 nop
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
493: 8b 55 f4 mov -0xc(%ebp),%edx
496: 8b 45 08 mov 0x8(%ebp),%eax
499: 01 d0 add %edx,%eax
49b: c6 00 00 movb $0x0,(%eax)
return buf;
49e: 8b 45 08 mov 0x8(%ebp),%eax
}
4a1: c9 leave
4a2: c3 ret
000004a3 <stat>:
int
stat(char *n, struct stat *st)
{
4a3: 55 push %ebp
4a4: 89 e5 mov %esp,%ebp
4a6: 83 ec 18 sub $0x18,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
4a9: 83 ec 08 sub $0x8,%esp
4ac: 6a 00 push $0x0
4ae: ff 75 08 pushl 0x8(%ebp)
4b1: e8 3c 01 00 00 call 5f2 <open>
4b6: 83 c4 10 add $0x10,%esp
4b9: 89 45 f4 mov %eax,-0xc(%ebp)
if(fd < 0)
4bc: 83 7d f4 00 cmpl $0x0,-0xc(%ebp)
4c0: 79 07 jns 4c9 <stat+0x26>
return -1;
4c2: b8 ff ff ff ff mov $0xffffffff,%eax
4c7: eb 25 jmp 4ee <stat+0x4b>
r = fstat(fd, st);
4c9: 83 ec 08 sub $0x8,%esp
4cc: ff 75 0c pushl 0xc(%ebp)
4cf: ff 75 f4 pushl -0xc(%ebp)
4d2: e8 33 01 00 00 call 60a <fstat>
4d7: 83 c4 10 add $0x10,%esp
4da: 89 45 f0 mov %eax,-0x10(%ebp)
close(fd);
4dd: 83 ec 0c sub $0xc,%esp
4e0: ff 75 f4 pushl -0xc(%ebp)
4e3: e8 f2 00 00 00 call 5da <close>
4e8: 83 c4 10 add $0x10,%esp
return r;
4eb: 8b 45 f0 mov -0x10(%ebp),%eax
}
4ee: c9 leave
4ef: c3 ret
000004f0 <atoi>:
int
atoi(const char *s)
{
4f0: 55 push %ebp
4f1: 89 e5 mov %esp,%ebp
4f3: 83 ec 10 sub $0x10,%esp
int n;
n = 0;
4f6: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%ebp)
while('0' <= *s && *s <= '9')
4fd: eb 25 jmp 524 <atoi+0x34>
n = n*10 + *s++ - '0';
4ff: 8b 55 fc mov -0x4(%ebp),%edx
502: 89 d0 mov %edx,%eax
504: c1 e0 02 shl $0x2,%eax
507: 01 d0 add %edx,%eax
509: 01 c0 add %eax,%eax
50b: 89 c1 mov %eax,%ecx
50d: 8b 45 08 mov 0x8(%ebp),%eax
510: 8d 50 01 lea 0x1(%eax),%edx
513: 89 55 08 mov %edx,0x8(%ebp)
516: 0f b6 00 movzbl (%eax),%eax
519: 0f be c0 movsbl %al,%eax
51c: 01 c8 add %ecx,%eax
51e: 83 e8 30 sub $0x30,%eax
521: 89 45 fc mov %eax,-0x4(%ebp)
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
524: 8b 45 08 mov 0x8(%ebp),%eax
527: 0f b6 00 movzbl (%eax),%eax
52a: 3c 2f cmp $0x2f,%al
52c: 7e 0a jle 538 <atoi+0x48>
52e: 8b 45 08 mov 0x8(%ebp),%eax
531: 0f b6 00 movzbl (%eax),%eax
534: 3c 39 cmp $0x39,%al
536: 7e c7 jle 4ff <atoi+0xf>
n = n*10 + *s++ - '0';
return n;
538: 8b 45 fc mov -0x4(%ebp),%eax
}
53b: c9 leave
53c: c3 ret
0000053d <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
53d: 55 push %ebp
53e: 89 e5 mov %esp,%ebp
540: 83 ec 10 sub $0x10,%esp
char *dst, *src;
dst = vdst;
543: 8b 45 08 mov 0x8(%ebp),%eax
546: 89 45 fc mov %eax,-0x4(%ebp)
src = vsrc;
549: 8b 45 0c mov 0xc(%ebp),%eax
54c: 89 45 f8 mov %eax,-0x8(%ebp)
while(n-- > 0)
54f: eb 17 jmp 568 <memmove+0x2b>
*dst++ = *src++;
551: 8b 45 fc mov -0x4(%ebp),%eax
554: 8d 50 01 lea 0x1(%eax),%edx
557: 89 55 fc mov %edx,-0x4(%ebp)
55a: 8b 55 f8 mov -0x8(%ebp),%edx
55d: 8d 4a 01 lea 0x1(%edx),%ecx
560: 89 4d f8 mov %ecx,-0x8(%ebp)
563: 0f b6 12 movzbl (%edx),%edx
566: 88 10 mov %dl,(%eax)
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
568: 8b 45 10 mov 0x10(%ebp),%eax
56b: 8d 50 ff lea -0x1(%eax),%edx
56e: 89 55 10 mov %edx,0x10(%ebp)
571: 85 c0 test %eax,%eax
573: 7f dc jg 551 <memmove+0x14>
*dst++ = *src++;
return vdst;
575: 8b 45 08 mov 0x8(%ebp),%eax
}
578: c9 leave
579: c3 ret
0000057a <restorer>:
57a: 83 c4 0c add $0xc,%esp
57d: 5a pop %edx
57e: 59 pop %ecx
57f: 58 pop %eax
580: c3 ret
00000581 <signal>:
"pop %ecx\n\t"
"pop %eax\n\t"
"ret\n\t");
int signal(int signum, void(*handler)(int))
{
581: 55 push %ebp
582: 89 e5 mov %esp,%ebp
584: 83 ec 08 sub $0x8,%esp
signal_restorer(restorer);
587: 83 ec 0c sub $0xc,%esp
58a: 68 7a 05 00 00 push $0x57a
58f: e8 ce 00 00 00 call 662 <signal_restorer>
594: 83 c4 10 add $0x10,%esp
return signal_register(signum, handler);
597: 83 ec 08 sub $0x8,%esp
59a: ff 75 0c pushl 0xc(%ebp)
59d: ff 75 08 pushl 0x8(%ebp)
5a0: e8 b5 00 00 00 call 65a <signal_register>
5a5: 83 c4 10 add $0x10,%esp
}
5a8: c9 leave
5a9: c3 ret
000005aa <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
5aa: b8 01 00 00 00 mov $0x1,%eax
5af: cd 40 int $0x40
5b1: c3 ret
000005b2 <exit>:
SYSCALL(exit)
5b2: b8 02 00 00 00 mov $0x2,%eax
5b7: cd 40 int $0x40
5b9: c3 ret
000005ba <wait>:
SYSCALL(wait)
5ba: b8 03 00 00 00 mov $0x3,%eax
5bf: cd 40 int $0x40
5c1: c3 ret
000005c2 <pipe>:
SYSCALL(pipe)
5c2: b8 04 00 00 00 mov $0x4,%eax
5c7: cd 40 int $0x40
5c9: c3 ret
000005ca <read>:
SYSCALL(read)
5ca: b8 05 00 00 00 mov $0x5,%eax
5cf: cd 40 int $0x40
5d1: c3 ret
000005d2 <write>:
SYSCALL(write)
5d2: b8 10 00 00 00 mov $0x10,%eax
5d7: cd 40 int $0x40
5d9: c3 ret
000005da <close>:
SYSCALL(close)
5da: b8 15 00 00 00 mov $0x15,%eax
5df: cd 40 int $0x40
5e1: c3 ret
000005e2 <kill>:
SYSCALL(kill)
5e2: b8 06 00 00 00 mov $0x6,%eax
5e7: cd 40 int $0x40
5e9: c3 ret
000005ea <exec>:
SYSCALL(exec)
5ea: b8 07 00 00 00 mov $0x7,%eax
5ef: cd 40 int $0x40
5f1: c3 ret
000005f2 <open>:
SYSCALL(open)
5f2: b8 0f 00 00 00 mov $0xf,%eax
5f7: cd 40 int $0x40
5f9: c3 ret
000005fa <mknod>:
SYSCALL(mknod)
5fa: b8 11 00 00 00 mov $0x11,%eax
5ff: cd 40 int $0x40
601: c3 ret
00000602 <unlink>:
SYSCALL(unlink)
602: b8 12 00 00 00 mov $0x12,%eax
607: cd 40 int $0x40
609: c3 ret
0000060a <fstat>:
SYSCALL(fstat)
60a: b8 08 00 00 00 mov $0x8,%eax
60f: cd 40 int $0x40
611: c3 ret
00000612 <link>:
SYSCALL(link)
612: b8 13 00 00 00 mov $0x13,%eax
617: cd 40 int $0x40
619: c3 ret
0000061a <mkdir>:
SYSCALL(mkdir)
61a: b8 14 00 00 00 mov $0x14,%eax
61f: cd 40 int $0x40
621: c3 ret
00000622 <chdir>:
SYSCALL(chdir)
622: b8 09 00 00 00 mov $0x9,%eax
627: cd 40 int $0x40
629: c3 ret
0000062a <dup>:
SYSCALL(dup)
62a: b8 0a 00 00 00 mov $0xa,%eax
62f: cd 40 int $0x40
631: c3 ret
00000632 <getpid>:
SYSCALL(getpid)
632: b8 0b 00 00 00 mov $0xb,%eax
637: cd 40 int $0x40
639: c3 ret
0000063a <sbrk>:
SYSCALL(sbrk)
63a: b8 0c 00 00 00 mov $0xc,%eax
63f: cd 40 int $0x40
641: c3 ret
00000642 <sleep>:
SYSCALL(sleep)
642: b8 0d 00 00 00 mov $0xd,%eax
647: cd 40 int $0x40
649: c3 ret
0000064a <uptime>:
SYSCALL(uptime)
64a: b8 0e 00 00 00 mov $0xe,%eax
64f: cd 40 int $0x40
651: c3 ret
00000652 <halt>:
SYSCALL(halt)
652: b8 16 00 00 00 mov $0x16,%eax
657: cd 40 int $0x40
659: c3 ret
0000065a <signal_register>:
SYSCALL(signal_register)
65a: b8 17 00 00 00 mov $0x17,%eax
65f: cd 40 int $0x40
661: c3 ret
00000662 <signal_restorer>:
SYSCALL(signal_restorer)
662: b8 18 00 00 00 mov $0x18,%eax
667: cd 40 int $0x40