-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcat.asm
1722 lines (1590 loc) · 48.9 KB
/
cat.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
_cat: 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: 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
}
}
int
main(int argc, char *argv[])
{
24: 89 45 e4 mov %eax,-0x1c(%ebp)
int fd, i;
if(argc <= 1){
27: 7e 54 jle 7d <main+0x7d>
29: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
cat(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 56 03 00 00 call 392 <open>
3c: 83 c4 10 add $0x10,%esp
3f: 85 c0 test %eax,%eax
41: 89 c7 mov %eax,%edi
43: 78 24 js 69 <main+0x69>
printf(1, "cat: cannot open %s\n", argv[i]);
exit();
}
cat(fd);
45: 83 ec 0c sub $0xc,%esp
if(argc <= 1){
cat(0);
exit();
}
for(i = 1; i < argc; i++){
48: 83 c6 01 add $0x1,%esi
4b: 83 c3 04 add $0x4,%ebx
if((fd = open(argv[i], 0)) < 0){
printf(1, "cat: cannot open %s\n", argv[i]);
exit();
}
cat(fd);
4e: 50 push %eax
4f: e8 3c 00 00 00 call 90 <cat>
close(fd);
54: 89 3c 24 mov %edi,(%esp)
57: e8 1e 03 00 00 call 37a <close>
if(argc <= 1){
cat(0);
exit();
}
for(i = 1; i < argc; i++){
5c: 83 c4 10 add $0x10,%esp
5f: 39 75 e4 cmp %esi,-0x1c(%ebp)
62: 75 cc jne 30 <main+0x30>
exit();
}
cat(fd);
close(fd);
}
exit();
64: e8 e9 02 00 00 call 352 <exit>
exit();
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "cat: cannot open %s\n", argv[i]);
69: 50 push %eax
6a: ff 33 pushl (%ebx)
6c: 68 03 08 00 00 push $0x803
71: 6a 01 push $0x1
73: e8 48 04 00 00 call 4c0 <printf>
exit();
78: e8 d5 02 00 00 call 352 <exit>
main(int argc, char *argv[])
{
int fd, i;
if(argc <= 1){
cat(0);
7d: 83 ec 0c sub $0xc,%esp
80: 6a 00 push $0x0
82: e8 09 00 00 00 call 90 <cat>
exit();
87: e8 c6 02 00 00 call 352 <exit>
8c: 66 90 xchg %ax,%ax
8e: 66 90 xchg %ax,%ax
00000090 <cat>:
char buf[512];
void
cat(int fd)
{
90: 55 push %ebp
91: 89 e5 mov %esp,%ebp
93: 56 push %esi
94: 53 push %ebx
95: 8b 75 08 mov 0x8(%ebp),%esi
int n;
while((n = read(fd, buf, sizeof(buf))) > 0) {
98: eb 1d jmp b7 <cat+0x27>
9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
if (write(1, buf, n) != n) {
a0: 83 ec 04 sub $0x4,%esp
a3: 53 push %ebx
a4: 68 20 0b 00 00 push $0xb20
a9: 6a 01 push $0x1
ab: e8 c2 02 00 00 call 372 <write>
b0: 83 c4 10 add $0x10,%esp
b3: 39 c3 cmp %eax,%ebx
b5: 75 26 jne dd <cat+0x4d>
void
cat(int fd)
{
int n;
while((n = read(fd, buf, sizeof(buf))) > 0) {
b7: 83 ec 04 sub $0x4,%esp
ba: 68 00 02 00 00 push $0x200
bf: 68 20 0b 00 00 push $0xb20
c4: 56 push %esi
c5: e8 a0 02 00 00 call 36a <read>
ca: 83 c4 10 add $0x10,%esp
cd: 83 f8 00 cmp $0x0,%eax
d0: 89 c3 mov %eax,%ebx
d2: 7f cc jg a0 <cat+0x10>
if (write(1, buf, n) != n) {
printf(1, "cat: write error\n");
exit();
}
}
if(n < 0){
d4: 75 1b jne f1 <cat+0x61>
printf(1, "cat: read error\n");
exit();
}
}
d6: 8d 65 f8 lea -0x8(%ebp),%esp
d9: 5b pop %ebx
da: 5e pop %esi
db: 5d pop %ebp
dc: c3 ret
{
int n;
while((n = read(fd, buf, sizeof(buf))) > 0) {
if (write(1, buf, n) != n) {
printf(1, "cat: write error\n");
dd: 83 ec 08 sub $0x8,%esp
e0: 68 e0 07 00 00 push $0x7e0
e5: 6a 01 push $0x1
e7: e8 d4 03 00 00 call 4c0 <printf>
exit();
ec: e8 61 02 00 00 call 352 <exit>
}
}
if(n < 0){
printf(1, "cat: read error\n");
f1: 83 ec 08 sub $0x8,%esp
f4: 68 f2 07 00 00 push $0x7f2
f9: 6a 01 push $0x1
fb: e8 c0 03 00 00 call 4c0 <printf>
exit();
100: e8 4d 02 00 00 call 352 <exit>
105: 66 90 xchg %ax,%ax
107: 66 90 xchg %ax,%ax
109: 66 90 xchg %ax,%ax
10b: 66 90 xchg %ax,%ax
10d: 66 90 xchg %ax,%ax
10f: 90 nop
00000110 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
110: 55 push %ebp
111: 89 e5 mov %esp,%ebp
113: 53 push %ebx
114: 8b 45 08 mov 0x8(%ebp),%eax
117: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
11a: 89 c2 mov %eax,%edx
11c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
120: 83 c1 01 add $0x1,%ecx
123: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
127: 83 c2 01 add $0x1,%edx
12a: 84 db test %bl,%bl
12c: 88 5a ff mov %bl,-0x1(%edx)
12f: 75 ef jne 120 <strcpy+0x10>
;
return os;
}
131: 5b pop %ebx
132: 5d pop %ebp
133: c3 ret
134: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
13a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000140 <strcmp>:
int
strcmp(const char *p, const char *q)
{
140: 55 push %ebp
141: 89 e5 mov %esp,%ebp
143: 56 push %esi
144: 53 push %ebx
145: 8b 55 08 mov 0x8(%ebp),%edx
148: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
14b: 0f b6 02 movzbl (%edx),%eax
14e: 0f b6 19 movzbl (%ecx),%ebx
151: 84 c0 test %al,%al
153: 75 1e jne 173 <strcmp+0x33>
155: eb 29 jmp 180 <strcmp+0x40>
157: 89 f6 mov %esi,%esi
159: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
160: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
163: 0f b6 02 movzbl (%edx),%eax
p++, q++;
166: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
169: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
16d: 84 c0 test %al,%al
16f: 74 0f je 180 <strcmp+0x40>
171: 89 f1 mov %esi,%ecx
173: 38 d8 cmp %bl,%al
175: 74 e9 je 160 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
177: 29 d8 sub %ebx,%eax
}
179: 5b pop %ebx
17a: 5e pop %esi
17b: 5d pop %ebp
17c: c3 ret
17d: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
180: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
182: 29 d8 sub %ebx,%eax
}
184: 5b pop %ebx
185: 5e pop %esi
186: 5d pop %ebp
187: c3 ret
188: 90 nop
189: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000190 <strlen>:
uint
strlen(char *s)
{
190: 55 push %ebp
191: 89 e5 mov %esp,%ebp
193: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
196: 80 39 00 cmpb $0x0,(%ecx)
199: 74 12 je 1ad <strlen+0x1d>
19b: 31 d2 xor %edx,%edx
19d: 8d 76 00 lea 0x0(%esi),%esi
1a0: 83 c2 01 add $0x1,%edx
1a3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
1a7: 89 d0 mov %edx,%eax
1a9: 75 f5 jne 1a0 <strlen+0x10>
;
return n;
}
1ab: 5d pop %ebp
1ac: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
1ad: 31 c0 xor %eax,%eax
;
return n;
}
1af: 5d pop %ebp
1b0: c3 ret
1b1: eb 0d jmp 1c0 <memset>
1b3: 90 nop
1b4: 90 nop
1b5: 90 nop
1b6: 90 nop
1b7: 90 nop
1b8: 90 nop
1b9: 90 nop
1ba: 90 nop
1bb: 90 nop
1bc: 90 nop
1bd: 90 nop
1be: 90 nop
1bf: 90 nop
000001c0 <memset>:
void*
memset(void *dst, int c, uint n)
{
1c0: 55 push %ebp
1c1: 89 e5 mov %esp,%ebp
1c3: 57 push %edi
1c4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
1c7: 8b 4d 10 mov 0x10(%ebp),%ecx
1ca: 8b 45 0c mov 0xc(%ebp),%eax
1cd: 89 d7 mov %edx,%edi
1cf: fc cld
1d0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
1d2: 89 d0 mov %edx,%eax
1d4: 5f pop %edi
1d5: 5d pop %ebp
1d6: c3 ret
1d7: 89 f6 mov %esi,%esi
1d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000001e0 <strchr>:
char*
strchr(const char *s, char c)
{
1e0: 55 push %ebp
1e1: 89 e5 mov %esp,%ebp
1e3: 53 push %ebx
1e4: 8b 45 08 mov 0x8(%ebp),%eax
1e7: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
1ea: 0f b6 10 movzbl (%eax),%edx
1ed: 84 d2 test %dl,%dl
1ef: 74 1d je 20e <strchr+0x2e>
if(*s == c)
1f1: 38 d3 cmp %dl,%bl
1f3: 89 d9 mov %ebx,%ecx
1f5: 75 0d jne 204 <strchr+0x24>
1f7: eb 17 jmp 210 <strchr+0x30>
1f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
200: 38 ca cmp %cl,%dl
202: 74 0c je 210 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
204: 83 c0 01 add $0x1,%eax
207: 0f b6 10 movzbl (%eax),%edx
20a: 84 d2 test %dl,%dl
20c: 75 f2 jne 200 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
20e: 31 c0 xor %eax,%eax
}
210: 5b pop %ebx
211: 5d pop %ebp
212: c3 ret
213: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
219: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000220 <gets>:
char*
gets(char *buf, int max)
{
220: 55 push %ebp
221: 89 e5 mov %esp,%ebp
223: 57 push %edi
224: 56 push %esi
225: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
226: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
228: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
22b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
22e: eb 29 jmp 259 <gets+0x39>
cc = read(0, &c, 1);
230: 83 ec 04 sub $0x4,%esp
233: 6a 01 push $0x1
235: 57 push %edi
236: 6a 00 push $0x0
238: e8 2d 01 00 00 call 36a <read>
if(cc < 1)
23d: 83 c4 10 add $0x10,%esp
240: 85 c0 test %eax,%eax
242: 7e 1d jle 261 <gets+0x41>
break;
buf[i++] = c;
244: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
248: 8b 55 08 mov 0x8(%ebp),%edx
24b: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
24d: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
24f: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
253: 74 1b je 270 <gets+0x50>
255: 3c 0d cmp $0xd,%al
257: 74 17 je 270 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
259: 8d 5e 01 lea 0x1(%esi),%ebx
25c: 3b 5d 0c cmp 0xc(%ebp),%ebx
25f: 7c cf jl 230 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
261: 8b 45 08 mov 0x8(%ebp),%eax
264: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
268: 8d 65 f4 lea -0xc(%ebp),%esp
26b: 5b pop %ebx
26c: 5e pop %esi
26d: 5f pop %edi
26e: 5d pop %ebp
26f: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
270: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
273: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
275: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
279: 8d 65 f4 lea -0xc(%ebp),%esp
27c: 5b pop %ebx
27d: 5e pop %esi
27e: 5f pop %edi
27f: 5d pop %ebp
280: c3 ret
281: eb 0d jmp 290 <stat>
283: 90 nop
284: 90 nop
285: 90 nop
286: 90 nop
287: 90 nop
288: 90 nop
289: 90 nop
28a: 90 nop
28b: 90 nop
28c: 90 nop
28d: 90 nop
28e: 90 nop
28f: 90 nop
00000290 <stat>:
int
stat(char *n, struct stat *st)
{
290: 55 push %ebp
291: 89 e5 mov %esp,%ebp
293: 56 push %esi
294: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
295: 83 ec 08 sub $0x8,%esp
298: 6a 00 push $0x0
29a: ff 75 08 pushl 0x8(%ebp)
29d: e8 f0 00 00 00 call 392 <open>
if(fd < 0)
2a2: 83 c4 10 add $0x10,%esp
2a5: 85 c0 test %eax,%eax
2a7: 78 27 js 2d0 <stat+0x40>
return -1;
r = fstat(fd, st);
2a9: 83 ec 08 sub $0x8,%esp
2ac: ff 75 0c pushl 0xc(%ebp)
2af: 89 c3 mov %eax,%ebx
2b1: 50 push %eax
2b2: e8 f3 00 00 00 call 3aa <fstat>
close(fd);
2b7: 89 1c 24 mov %ebx,(%esp)
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
r = fstat(fd, st);
2ba: 89 c6 mov %eax,%esi
close(fd);
2bc: e8 b9 00 00 00 call 37a <close>
return r;
2c1: 83 c4 10 add $0x10,%esp
}
2c4: 8d 65 f8 lea -0x8(%ebp),%esp
2c7: 89 f0 mov %esi,%eax
2c9: 5b pop %ebx
2ca: 5e pop %esi
2cb: 5d pop %ebp
2cc: c3 ret
2cd: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
2d0: be ff ff ff ff mov $0xffffffff,%esi
2d5: eb ed jmp 2c4 <stat+0x34>
2d7: 89 f6 mov %esi,%esi
2d9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000002e0 <atoi>:
return r;
}
int
atoi(const char *s)
{
2e0: 55 push %ebp
2e1: 89 e5 mov %esp,%ebp
2e3: 53 push %ebx
2e4: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
2e7: 0f be 11 movsbl (%ecx),%edx
2ea: 8d 42 d0 lea -0x30(%edx),%eax
2ed: 3c 09 cmp $0x9,%al
2ef: b8 00 00 00 00 mov $0x0,%eax
2f4: 77 1f ja 315 <atoi+0x35>
2f6: 8d 76 00 lea 0x0(%esi),%esi
2f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
300: 8d 04 80 lea (%eax,%eax,4),%eax
303: 83 c1 01 add $0x1,%ecx
306: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
30a: 0f be 11 movsbl (%ecx),%edx
30d: 8d 5a d0 lea -0x30(%edx),%ebx
310: 80 fb 09 cmp $0x9,%bl
313: 76 eb jbe 300 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
315: 5b pop %ebx
316: 5d pop %ebp
317: c3 ret
318: 90 nop
319: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000320 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
320: 55 push %ebp
321: 89 e5 mov %esp,%ebp
323: 56 push %esi
324: 53 push %ebx
325: 8b 5d 10 mov 0x10(%ebp),%ebx
328: 8b 45 08 mov 0x8(%ebp),%eax
32b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
32e: 85 db test %ebx,%ebx
330: 7e 14 jle 346 <memmove+0x26>
332: 31 d2 xor %edx,%edx
334: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
338: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
33c: 88 0c 10 mov %cl,(%eax,%edx,1)
33f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
342: 39 da cmp %ebx,%edx
344: 75 f2 jne 338 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
346: 5b pop %ebx
347: 5e pop %esi
348: 5d pop %ebp
349: c3 ret
0000034a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
34a: b8 01 00 00 00 mov $0x1,%eax
34f: cd 40 int $0x40
351: c3 ret
00000352 <exit>:
SYSCALL(exit)
352: b8 02 00 00 00 mov $0x2,%eax
357: cd 40 int $0x40
359: c3 ret
0000035a <wait>:
SYSCALL(wait)
35a: b8 03 00 00 00 mov $0x3,%eax
35f: cd 40 int $0x40
361: c3 ret
00000362 <pipe>:
SYSCALL(pipe)
362: b8 04 00 00 00 mov $0x4,%eax
367: cd 40 int $0x40
369: c3 ret
0000036a <read>:
SYSCALL(read)
36a: b8 05 00 00 00 mov $0x5,%eax
36f: cd 40 int $0x40
371: c3 ret
00000372 <write>:
SYSCALL(write)
372: b8 10 00 00 00 mov $0x10,%eax
377: cd 40 int $0x40
379: c3 ret
0000037a <close>:
SYSCALL(close)
37a: b8 15 00 00 00 mov $0x15,%eax
37f: cd 40 int $0x40
381: c3 ret
00000382 <kill>:
SYSCALL(kill)
382: b8 06 00 00 00 mov $0x6,%eax
387: cd 40 int $0x40
389: c3 ret
0000038a <exec>:
SYSCALL(exec)
38a: b8 07 00 00 00 mov $0x7,%eax
38f: cd 40 int $0x40
391: c3 ret
00000392 <open>:
SYSCALL(open)
392: b8 0f 00 00 00 mov $0xf,%eax
397: cd 40 int $0x40
399: c3 ret
0000039a <mknod>:
SYSCALL(mknod)
39a: b8 11 00 00 00 mov $0x11,%eax
39f: cd 40 int $0x40
3a1: c3 ret
000003a2 <unlink>:
SYSCALL(unlink)
3a2: b8 12 00 00 00 mov $0x12,%eax
3a7: cd 40 int $0x40
3a9: c3 ret
000003aa <fstat>:
SYSCALL(fstat)
3aa: b8 08 00 00 00 mov $0x8,%eax
3af: cd 40 int $0x40
3b1: c3 ret
000003b2 <link>:
SYSCALL(link)
3b2: b8 13 00 00 00 mov $0x13,%eax
3b7: cd 40 int $0x40
3b9: c3 ret
000003ba <mkdir>:
SYSCALL(mkdir)
3ba: b8 14 00 00 00 mov $0x14,%eax
3bf: cd 40 int $0x40
3c1: c3 ret
000003c2 <chdir>:
SYSCALL(chdir)
3c2: b8 09 00 00 00 mov $0x9,%eax
3c7: cd 40 int $0x40
3c9: c3 ret
000003ca <dup>:
SYSCALL(dup)
3ca: b8 0a 00 00 00 mov $0xa,%eax
3cf: cd 40 int $0x40
3d1: c3 ret
000003d2 <getpid>:
SYSCALL(getpid)
3d2: b8 0b 00 00 00 mov $0xb,%eax
3d7: cd 40 int $0x40
3d9: c3 ret
000003da <getppid>:
SYSCALL(getppid)
3da: b8 19 00 00 00 mov $0x19,%eax
3df: cd 40 int $0x40
3e1: c3 ret
000003e2 <getAllPids>:
SYSCALL(getAllPids)
3e2: b8 17 00 00 00 mov $0x17,%eax
3e7: cd 40 int $0x40
3e9: c3 ret
000003ea <shutdown>:
SYSCALL(shutdown)
3ea: b8 18 00 00 00 mov $0x18,%eax
3ef: cd 40 int $0x40
3f1: c3 ret
000003f2 <sbrk>:
SYSCALL(sbrk)
3f2: b8 0c 00 00 00 mov $0xc,%eax
3f7: cd 40 int $0x40
3f9: c3 ret
000003fa <sleep>:
SYSCALL(sleep)
3fa: b8 0d 00 00 00 mov $0xd,%eax
3ff: cd 40 int $0x40
401: c3 ret
00000402 <uptime>:
SYSCALL(uptime)
402: b8 0e 00 00 00 mov $0xe,%eax
407: cd 40 int $0x40
409: c3 ret
0000040a <cps>:
SYSCALL(cps)
40a: b8 16 00 00 00 mov $0x16,%eax
40f: cd 40 int $0x40
411: c3 ret
412: 66 90 xchg %ax,%ax
414: 66 90 xchg %ax,%ax
416: 66 90 xchg %ax,%ax
418: 66 90 xchg %ax,%ax
41a: 66 90 xchg %ax,%ax
41c: 66 90 xchg %ax,%ax
41e: 66 90 xchg %ax,%ax
00000420 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
420: 55 push %ebp
421: 89 e5 mov %esp,%ebp
423: 57 push %edi
424: 56 push %esi
425: 53 push %ebx
426: 89 c6 mov %eax,%esi
428: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
42b: 8b 5d 08 mov 0x8(%ebp),%ebx
42e: 85 db test %ebx,%ebx
430: 74 7e je 4b0 <printint+0x90>
432: 89 d0 mov %edx,%eax
434: c1 e8 1f shr $0x1f,%eax
437: 84 c0 test %al,%al
439: 74 75 je 4b0 <printint+0x90>
neg = 1;
x = -xx;
43b: 89 d0 mov %edx,%eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
43d: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
x = -xx;
444: f7 d8 neg %eax
446: 89 75 c0 mov %esi,-0x40(%ebp)
} else {
x = xx;
}
i = 0;
449: 31 ff xor %edi,%edi
44b: 8d 5d d7 lea -0x29(%ebp),%ebx
44e: 89 ce mov %ecx,%esi
450: eb 08 jmp 45a <printint+0x3a>
452: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
458: 89 cf mov %ecx,%edi
45a: 31 d2 xor %edx,%edx
45c: 8d 4f 01 lea 0x1(%edi),%ecx
45f: f7 f6 div %esi
461: 0f b6 92 20 08 00 00 movzbl 0x820(%edx),%edx
}while((x /= base) != 0);
468: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
46a: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
46d: 75 e9 jne 458 <printint+0x38>
if(neg)
46f: 8b 45 c4 mov -0x3c(%ebp),%eax
472: 8b 75 c0 mov -0x40(%ebp),%esi
475: 85 c0 test %eax,%eax
477: 74 08 je 481 <printint+0x61>
buf[i++] = '-';
479: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1)
47e: 8d 4f 02 lea 0x2(%edi),%ecx
while(--i >= 0)
481: 8d 79 ff lea -0x1(%ecx),%edi
484: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
488: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
48d: 83 ec 04 sub $0x4,%esp
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
490: 83 ef 01 sub $0x1,%edi
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
493: 6a 01 push $0x1
495: 53 push %ebx
496: 56 push %esi
497: 88 45 d7 mov %al,-0x29(%ebp)
49a: e8 d3 fe ff ff call 372 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
49f: 83 c4 10 add $0x10,%esp
4a2: 83 ff ff cmp $0xffffffff,%edi
4a5: 75 e1 jne 488 <printint+0x68>
putc(fd, buf[i]);
}
4a7: 8d 65 f4 lea -0xc(%ebp),%esp
4aa: 5b pop %ebx
4ab: 5e pop %esi
4ac: 5f pop %edi
4ad: 5d pop %ebp
4ae: c3 ret
4af: 90 nop
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
} else {
x = xx;
4b0: 89 d0 mov %edx,%eax