-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoo.asm
1289 lines (1216 loc) · 42.8 KB
/
foo.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
_foo: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "user.h"
#include "fcntl.h"
int
main(int argc, char const *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: 83 ec 28 sub $0x28,%esp
14: 8b 19 mov (%ecx),%ebx
16: 8b 79 04 mov 0x4(%ecx),%edi
int k,n,id;
double x = 0,z,d;
if(argc <2)
19: 83 fb 01 cmp $0x1,%ebx
1c: 7f 67 jg 85 <main+0x85>
if( n < 0 || n > 20 )
n = 2;
if( argc < 3)
d = 1.0;
1e: d9 e8 fld1
n=1; //default value
20: be 01 00 00 00 mov $0x1,%esi
d = 1.0;
25: dd 5d d0 fstpl -0x30(%ebp)
n=1; //default value
28: 31 db xor %ebx,%ebx
2a: eb 16 jmp 42 <main+0x42>
2c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
id = 0;
for( k=0; k<n; k++){
id = fork();
if(id < 0)
printf(1,"%d failed in fork!\n",getpid());
else if(id > 0){ //parent
30: 0f 84 8f 00 00 00 je c5 <main+0xc5>
for( k=0; k<n; k++){
36: 83 c3 01 add $0x1,%ebx
// printf(1, "Parent %d created child %d\n",getpid(),id);
wait();
39: e8 2c 03 00 00 call 36a <wait>
for( k=0; k<n; k++){
3e: 39 f3 cmp %esi,%ebx
40: 7d 2e jge 70 <main+0x70>
id = fork();
42: e8 13 03 00 00 call 35a <fork>
if(id < 0)
47: 85 c0 test %eax,%eax
49: 79 e5 jns 30 <main+0x30>
printf(1,"%d failed in fork!\n",getpid());
4b: e8 92 03 00 00 call 3e2 <getpid>
50: 83 ec 04 sub $0x4,%esp
for( k=0; k<n; k++){
53: 83 c3 01 add $0x1,%ebx
printf(1,"%d failed in fork!\n",getpid());
56: 50 push %eax
57: 68 28 08 00 00 push $0x828
5c: 6a 01 push $0x1
5e: e8 6d 04 00 00 call 4d0 <printf>
63: 83 c4 10 add $0x10,%esp
for( k=0; k<n; k++){
66: 39 f3 cmp %esi,%ebx
68: 7c d8 jl 42 <main+0x42>
6a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
sleep(100);
break;
}
}
int wtime,rtime;
waitx(&wtime,&rtime);
70: 8d 45 e4 lea -0x1c(%ebp),%eax
73: 83 ec 08 sub $0x8,%esp
76: 50 push %eax
77: 8d 45 e0 lea -0x20(%ebp),%eax
7a: 50 push %eax
7b: e8 92 03 00 00 call 412 <waitx>
// printf(1,"wtime = %d, rtime = %d\n",wtime,rtime);
exit();
80: e8 dd 02 00 00 call 362 <exit>
n = atoi(argv[1]); //from command line
85: 83 ec 0c sub $0xc,%esp
88: ff 77 04 pushl 0x4(%edi)
8b: e8 60 02 00 00 call 2f0 <atoi>
if( n < 0 || n > 20 )
90: 83 c4 10 add $0x10,%esp
93: 83 f8 14 cmp $0x14,%eax
n = atoi(argv[1]); //from command line
96: 89 c6 mov %eax,%esi
if( n < 0 || n > 20 )
98: 76 63 jbe fd <main+0xfd>
if( argc < 3)
9a: 83 fb 02 cmp $0x2,%ebx
9d: 7e 4f jle ee <main+0xee>
n = 2;
9f: be 02 00 00 00 mov $0x2,%esi
d = atoi(argv[2]);
a4: 83 ec 0c sub $0xc,%esp
a7: ff 77 08 pushl 0x8(%edi)
aa: e8 41 02 00 00 call 2f0 <atoi>
af: 89 45 d0 mov %eax,-0x30(%ebp)
b2: 83 c4 10 add $0x10,%esp
b5: db 45 d0 fildl -0x30(%ebp)
b8: dd 5d d0 fstpl -0x30(%ebp)
for( k=0; k<n; k++){
bb: 85 f6 test %esi,%esi
bd: 0f 85 65 ff ff ff jne 28 <main+0x28>
c3: eb ab jmp 70 <main+0x70>
for( z = 0; z < 8000000.0; z += d)
c5: d9 ee fldz
c7: 89 f6 mov %esi,%esi
c9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
d0: dc 45 d0 faddl -0x30(%ebp)
d3: d9 05 3c 08 00 00 flds 0x83c
d9: df e9 fucomip %st(1),%st
db: 77 f3 ja d0 <main+0xd0>
dd: dd d8 fstp %st(0)
sleep(100);
df: 83 ec 0c sub $0xc,%esp
e2: 6a 64 push $0x64
e4: e8 09 03 00 00 call 3f2 <sleep>
break;
e9: 83 c4 10 add $0x10,%esp
ec: eb 82 jmp 70 <main+0x70>
d = 1.0;
ee: d9 e8 fld1
n = 2;
f0: be 02 00 00 00 mov $0x2,%esi
d = 1.0;
f5: dd 5d d0 fstpl -0x30(%ebp)
f8: e9 2b ff ff ff jmp 28 <main+0x28>
if( argc < 3)
fd: 83 fb 02 cmp $0x2,%ebx
100: 75 a2 jne a4 <main+0xa4>
d = 1.0;
102: d9 e8 fld1
104: dd 5d d0 fstpl -0x30(%ebp)
107: eb b2 jmp bb <main+0xbb>
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, const 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(const 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(const 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, const 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;
const char *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 <waitx>:
SYSCALL(waitx)
412: b8 18 00 00 00 mov $0x18,%eax
417: cd 40 int $0x40
419: c3 ret
0000041a <getpinfo>:
SYSCALL(getpinfo)
41a: b8 19 00 00 00 mov $0x19,%eax
41f: cd 40 int $0x40
421: c3 ret
422: 66 90 xchg %ax,%ax
424: 66 90 xchg %ax,%ax
426: 66 90 xchg %ax,%ax
428: 66 90 xchg %ax,%ax
42a: 66 90 xchg %ax,%ax
42c: 66 90 xchg %ax,%ax
42e: 66 90 xchg %ax,%ax
00000430 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
430: 55 push %ebp
431: 89 e5 mov %esp,%ebp
433: 57 push %edi
434: 56 push %esi
435: 53 push %ebx
436: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
439: 85 d2 test %edx,%edx
{
43b: 89 45 c0 mov %eax,-0x40(%ebp)
neg = 1;
x = -xx;
43e: 89 d0 mov %edx,%eax
if(sgn && xx < 0){
440: 79 76 jns 4b8 <printint+0x88>
442: f6 45 08 01 testb $0x1,0x8(%ebp)
446: 74 70 je 4b8 <printint+0x88>
x = -xx;
448: f7 d8 neg %eax
neg = 1;
44a: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
} else {
x = xx;
}
i = 0;
451: 31 f6 xor %esi,%esi
453: 8d 5d d7 lea -0x29(%ebp),%ebx
456: eb 0a jmp 462 <printint+0x32>
458: 90 nop
459: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
do{
buf[i++] = digits[x % base];
460: 89 fe mov %edi,%esi
462: 31 d2 xor %edx,%edx
464: 8d 7e 01 lea 0x1(%esi),%edi
467: f7 f1 div %ecx
469: 0f b6 92 48 08 00 00 movzbl 0x848(%edx),%edx
}while((x /= base) != 0);
470: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
472: 88 14 3b mov %dl,(%ebx,%edi,1)
}while((x /= base) != 0);
475: 75 e9 jne 460 <printint+0x30>
if(neg)
477: 8b 45 c4 mov -0x3c(%ebp),%eax
47a: 85 c0 test %eax,%eax
47c: 74 08 je 486 <printint+0x56>
buf[i++] = '-';
47e: c6 44 3d d8 2d movb $0x2d,-0x28(%ebp,%edi,1)
483: 8d 7e 02 lea 0x2(%esi),%edi
486: 8d 74 3d d7 lea -0x29(%ebp,%edi,1),%esi
48a: 8b 7d c0 mov -0x40(%ebp),%edi
48d: 8d 76 00 lea 0x0(%esi),%esi
490: 0f b6 06 movzbl (%esi),%eax
write(fd, &c, 1);
493: 83 ec 04 sub $0x4,%esp
496: 83 ee 01 sub $0x1,%esi
499: 6a 01 push $0x1
49b: 53 push %ebx
49c: 57 push %edi
49d: 88 45 d7 mov %al,-0x29(%ebp)
4a0: e8 dd fe ff ff call 382 <write>
while(--i >= 0)
4a5: 83 c4 10 add $0x10,%esp
4a8: 39 de cmp %ebx,%esi
4aa: 75 e4 jne 490 <printint+0x60>
putc(fd, buf[i]);
}
4ac: 8d 65 f4 lea -0xc(%ebp),%esp
4af: 5b pop %ebx
4b0: 5e pop %esi
4b1: 5f pop %edi
4b2: 5d pop %ebp
4b3: c3 ret
4b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
4b8: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
4bf: eb 90 jmp 451 <printint+0x21>
4c1: eb 0d jmp 4d0 <printf>
4c3: 90 nop
4c4: 90 nop
4c5: 90 nop
4c6: 90 nop
4c7: 90 nop
4c8: 90 nop
4c9: 90 nop
4ca: 90 nop
4cb: 90 nop
4cc: 90 nop
4cd: 90 nop
4ce: 90 nop
4cf: 90 nop
000004d0 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, const char *fmt, ...)
{
4d0: 55 push %ebp
4d1: 89 e5 mov %esp,%ebp
4d3: 57 push %edi
4d4: 56 push %esi
4d5: 53 push %ebx
4d6: 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++){
4d9: 8b 75 0c mov 0xc(%ebp),%esi
4dc: 0f b6 1e movzbl (%esi),%ebx
4df: 84 db test %bl,%bl
4e1: 0f 84 b3 00 00 00 je 59a <printf+0xca>
ap = (uint*)(void*)&fmt + 1;
4e7: 8d 45 10 lea 0x10(%ebp),%eax
4ea: 83 c6 01 add $0x1,%esi
state = 0;
4ed: 31 ff xor %edi,%edi
ap = (uint*)(void*)&fmt + 1;
4ef: 89 45 d4 mov %eax,-0x2c(%ebp)
4f2: eb 2f jmp 523 <printf+0x53>
4f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
4f8: 83 f8 25 cmp $0x25,%eax
4fb: 0f 84 a7 00 00 00 je 5a8 <printf+0xd8>
write(fd, &c, 1);
501: 8d 45 e2 lea -0x1e(%ebp),%eax
504: 83 ec 04 sub $0x4,%esp
507: 88 5d e2 mov %bl,-0x1e(%ebp)
50a: 6a 01 push $0x1
50c: 50 push %eax
50d: ff 75 08 pushl 0x8(%ebp)
510: e8 6d fe ff ff call 382 <write>
515: 83 c4 10 add $0x10,%esp
518: 83 c6 01 add $0x1,%esi
for(i = 0; fmt[i]; i++){
51b: 0f b6 5e ff movzbl -0x1(%esi),%ebx
51f: 84 db test %bl,%bl
521: 74 77 je 59a <printf+0xca>
if(state == 0){
523: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
525: 0f be cb movsbl %bl,%ecx
528: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
52b: 74 cb je 4f8 <printf+0x28>
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
52d: 83 ff 25 cmp $0x25,%edi
530: 75 e6 jne 518 <printf+0x48>
if(c == 'd'){
532: 83 f8 64 cmp $0x64,%eax
535: 0f 84 05 01 00 00 je 640 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
53b: 81 e1 f7 00 00 00 and $0xf7,%ecx
541: 83 f9 70 cmp $0x70,%ecx
544: 74 72 je 5b8 <printf+0xe8>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
546: 83 f8 73 cmp $0x73,%eax
549: 0f 84 99 00 00 00 je 5e8 <printf+0x118>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
54f: 83 f8 63 cmp $0x63,%eax
552: 0f 84 08 01 00 00 je 660 <printf+0x190>
putc(fd, *ap);
ap++;
} else if(c == '%'){
558: 83 f8 25 cmp $0x25,%eax
55b: 0f 84 ef 00 00 00 je 650 <printf+0x180>
write(fd, &c, 1);
561: 8d 45 e7 lea -0x19(%ebp),%eax
564: 83 ec 04 sub $0x4,%esp
567: c6 45 e7 25 movb $0x25,-0x19(%ebp)
56b: 6a 01 push $0x1
56d: 50 push %eax
56e: ff 75 08 pushl 0x8(%ebp)
571: e8 0c fe ff ff call 382 <write>
576: 83 c4 0c add $0xc,%esp
579: 8d 45 e6 lea -0x1a(%ebp),%eax
57c: 88 5d e6 mov %bl,-0x1a(%ebp)
57f: 6a 01 push $0x1
581: 50 push %eax
582: ff 75 08 pushl 0x8(%ebp)
585: 83 c6 01 add $0x1,%esi
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
588: 31 ff xor %edi,%edi
write(fd, &c, 1);
58a: e8 f3 fd ff ff call 382 <write>
for(i = 0; fmt[i]; i++){
58f: 0f b6 5e ff movzbl -0x1(%esi),%ebx
write(fd, &c, 1);
593: 83 c4 10 add $0x10,%esp
for(i = 0; fmt[i]; i++){
596: 84 db test %bl,%bl
598: 75 89 jne 523 <printf+0x53>
}
}
}
59a: 8d 65 f4 lea -0xc(%ebp),%esp
59d: 5b pop %ebx
59e: 5e pop %esi
59f: 5f pop %edi
5a0: 5d pop %ebp
5a1: c3 ret
5a2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
state = '%';
5a8: bf 25 00 00 00 mov $0x25,%edi
5ad: e9 66 ff ff ff jmp 518 <printf+0x48>
5b2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
5b8: 83 ec 0c sub $0xc,%esp
5bb: b9 10 00 00 00 mov $0x10,%ecx
5c0: 6a 00 push $0x0
5c2: 8b 7d d4 mov -0x2c(%ebp),%edi
5c5: 8b 45 08 mov 0x8(%ebp),%eax
5c8: 8b 17 mov (%edi),%edx
5ca: e8 61 fe ff ff call 430 <printint>
ap++;
5cf: 89 f8 mov %edi,%eax
5d1: 83 c4 10 add $0x10,%esp
state = 0;
5d4: 31 ff xor %edi,%edi
ap++;
5d6: 83 c0 04 add $0x4,%eax
5d9: 89 45 d4 mov %eax,-0x2c(%ebp)
5dc: e9 37 ff ff ff jmp 518 <printf+0x48>
5e1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
5e8: 8b 45 d4 mov -0x2c(%ebp),%eax
5eb: 8b 08 mov (%eax),%ecx
ap++;
5ed: 83 c0 04 add $0x4,%eax
5f0: 89 45 d4 mov %eax,-0x2c(%ebp)
if(s == 0)
5f3: 85 c9 test %ecx,%ecx
5f5: 0f 84 8e 00 00 00 je 689 <printf+0x1b9>
while(*s != 0){
5fb: 0f b6 01 movzbl (%ecx),%eax
state = 0;
5fe: 31 ff xor %edi,%edi
s = (char*)*ap;
600: 89 cb mov %ecx,%ebx
while(*s != 0){
602: 84 c0 test %al,%al
604: 0f 84 0e ff ff ff je 518 <printf+0x48>
60a: 89 75 d0 mov %esi,-0x30(%ebp)
60d: 89 de mov %ebx,%esi
60f: 8b 5d 08 mov 0x8(%ebp),%ebx
612: 8d 7d e3 lea -0x1d(%ebp),%edi
615: 8d 76 00 lea 0x0(%esi),%esi
write(fd, &c, 1);
618: 83 ec 04 sub $0x4,%esp
s++;
61b: 83 c6 01 add $0x1,%esi
61e: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
621: 6a 01 push $0x1
623: 57 push %edi