/
cat.asm
1290 lines (1214 loc) · 42.5 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
{
24: 89 45 e4 mov %eax,-0x1c(%ebp)
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 66 03 00 00 call 3a2 <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
for(i = 1; i < argc; i++){
48: 83 c6 01 add $0x1,%esi
4b: 83 c3 04 add $0x4,%ebx
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 2e 03 00 00 call 38a <close>
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();
64: e8 f9 02 00 00 call 362 <exit>
printf(1, "cat: cannot open %s\n", argv[i]);
69: 50 push %eax
6a: ff 33 pushl (%ebx)
6c: 68 5b 08 00 00 push $0x85b
71: 6a 01 push $0x1
73: e8 68 04 00 00 call 4e0 <printf>
exit();
78: e8 e5 02 00 00 call 362 <exit>
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 d6 02 00 00 call 362 <exit>
8c: 66 90 xchg %ax,%ax
8e: 66 90 xchg %ax,%ax
00000090 <cat>:
{
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
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 80 0b 00 00 push $0xb80
a9: 6a 01 push $0x1
ab: e8 d2 02 00 00 call 382 <write>
b0: 83 c4 10 add $0x10,%esp
b3: 39 d8 cmp %ebx,%eax
b5: 75 26 jne dd <cat+0x4d>
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 80 0b 00 00 push $0xb80
c4: 56 push %esi
c5: e8 b0 02 00 00 call 37a <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(n < 0){
d4: 75 1b jne f1 <cat+0x61>
}
d6: 8d 65 f8 lea -0x8(%ebp),%esp
d9: 5b pop %ebx
da: 5e pop %esi
db: 5d pop %ebp
dc: c3 ret
printf(1, "cat: write error\n");
dd: 83 ec 08 sub $0x8,%esp
e0: 68 38 08 00 00 push $0x838
e5: 6a 01 push $0x1
e7: e8 f4 03 00 00 call 4e0 <printf>
exit();
ec: e8 71 02 00 00 call 362 <exit>
printf(1, "cat: read error\n");
f1: 50 push %eax
f2: 50 push %eax
f3: 68 4a 08 00 00 push $0x84a
f8: 6a 01 push $0x1
fa: e8 e1 03 00 00 call 4e0 <printf>
exit();
ff: e8 5e 02 00 00 call 362 <exit>
104: 66 90 xchg %ax,%ax
106: 66 90 xchg %ax,%ax
108: 66 90 xchg %ax,%ax
10a: 66 90 xchg %ax,%ax
10c: 66 90 xchg %ax,%ax
10e: 66 90 xchg %ax,%ax
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: 53 push %ebx
144: 8b 55 08 mov 0x8(%ebp),%edx
147: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
14a: 0f b6 02 movzbl (%edx),%eax
14d: 0f b6 19 movzbl (%ecx),%ebx
150: 84 c0 test %al,%al
152: 75 1c jne 170 <strcmp+0x30>
154: eb 2a jmp 180 <strcmp+0x40>
156: 8d 76 00 lea 0x0(%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
while(*p && *p == *q)
163: 0f b6 02 movzbl (%edx),%eax
p++, q++;
166: 83 c1 01 add $0x1,%ecx
169: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
16c: 84 c0 test %al,%al
16e: 74 10 je 180 <strcmp+0x40>
170: 38 d8 cmp %bl,%al
172: 74 ec je 160 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
174: 29 d8 sub %ebx,%eax
}
176: 5b pop %ebx
177: 5d pop %ebp
178: c3 ret
179: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
180: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
182: 29 d8 sub %ebx,%eax
}
184: 5b pop %ebx
185: 5d pop %ebp
186: c3 ret
187: 89 f6 mov %esi,%esi
189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
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 15 je 1b0 <strlen+0x20>
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
1ad: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
1b0: 31 c0 xor %eax,%eax
}
1b2: 5d pop %ebp
1b3: c3 ret
1b4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1ba: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
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>
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>
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
228: 89 f3 mov %esi,%ebx
{
22a: 83 ec 1c sub $0x1c,%esp
22d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
230: eb 2f jmp 261 <gets+0x41>
232: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
238: 8d 45 e7 lea -0x19(%ebp),%eax
23b: 83 ec 04 sub $0x4,%esp
23e: 6a 01 push $0x1
240: 50 push %eax
241: 6a 00 push $0x0
243: e8 32 01 00 00 call 37a <read>
if(cc < 1)
248: 83 c4 10 add $0x10,%esp
24b: 85 c0 test %eax,%eax
24d: 7e 1c jle 26b <gets+0x4b>
break;
buf[i++] = c;
24f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
253: 83 c7 01 add $0x1,%edi
256: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
259: 3c 0a cmp $0xa,%al
25b: 74 23 je 280 <gets+0x60>
25d: 3c 0d cmp $0xd,%al
25f: 74 1f je 280 <gets+0x60>
for(i=0; i+1 < max; ){
261: 83 c3 01 add $0x1,%ebx
264: 3b 5d 0c cmp 0xc(%ebp),%ebx
267: 89 fe mov %edi,%esi
269: 7c cd jl 238 <gets+0x18>
26b: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
26d: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
270: c6 03 00 movb $0x0,(%ebx)
}
273: 8d 65 f4 lea -0xc(%ebp),%esp
276: 5b pop %ebx
277: 5e pop %esi
278: 5f pop %edi
279: 5d pop %ebp
27a: c3 ret
27b: 90 nop
27c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
280: 8b 75 08 mov 0x8(%ebp),%esi
283: 8b 45 08 mov 0x8(%ebp),%eax
286: 01 de add %ebx,%esi
288: 89 f3 mov %esi,%ebx
buf[i] = '\0';
28a: c6 03 00 movb $0x0,(%ebx)
}
28d: 8d 65 f4 lea -0xc(%ebp),%esp
290: 5b pop %ebx
291: 5e pop %esi
292: 5f pop %edi
293: 5d pop %ebp
294: c3 ret
295: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
299: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000002a0 <stat>:
int
stat(char *n, struct stat *st)
{
2a0: 55 push %ebp
2a1: 89 e5 mov %esp,%ebp
2a3: 56 push %esi
2a4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
2a5: 83 ec 08 sub $0x8,%esp
2a8: 6a 00 push $0x0
2aa: ff 75 08 pushl 0x8(%ebp)
2ad: e8 f0 00 00 00 call 3a2 <open>
if(fd < 0)
2b2: 83 c4 10 add $0x10,%esp
2b5: 85 c0 test %eax,%eax
2b7: 78 27 js 2e0 <stat+0x40>
return -1;
r = fstat(fd, st);
2b9: 83 ec 08 sub $0x8,%esp
2bc: ff 75 0c pushl 0xc(%ebp)
2bf: 89 c3 mov %eax,%ebx
2c1: 50 push %eax
2c2: e8 f3 00 00 00 call 3ba <fstat>
close(fd);
2c7: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
2ca: 89 c6 mov %eax,%esi
close(fd);
2cc: e8 b9 00 00 00 call 38a <close>
return r;
2d1: 83 c4 10 add $0x10,%esp
}
2d4: 8d 65 f8 lea -0x8(%ebp),%esp
2d7: 89 f0 mov %esi,%eax
2d9: 5b pop %ebx
2da: 5e pop %esi
2db: 5d pop %ebp
2dc: c3 ret
2dd: 8d 76 00 lea 0x0(%esi),%esi
return -1;
2e0: be ff ff ff ff mov $0xffffffff,%esi
2e5: eb ed jmp 2d4 <stat+0x34>
2e7: 89 f6 mov %esi,%esi
2e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000002f0 <atoi>:
int
atoi(const char *s)
{
2f0: 55 push %ebp
2f1: 89 e5 mov %esp,%ebp
2f3: 53 push %ebx
2f4: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
2f7: 0f be 11 movsbl (%ecx),%edx
2fa: 8d 42 d0 lea -0x30(%edx),%eax
2fd: 3c 09 cmp $0x9,%al
n = 0;
2ff: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
304: 77 1f ja 325 <atoi+0x35>
306: 8d 76 00 lea 0x0(%esi),%esi
309: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
310: 8d 04 80 lea (%eax,%eax,4),%eax
313: 83 c1 01 add $0x1,%ecx
316: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
31a: 0f be 11 movsbl (%ecx),%edx
31d: 8d 5a d0 lea -0x30(%edx),%ebx
320: 80 fb 09 cmp $0x9,%bl
323: 76 eb jbe 310 <atoi+0x20>
return n;
}
325: 5b pop %ebx
326: 5d pop %ebp
327: c3 ret
328: 90 nop
329: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000330 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
330: 55 push %ebp
331: 89 e5 mov %esp,%ebp
333: 56 push %esi
334: 53 push %ebx
335: 8b 5d 10 mov 0x10(%ebp),%ebx
338: 8b 45 08 mov 0x8(%ebp),%eax
33b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
33e: 85 db test %ebx,%ebx
340: 7e 14 jle 356 <memmove+0x26>
342: 31 d2 xor %edx,%edx
344: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
348: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
34c: 88 0c 10 mov %cl,(%eax,%edx,1)
34f: 83 c2 01 add $0x1,%edx
while(n-- > 0)
352: 39 d3 cmp %edx,%ebx
354: 75 f2 jne 348 <memmove+0x18>
return vdst;
}
356: 5b pop %ebx
357: 5e pop %esi
358: 5d pop %ebp
359: c3 ret
0000035a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
35a: b8 01 00 00 00 mov $0x1,%eax
35f: cd 40 int $0x40
361: c3 ret
00000362 <exit>:
SYSCALL(exit)
362: b8 02 00 00 00 mov $0x2,%eax
367: cd 40 int $0x40
369: c3 ret
0000036a <wait>:
SYSCALL(wait)
36a: b8 03 00 00 00 mov $0x3,%eax
36f: cd 40 int $0x40
371: c3 ret
00000372 <pipe>:
SYSCALL(pipe)
372: b8 04 00 00 00 mov $0x4,%eax
377: cd 40 int $0x40
379: c3 ret
0000037a <read>:
SYSCALL(read)
37a: b8 05 00 00 00 mov $0x5,%eax
37f: cd 40 int $0x40
381: c3 ret
00000382 <write>:
SYSCALL(write)
382: b8 10 00 00 00 mov $0x10,%eax
387: cd 40 int $0x40
389: c3 ret
0000038a <close>:
SYSCALL(close)
38a: b8 15 00 00 00 mov $0x15,%eax
38f: cd 40 int $0x40
391: c3 ret
00000392 <kill>:
SYSCALL(kill)
392: b8 06 00 00 00 mov $0x6,%eax
397: cd 40 int $0x40
399: c3 ret
0000039a <exec>:
SYSCALL(exec)
39a: b8 07 00 00 00 mov $0x7,%eax
39f: cd 40 int $0x40
3a1: c3 ret
000003a2 <open>:
SYSCALL(open)
3a2: b8 0f 00 00 00 mov $0xf,%eax
3a7: cd 40 int $0x40
3a9: c3 ret
000003aa <mknod>:
SYSCALL(mknod)
3aa: b8 11 00 00 00 mov $0x11,%eax
3af: cd 40 int $0x40
3b1: c3 ret
000003b2 <unlink>:
SYSCALL(unlink)
3b2: b8 12 00 00 00 mov $0x12,%eax
3b7: cd 40 int $0x40
3b9: c3 ret
000003ba <fstat>:
SYSCALL(fstat)
3ba: b8 08 00 00 00 mov $0x8,%eax
3bf: cd 40 int $0x40
3c1: c3 ret
000003c2 <link>:
SYSCALL(link)
3c2: b8 13 00 00 00 mov $0x13,%eax
3c7: cd 40 int $0x40
3c9: c3 ret
000003ca <mkdir>:
SYSCALL(mkdir)
3ca: b8 14 00 00 00 mov $0x14,%eax
3cf: cd 40 int $0x40
3d1: c3 ret
000003d2 <chdir>:
SYSCALL(chdir)
3d2: b8 09 00 00 00 mov $0x9,%eax
3d7: cd 40 int $0x40
3d9: c3 ret
000003da <dup>:
SYSCALL(dup)
3da: b8 0a 00 00 00 mov $0xa,%eax
3df: cd 40 int $0x40
3e1: c3 ret
000003e2 <getpid>:
SYSCALL(getpid)
3e2: b8 0b 00 00 00 mov $0xb,%eax
3e7: cd 40 int $0x40
3e9: c3 ret
000003ea <sbrk>:
SYSCALL(sbrk)
3ea: b8 0c 00 00 00 mov $0xc,%eax
3ef: cd 40 int $0x40
3f1: c3 ret
000003f2 <sleep>:
SYSCALL(sleep)
3f2: b8 0d 00 00 00 mov $0xd,%eax
3f7: cd 40 int $0x40
3f9: c3 ret
000003fa <uptime>:
SYSCALL(uptime)
3fa: b8 0e 00 00 00 mov $0xe,%eax
3ff: cd 40 int $0x40
401: c3 ret
00000402 <cps>:
SYSCALL(cps)
402: b8 16 00 00 00 mov $0x16,%eax
407: cd 40 int $0x40
409: c3 ret
0000040a <chpr>:
SYSCALL(chpr)
40a: b8 17 00 00 00 mov $0x17,%eax
40f: cd 40 int $0x40
411: c3 ret
00000412 <setTickets>:
SYSCALL(setTickets)
412: b8 18 00 00 00 mov $0x18,%eax
417: cd 40 int $0x40
419: c3 ret
0000041a <thread_create>:
SYSCALL(thread_create)
41a: b8 19 00 00 00 mov $0x19,%eax
41f: cd 40 int $0x40
421: c3 ret
00000422 <thread_exit>:
SYSCALL(thread_exit)
422: b8 1a 00 00 00 mov $0x1a,%eax
427: cd 40 int $0x40
429: c3 ret
0000042a <thread_join>:
SYSCALL(thread_join)
42a: b8 1b 00 00 00 mov $0x1b,%eax
42f: cd 40 int $0x40
431: c3 ret
00000432 <gettid>:
SYSCALL(gettid)
432: b8 1c 00 00 00 mov $0x1c,%eax
437: cd 40 int $0x40
439: c3 ret
43a: 66 90 xchg %ax,%ax
43c: 66 90 xchg %ax,%ax
43e: 66 90 xchg %ax,%ax
00000440 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
440: 55 push %ebp
441: 89 e5 mov %esp,%ebp
443: 57 push %edi
444: 56 push %esi
445: 53 push %ebx
446: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
449: 85 d2 test %edx,%edx
{
44b: 89 45 c0 mov %eax,-0x40(%ebp)
neg = 1;
x = -xx;
44e: 89 d0 mov %edx,%eax
if(sgn && xx < 0){
450: 79 76 jns 4c8 <printint+0x88>
452: f6 45 08 01 testb $0x1,0x8(%ebp)
456: 74 70 je 4c8 <printint+0x88>
x = -xx;
458: f7 d8 neg %eax
neg = 1;
45a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
} else {
x = xx;
}
i = 0;
461: 31 f6 xor %esi,%esi
463: 8d 5d d7 lea -0x29(%ebp),%ebx
466: eb 0a jmp 472 <printint+0x32>
468: 90 nop
469: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
do{
buf[i++] = digits[x % base];
470: 89 fe mov %edi,%esi
472: 31 d2 xor %edx,%edx
474: 8d 7e 01 lea 0x1(%esi),%edi
477: f7 f1 div %ecx
479: 0f b6 92 78 08 00 00 movzbl 0x878(%edx),%edx
}while((x /= base) != 0);
480: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
482: 88 14 3b mov %dl,(%ebx,%edi,1)
}while((x /= base) != 0);
485: 75 e9 jne 470 <printint+0x30>
if(neg)
487: 8b 45 c4 mov -0x3c(%ebp),%eax
48a: 85 c0 test %eax,%eax
48c: 74 08 je 496 <printint+0x56>
buf[i++] = '-';
48e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
493: 8d 7e 02 lea 0x2(%esi),%edi
496: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi
49a: 8b 7d c0 mov -0x40(%ebp),%edi
49d: 8d 76 00 lea 0x0(%esi),%esi
4a0: 0f b6 06 movzbl (%esi),%eax
write(fd, &c, 1);
4a3: 83 ec 04 sub $0x4,%esp
4a6: 83 ee 01 sub $0x1,%esi
4a9: 6a 01 push $0x1
4ab: 53 push %ebx
4ac: 57 push %edi
4ad: 88 45 d7 mov %al,-0x29(%ebp)
4b0: e8 cd fe ff ff call 382 <write>
while(--i >= 0)
4b5: 83 c4 10 add $0x10,%esp
4b8: 39 de cmp %ebx,%esi
4ba: 75 e4 jne 4a0 <printint+0x60>
putc(fd, buf[i]);
}
4bc: 8d 65 f4 lea -0xc(%ebp),%esp
4bf: 5b pop %ebx
4c0: 5e pop %esi
4c1: 5f pop %edi
4c2: 5d pop %ebp
4c3: c3 ret
4c4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
4c8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
4cf: eb 90 jmp 461 <printint+0x21>
4d1: eb 0d jmp 4e0 <printf>
4d3: 90 nop
4d4: 90 nop
4d5: 90 nop
4d6: 90 nop
4d7: 90 nop
4d8: 90 nop
4d9: 90 nop
4da: 90 nop
4db: 90 nop
4dc: 90 nop
4dd: 90 nop
4de: 90 nop
4df: 90 nop
000004e0 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
4e0: 55 push %ebp
4e1: 89 e5 mov %esp,%ebp
4e3: 57 push %edi
4e4: 56 push %esi
4e5: 53 push %ebx
4e6: 83 ec 2c sub $0x2c,%esp
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
4e9: 8b 75 0c mov 0xc(%ebp),%esi
4ec: 0f b6 1e movzbl (%esi),%ebx
4ef: 84 db test %bl,%bl
4f1: 0f 84 b3 00 00 00 je 5aa <printf+0xca>
ap = (uint*)(void*)&fmt + 1;
4f7: 8d 45 10 lea 0x10(%ebp),%eax
4fa: 83 c6 01 add $0x1,%esi
state = 0;
4fd: 31 ff xor %edi,%edi
ap = (uint*)(void*)&fmt + 1;
4ff: 89 45 d4 mov %eax,-0x2c(%ebp)
502: eb 2f jmp 533 <printf+0x53>
504: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
508: 83 f8 25 cmp $0x25,%eax
50b: 0f 84 a7 00 00 00 je 5b8 <printf+0xd8>
write(fd, &c, 1);
511: 8d 45 e2 lea -0x1e(%ebp),%eax
514: 83 ec 04 sub $0x4,%esp
517: 88 5d e2 mov %bl,-0x1e(%ebp)
51a: 6a 01 push $0x1
51c: 50 push %eax
51d: ff 75 08 pushl 0x8(%ebp)
520: e8 5d fe ff ff call 382 <write>
525: 83 c4 10 add $0x10,%esp
528: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
52b: 0f b6 5e ff movzbl -0x1(%esi),%ebx
52f: 84 db test %bl,%bl
531: 74 77 je 5aa <printf+0xca>
if(state == 0){
533: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
535: 0f be cb movsbl %bl,%ecx
538: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
53b: 74 cb je 508 <printf+0x28>
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
53d: 83 ff 25 cmp $0x25,%edi
540: 75 e6 jne 528 <printf+0x48>
if(c == 'd'){
542: 83 f8 64 cmp $0x64,%eax
545: 0f 84 05 01 00 00 je 650 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
54b: 81 e1 f7 00 00 00 and $0xf7,%ecx
551: 83 f9 70 cmp $0x70,%ecx
554: 74 72 je 5c8 <printf+0xe8>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
556: 83 f8 73 cmp $0x73,%eax
559: 0f 84 99 00 00 00 je 5f8 <printf+0x118>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
55f: 83 f8 63 cmp $0x63,%eax
562: 0f 84 08 01 00 00 je 670 <printf+0x190>
putc(fd, *ap);
ap++;
} else if(c == '%'){
568: 83 f8 25 cmp $0x25,%eax
56b: 0f 84 ef 00 00 00 je 660 <printf+0x180>
write(fd, &c, 1);
571: 8d 45 e7 lea -0x19(%ebp),%eax
574: 83 ec 04 sub $0x4,%esp
577: c6 45 e7 25 movb $0x25,-0x19(%ebp)
57b: 6a 01 push $0x1
57d: 50 push %eax
57e: ff 75 08 pushl 0x8(%ebp)
581: e8 fc fd ff ff call 382 <write>
586: 83 c4 0c add $0xc,%esp
589: 8d 45 e6 lea -0x1a(%ebp),%eax
58c: 88 5d e6 mov %bl,-0x1a(%ebp)
58f: 6a 01 push $0x1
591: 50 push %eax
592: ff 75 08 pushl 0x8(%ebp)
595: 83 c6 01 add $0x1,%esi
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
598: 31 ff xor %edi,%edi
write(fd, &c, 1);
59a: e8 e3 fd ff ff call 382 <write>
for(i = 0; fmt[i]; i++){
59f: 0f b6 5e ff movzbl -0x1(%esi),%ebx
write(fd, &c, 1);
5a3: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
5a6: 84 db test %bl,%bl
5a8: 75 89 jne 533 <printf+0x53>
}
}
}
5aa: 8d 65 f4 lea -0xc(%ebp),%esp
5ad: 5b pop %ebx
5ae: 5e pop %esi
5af: 5f pop %edi
5b0: 5d pop %ebp
5b1: c3 ret
5b2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
state = '%';
5b8: bf 25 00 00 00 mov $0x25,%edi
5bd: e9 66 ff ff ff jmp 528 <printf+0x48>
5c2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
5c8: 83 ec 0c sub $0xc,%esp
5cb: b9 10 00 00 00 mov $0x10,%ecx
5d0: 6a 00 push $0x0
5d2: 8b 7d d4 mov -0x2c(%ebp),%edi
5d5: 8b 45 08 mov 0x8(%ebp),%eax
5d8: 8b 17 mov (%edi),%edx
5da: e8 61 fe ff ff call 440 <printint>
ap++;
5df: 89 f8 mov %edi,%eax
5e1: 83 c4 10 add $0x10,%esp
state = 0;
5e4: 31 ff xor %edi,%edi
ap++;
5e6: 83 c0 04 add $0x4,%eax
5e9: 89 45 d4 mov %eax,-0x2c(%ebp)
5ec: e9 37 ff ff ff jmp 528 <printf+0x48>
5f1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
5f8: 8b 45 d4 mov -0x2c(%ebp),%eax
5fb: 8b 08 mov (%eax),%ecx
ap++;
5fd: 83 c0 04 add $0x4,%eax
600: 89 45 d4 mov %eax,-0x2c(%ebp)
if(s == 0)
603: 85 c9 test %ecx,%ecx
605: 0f 84 8e 00 00 00 je 699 <printf+0x1b9>
while(*s != 0){
60b: 0f b6 01 movzbl (%ecx),%eax
state = 0;
60e: 31 ff xor %edi,%edi
s = (char*)*ap;
610: 89 cb mov %ecx,%ebx
while(*s != 0){
612: 84 c0 test %al,%al
614: 0f 84 0e ff ff ff je 528 <printf+0x48>
61a: 89 75 d0 mov %esi,-0x30(%ebp)
61d: 89 de mov %ebx,%esi
61f: 8b 5d 08 mov 0x8(%ebp),%ebx
622: 8d 7d e3 lea -0x1d(%ebp),%edi
625: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
628: 83 ec 04 sub $0x4,%esp
s++;
62b: 83 c6 01 add $0x1,%esi
62e: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
631: 6a 01 push $0x1