-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwc.asm
3494 lines (3270 loc) · 120 KB
/
wc.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
_wc: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
printf(1, "%d %d %d %s\n", l, w, c, name);
}
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: be 01 00 00 00 mov $0x1,%esi
16: 83 ec 18 sub $0x18,%esp
19: 8b 01 mov (%ecx),%eax
1b: 8b 59 04 mov 0x4(%ecx),%ebx
1e: 83 c3 04 add $0x4,%ebx
int fd, i;
if(argc <= 1){
21: 83 f8 01 cmp $0x1,%eax
printf(1, "%d %d %d %s\n", l, w, c, name);
}
int
main(int argc, char *argv[])
{
24: 89 45 e4 mov %eax,-0x1c(%ebp)
int fd, i;
if(argc <= 1){
27: 7e 56 jle 7f <main+0x7f>
29: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
wc(0, "");
exit();
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
30: 83 ec 08 sub $0x8,%esp
33: 6a 00 push $0x0
35: ff 33 pushl (%ebx)
37: e8 c6 03 00 00 call 402 <open>
3c: 83 c4 10 add $0x10,%esp
3f: 85 c0 test %eax,%eax
41: 89 c7 mov %eax,%edi
43: 78 26 js 6b <main+0x6b>
printf(1, "wc: cannot open %s\n", argv[i]);
exit();
}
wc(fd, argv[i]);
45: 83 ec 08 sub $0x8,%esp
48: ff 33 pushl (%ebx)
if(argc <= 1){
wc(0, "");
exit();
}
for(i = 1; i < argc; i++){
4a: 83 c6 01 add $0x1,%esi
if((fd = open(argv[i], 0)) < 0){
printf(1, "wc: cannot open %s\n", argv[i]);
exit();
}
wc(fd, argv[i]);
4d: 50 push %eax
4e: 83 c3 04 add $0x4,%ebx
51: e8 4a 00 00 00 call a0 <wc>
close(fd);
56: 89 3c 24 mov %edi,(%esp)
59: e8 8c 03 00 00 call 3ea <close>
if(argc <= 1){
wc(0, "");
exit();
}
for(i = 1; i < argc; i++){
5e: 83 c4 10 add $0x10,%esp
61: 39 75 e4 cmp %esi,-0x1c(%ebp)
64: 75 ca jne 30 <main+0x30>
exit();
}
wc(fd, argv[i]);
close(fd);
}
exit();
66: e8 57 03 00 00 call 3c2 <exit>
exit();
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "wc: cannot open %s\n", argv[i]);
6b: 50 push %eax
6c: ff 33 pushl (%ebx)
6e: 68 3f 13 00 00 push $0x133f
73: 6a 01 push $0x1
75: e8 b6 04 00 00 call 530 <printf>
exit();
7a: e8 43 03 00 00 call 3c2 <exit>
main(int argc, char *argv[])
{
int fd, i;
if(argc <= 1){
wc(0, "");
7f: 52 push %edx
80: 52 push %edx
81: 68 eb 14 00 00 push $0x14eb
86: 6a 00 push $0x0
88: e8 13 00 00 00 call a0 <wc>
exit();
8d: e8 30 03 00 00 call 3c2 <exit>
92: 66 90 xchg %ax,%ax
94: 66 90 xchg %ax,%ax
96: 66 90 xchg %ax,%ax
98: 66 90 xchg %ax,%ax
9a: 66 90 xchg %ax,%ax
9c: 66 90 xchg %ax,%ax
9e: 66 90 xchg %ax,%ax
000000a0 <wc>:
char buf[512];
void
wc(int fd, char *name)
{
a0: 55 push %ebp
a1: 89 e5 mov %esp,%ebp
a3: 57 push %edi
a4: 56 push %esi
a5: 53 push %ebx
int i, n;
int l, w, c, inword;
l = w = c = 0;
inword = 0;
a6: 31 f6 xor %esi,%esi
wc(int fd, char *name)
{
int i, n;
int l, w, c, inword;
l = w = c = 0;
a8: 31 db xor %ebx,%ebx
char buf[512];
void
wc(int fd, char *name)
{
aa: 83 ec 1c sub $0x1c,%esp
int i, n;
int l, w, c, inword;
l = w = c = 0;
ad: c7 45 dc 00 00 00 00 movl $0x0,-0x24(%ebp)
b4: c7 45 e0 00 00 00 00 movl $0x0,-0x20(%ebp)
bb: 90 nop
bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
inword = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
c0: 83 ec 04 sub $0x4,%esp
c3: 68 00 02 00 00 push $0x200
c8: 68 20 1b 00 00 push $0x1b20
cd: ff 75 08 pushl 0x8(%ebp)
d0: e8 05 03 00 00 call 3da <read>
d5: 83 c4 10 add $0x10,%esp
d8: 83 f8 00 cmp $0x0,%eax
db: 89 45 e4 mov %eax,-0x1c(%ebp)
de: 7e 5f jle 13f <wc+0x9f>
e0: 31 ff xor %edi,%edi
e2: eb 0e jmp f2 <wc+0x52>
e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
for(i=0; i<n; i++){
c++;
if(buf[i] == '\n')
l++;
if(strchr(" \r\t\n\v", buf[i]))
inword = 0;
e8: 31 f6 xor %esi,%esi
int l, w, c, inword;
l = w = c = 0;
inword = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
for(i=0; i<n; i++){
ea: 83 c7 01 add $0x1,%edi
ed: 39 7d e4 cmp %edi,-0x1c(%ebp)
f0: 74 3a je 12c <wc+0x8c>
c++;
if(buf[i] == '\n')
f2: 0f be 87 20 1b 00 00 movsbl 0x1b20(%edi),%eax
l++;
f9: 31 c9 xor %ecx,%ecx
fb: 3c 0a cmp $0xa,%al
fd: 0f 94 c1 sete %cl
if(strchr(" \r\t\n\v", buf[i]))
100: 83 ec 08 sub $0x8,%esp
103: 50 push %eax
104: 68 1c 13 00 00 push $0x131c
inword = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
for(i=0; i<n; i++){
c++;
if(buf[i] == '\n')
l++;
109: 01 cb add %ecx,%ebx
if(strchr(" \r\t\n\v", buf[i]))
10b: e8 40 01 00 00 call 250 <strchr>
110: 83 c4 10 add $0x10,%esp
113: 85 c0 test %eax,%eax
115: 75 d1 jne e8 <wc+0x48>
inword = 0;
else if(!inword){
117: 85 f6 test %esi,%esi
119: 75 1d jne 138 <wc+0x98>
w++;
11b: 83 45 e0 01 addl $0x1,-0x20(%ebp)
int l, w, c, inword;
l = w = c = 0;
inword = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
for(i=0; i<n; i++){
11f: 83 c7 01 add $0x1,%edi
122: 39 7d e4 cmp %edi,-0x1c(%ebp)
l++;
if(strchr(" \r\t\n\v", buf[i]))
inword = 0;
else if(!inword){
w++;
inword = 1;
125: be 01 00 00 00 mov $0x1,%esi
int l, w, c, inword;
l = w = c = 0;
inword = 0;
while((n = read(fd, buf, sizeof(buf))) > 0){
for(i=0; i<n; i++){
12a: 75 c6 jne f2 <wc+0x52>
12c: 8b 55 e4 mov -0x1c(%ebp),%edx
12f: 01 55 dc add %edx,-0x24(%ebp)
132: eb 8c jmp c0 <wc+0x20>
134: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
138: be 01 00 00 00 mov $0x1,%esi
13d: eb ab jmp ea <wc+0x4a>
w++;
inword = 1;
}
}
}
if(n < 0){
13f: 75 24 jne 165 <wc+0xc5>
printf(1, "wc: read error\n");
exit();
}
printf(1, "%d %d %d %s\n", l, w, c, name);
141: 83 ec 08 sub $0x8,%esp
144: ff 75 0c pushl 0xc(%ebp)
147: ff 75 dc pushl -0x24(%ebp)
14a: ff 75 e0 pushl -0x20(%ebp)
14d: 53 push %ebx
14e: 68 32 13 00 00 push $0x1332
153: 6a 01 push $0x1
155: e8 d6 03 00 00 call 530 <printf>
}
15a: 83 c4 20 add $0x20,%esp
15d: 8d 65 f4 lea -0xc(%ebp),%esp
160: 5b pop %ebx
161: 5e pop %esi
162: 5f pop %edi
163: 5d pop %ebp
164: c3 ret
inword = 1;
}
}
}
if(n < 0){
printf(1, "wc: read error\n");
165: 83 ec 08 sub $0x8,%esp
168: 68 22 13 00 00 push $0x1322
16d: 6a 01 push $0x1
16f: e8 bc 03 00 00 call 530 <printf>
exit();
174: e8 49 02 00 00 call 3c2 <exit>
179: 66 90 xchg %ax,%ax
17b: 66 90 xchg %ax,%ax
17d: 66 90 xchg %ax,%ax
17f: 90 nop
00000180 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
180: 55 push %ebp
181: 89 e5 mov %esp,%ebp
183: 53 push %ebx
184: 8b 45 08 mov 0x8(%ebp),%eax
187: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
18a: 89 c2 mov %eax,%edx
18c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
190: 83 c1 01 add $0x1,%ecx
193: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
197: 83 c2 01 add $0x1,%edx
19a: 84 db test %bl,%bl
19c: 88 5a ff mov %bl,-0x1(%edx)
19f: 75 ef jne 190 <strcpy+0x10>
;
return os;
}
1a1: 5b pop %ebx
1a2: 5d pop %ebp
1a3: c3 ret
1a4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1aa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000001b0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
1b0: 55 push %ebp
1b1: 89 e5 mov %esp,%ebp
1b3: 56 push %esi
1b4: 53 push %ebx
1b5: 8b 55 08 mov 0x8(%ebp),%edx
1b8: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
1bb: 0f b6 02 movzbl (%edx),%eax
1be: 0f b6 19 movzbl (%ecx),%ebx
1c1: 84 c0 test %al,%al
1c3: 75 1e jne 1e3 <strcmp+0x33>
1c5: eb 29 jmp 1f0 <strcmp+0x40>
1c7: 89 f6 mov %esi,%esi
1c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
1d0: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
1d3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
1d6: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
1d9: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
1dd: 84 c0 test %al,%al
1df: 74 0f je 1f0 <strcmp+0x40>
1e1: 89 f1 mov %esi,%ecx
1e3: 38 d8 cmp %bl,%al
1e5: 74 e9 je 1d0 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
1e7: 29 d8 sub %ebx,%eax
}
1e9: 5b pop %ebx
1ea: 5e pop %esi
1eb: 5d pop %ebp
1ec: c3 ret
1ed: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
1f0: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
1f2: 29 d8 sub %ebx,%eax
}
1f4: 5b pop %ebx
1f5: 5e pop %esi
1f6: 5d pop %ebp
1f7: c3 ret
1f8: 90 nop
1f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000200 <strlen>:
uint
strlen(char *s)
{
200: 55 push %ebp
201: 89 e5 mov %esp,%ebp
203: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
206: 80 39 00 cmpb $0x0,(%ecx)
209: 74 12 je 21d <strlen+0x1d>
20b: 31 d2 xor %edx,%edx
20d: 8d 76 00 lea 0x0(%esi),%esi
210: 83 c2 01 add $0x1,%edx
213: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
217: 89 d0 mov %edx,%eax
219: 75 f5 jne 210 <strlen+0x10>
;
return n;
}
21b: 5d pop %ebp
21c: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
21d: 31 c0 xor %eax,%eax
;
return n;
}
21f: 5d pop %ebp
220: c3 ret
221: eb 0d jmp 230 <memset>
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 <memset>:
void*
memset(void *dst, int c, uint n)
{
230: 55 push %ebp
231: 89 e5 mov %esp,%ebp
233: 57 push %edi
234: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
237: 8b 4d 10 mov 0x10(%ebp),%ecx
23a: 8b 45 0c mov 0xc(%ebp),%eax
23d: 89 d7 mov %edx,%edi
23f: fc cld
240: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
242: 89 d0 mov %edx,%eax
244: 5f pop %edi
245: 5d pop %ebp
246: c3 ret
247: 89 f6 mov %esi,%esi
249: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000250 <strchr>:
char*
strchr(const char *s, char c)
{
250: 55 push %ebp
251: 89 e5 mov %esp,%ebp
253: 53 push %ebx
254: 8b 45 08 mov 0x8(%ebp),%eax
257: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
25a: 0f b6 10 movzbl (%eax),%edx
25d: 84 d2 test %dl,%dl
25f: 74 1d je 27e <strchr+0x2e>
if(*s == c)
261: 38 d3 cmp %dl,%bl
263: 89 d9 mov %ebx,%ecx
265: 75 0d jne 274 <strchr+0x24>
267: eb 17 jmp 280 <strchr+0x30>
269: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
270: 38 ca cmp %cl,%dl
272: 74 0c je 280 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
274: 83 c0 01 add $0x1,%eax
277: 0f b6 10 movzbl (%eax),%edx
27a: 84 d2 test %dl,%dl
27c: 75 f2 jne 270 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
27e: 31 c0 xor %eax,%eax
}
280: 5b pop %ebx
281: 5d pop %ebp
282: c3 ret
283: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
289: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000290 <gets>:
char*
gets(char *buf, int max)
{
290: 55 push %ebp
291: 89 e5 mov %esp,%ebp
293: 57 push %edi
294: 56 push %esi
295: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
296: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
298: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
29b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
29e: eb 29 jmp 2c9 <gets+0x39>
cc = read(0, &c, 1);
2a0: 83 ec 04 sub $0x4,%esp
2a3: 6a 01 push $0x1
2a5: 57 push %edi
2a6: 6a 00 push $0x0
2a8: e8 2d 01 00 00 call 3da <read>
if(cc < 1)
2ad: 83 c4 10 add $0x10,%esp
2b0: 85 c0 test %eax,%eax
2b2: 7e 1d jle 2d1 <gets+0x41>
break;
buf[i++] = c;
2b4: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
2b8: 8b 55 08 mov 0x8(%ebp),%edx
2bb: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
2bd: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
2bf: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
2c3: 74 1b je 2e0 <gets+0x50>
2c5: 3c 0d cmp $0xd,%al
2c7: 74 17 je 2e0 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
2c9: 8d 5e 01 lea 0x1(%esi),%ebx
2cc: 3b 5d 0c cmp 0xc(%ebp),%ebx
2cf: 7c cf jl 2a0 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
2d1: 8b 45 08 mov 0x8(%ebp),%eax
2d4: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
2d8: 8d 65 f4 lea -0xc(%ebp),%esp
2db: 5b pop %ebx
2dc: 5e pop %esi
2dd: 5f pop %edi
2de: 5d pop %ebp
2df: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
2e0: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
2e3: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
2e5: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
2e9: 8d 65 f4 lea -0xc(%ebp),%esp
2ec: 5b pop %ebx
2ed: 5e pop %esi
2ee: 5f pop %edi
2ef: 5d pop %ebp
2f0: c3 ret
2f1: eb 0d jmp 300 <stat>
2f3: 90 nop
2f4: 90 nop
2f5: 90 nop
2f6: 90 nop
2f7: 90 nop
2f8: 90 nop
2f9: 90 nop
2fa: 90 nop
2fb: 90 nop
2fc: 90 nop
2fd: 90 nop
2fe: 90 nop
2ff: 90 nop
00000300 <stat>:
int
stat(char *n, struct stat *st)
{
300: 55 push %ebp
301: 89 e5 mov %esp,%ebp
303: 56 push %esi
304: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
305: 83 ec 08 sub $0x8,%esp
308: 6a 00 push $0x0
30a: ff 75 08 pushl 0x8(%ebp)
30d: e8 f0 00 00 00 call 402 <open>
if(fd < 0)
312: 83 c4 10 add $0x10,%esp
315: 85 c0 test %eax,%eax
317: 78 27 js 340 <stat+0x40>
return -1;
r = fstat(fd, st);
319: 83 ec 08 sub $0x8,%esp
31c: ff 75 0c pushl 0xc(%ebp)
31f: 89 c3 mov %eax,%ebx
321: 50 push %eax
322: e8 f3 00 00 00 call 41a <fstat>
327: 89 c6 mov %eax,%esi
close(fd);
329: 89 1c 24 mov %ebx,(%esp)
32c: e8 b9 00 00 00 call 3ea <close>
return r;
331: 83 c4 10 add $0x10,%esp
334: 89 f0 mov %esi,%eax
}
336: 8d 65 f8 lea -0x8(%ebp),%esp
339: 5b pop %ebx
33a: 5e pop %esi
33b: 5d pop %ebp
33c: c3 ret
33d: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
340: b8 ff ff ff ff mov $0xffffffff,%eax
345: eb ef jmp 336 <stat+0x36>
347: 89 f6 mov %esi,%esi
349: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000350 <atoi>:
return r;
}
int
atoi(const char *s)
{
350: 55 push %ebp
351: 89 e5 mov %esp,%ebp
353: 53 push %ebx
354: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
357: 0f be 11 movsbl (%ecx),%edx
35a: 8d 42 d0 lea -0x30(%edx),%eax
35d: 3c 09 cmp $0x9,%al
35f: b8 00 00 00 00 mov $0x0,%eax
364: 77 1f ja 385 <atoi+0x35>
366: 8d 76 00 lea 0x0(%esi),%esi
369: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
370: 8d 04 80 lea (%eax,%eax,4),%eax
373: 83 c1 01 add $0x1,%ecx
376: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
37a: 0f be 11 movsbl (%ecx),%edx
37d: 8d 5a d0 lea -0x30(%edx),%ebx
380: 80 fb 09 cmp $0x9,%bl
383: 76 eb jbe 370 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
385: 5b pop %ebx
386: 5d pop %ebp
387: c3 ret
388: 90 nop
389: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000390 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
390: 55 push %ebp
391: 89 e5 mov %esp,%ebp
393: 56 push %esi
394: 53 push %ebx
395: 8b 5d 10 mov 0x10(%ebp),%ebx
398: 8b 45 08 mov 0x8(%ebp),%eax
39b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
39e: 85 db test %ebx,%ebx
3a0: 7e 14 jle 3b6 <memmove+0x26>
3a2: 31 d2 xor %edx,%edx
3a4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
3a8: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
3ac: 88 0c 10 mov %cl,(%eax,%edx,1)
3af: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
3b2: 39 da cmp %ebx,%edx
3b4: 75 f2 jne 3a8 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
3b6: 5b pop %ebx
3b7: 5e pop %esi
3b8: 5d pop %ebp
3b9: c3 ret
000003ba <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
3ba: b8 01 00 00 00 mov $0x1,%eax
3bf: cd 40 int $0x40
3c1: c3 ret
000003c2 <exit>:
SYSCALL(exit)
3c2: b8 02 00 00 00 mov $0x2,%eax
3c7: cd 40 int $0x40
3c9: c3 ret
000003ca <wait>:
SYSCALL(wait)
3ca: b8 03 00 00 00 mov $0x3,%eax
3cf: cd 40 int $0x40
3d1: c3 ret
000003d2 <pipe>:
SYSCALL(pipe)
3d2: b8 04 00 00 00 mov $0x4,%eax
3d7: cd 40 int $0x40
3d9: c3 ret
000003da <read>:
SYSCALL(read)
3da: b8 05 00 00 00 mov $0x5,%eax
3df: cd 40 int $0x40
3e1: c3 ret
000003e2 <write>:
SYSCALL(write)
3e2: b8 10 00 00 00 mov $0x10,%eax
3e7: cd 40 int $0x40
3e9: c3 ret
000003ea <close>:
SYSCALL(close)
3ea: b8 15 00 00 00 mov $0x15,%eax
3ef: cd 40 int $0x40
3f1: c3 ret
000003f2 <kill>:
SYSCALL(kill)
3f2: b8 06 00 00 00 mov $0x6,%eax
3f7: cd 40 int $0x40
3f9: c3 ret
000003fa <exec>:
SYSCALL(exec)
3fa: b8 07 00 00 00 mov $0x7,%eax
3ff: cd 40 int $0x40
401: c3 ret
00000402 <open>:
SYSCALL(open)
402: b8 0f 00 00 00 mov $0xf,%eax
407: cd 40 int $0x40
409: c3 ret
0000040a <mknod>:
SYSCALL(mknod)
40a: b8 11 00 00 00 mov $0x11,%eax
40f: cd 40 int $0x40
411: c3 ret
00000412 <unlink>:
SYSCALL(unlink)
412: b8 12 00 00 00 mov $0x12,%eax
417: cd 40 int $0x40
419: c3 ret
0000041a <fstat>:
SYSCALL(fstat)
41a: b8 08 00 00 00 mov $0x8,%eax
41f: cd 40 int $0x40
421: c3 ret
00000422 <link>:
SYSCALL(link)
422: b8 13 00 00 00 mov $0x13,%eax
427: cd 40 int $0x40
429: c3 ret
0000042a <mkdir>:
SYSCALL(mkdir)
42a: b8 14 00 00 00 mov $0x14,%eax
42f: cd 40 int $0x40
431: c3 ret
00000432 <chdir>:
SYSCALL(chdir)
432: b8 09 00 00 00 mov $0x9,%eax
437: cd 40 int $0x40
439: c3 ret
0000043a <dup>:
SYSCALL(dup)
43a: b8 0a 00 00 00 mov $0xa,%eax
43f: cd 40 int $0x40
441: c3 ret
00000442 <getpid>:
SYSCALL(getpid)
442: b8 0b 00 00 00 mov $0xb,%eax
447: cd 40 int $0x40
449: c3 ret
0000044a <sbrk>:
SYSCALL(sbrk)
44a: b8 0c 00 00 00 mov $0xc,%eax
44f: cd 40 int $0x40
451: c3 ret
00000452 <sleep>:
SYSCALL(sleep)
452: b8 0d 00 00 00 mov $0xd,%eax
457: cd 40 int $0x40
459: c3 ret
0000045a <uptime>:
SYSCALL(uptime)
45a: b8 0e 00 00 00 mov $0xe,%eax
45f: cd 40 int $0x40
461: c3 ret
00000462 <signal>:
/* assignment 2 adding code */
SYSCALL(signal)
462: b8 16 00 00 00 mov $0x16,%eax
467: cd 40 int $0x40
469: c3 ret
0000046a <sigsend>:
SYSCALL(sigsend)
46a: b8 17 00 00 00 mov $0x17,%eax
46f: cd 40 int $0x40
471: c3 ret
00000472 <sigreturn>:
SYSCALL(sigreturn)
472: b8 18 00 00 00 mov $0x18,%eax
477: cd 40 int $0x40
479: c3 ret
0000047a <alarm>:
SYSCALL(alarm)
47a: b8 19 00 00 00 mov $0x19,%eax
47f: cd 40 int $0x40
481: c3 ret
482: 66 90 xchg %ax,%ax
484: 66 90 xchg %ax,%ax
486: 66 90 xchg %ax,%ax
488: 66 90 xchg %ax,%ax
48a: 66 90 xchg %ax,%ax
48c: 66 90 xchg %ax,%ax
48e: 66 90 xchg %ax,%ax
00000490 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
490: 55 push %ebp
491: 89 e5 mov %esp,%ebp
493: 57 push %edi
494: 56 push %esi
495: 53 push %ebx
496: 89 c6 mov %eax,%esi
498: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
49b: 8b 5d 08 mov 0x8(%ebp),%ebx
49e: 85 db test %ebx,%ebx
4a0: 74 7e je 520 <printint+0x90>
4a2: 89 d0 mov %edx,%eax
4a4: c1 e8 1f shr $0x1f,%eax
4a7: 84 c0 test %al,%al
4a9: 74 75 je 520 <printint+0x90>
neg = 1;
x = -xx;
4ab: 89 d0 mov %edx,%eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
4ad: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
x = -xx;
4b4: f7 d8 neg %eax
4b6: 89 75 c0 mov %esi,-0x40(%ebp)
} else {
x = xx;
}