-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.asm
1297 lines (1226 loc) · 43 KB
/
check.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
_check: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
#include "memlayout.h"
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: 83 ec 24 sub $0x24,%esp
int fd, fd1;
char c;
mkdir("utkarsh");
14: 68 38 08 00 00 push $0x838
19: e8 bc 03 00 00 call 3da <mkdir>
mkdir("mohanya");
1e: c7 04 24 40 08 00 00 movl $0x840,(%esp)
25: e8 b0 03 00 00 call 3da <mkdir>
fd = open("/utkarsh/1.txt", O_CREATE|O_RDWR);
2a: 58 pop %eax
2b: 5a pop %edx
2c: 68 02 02 00 00 push $0x202
31: 68 48 08 00 00 push $0x848
36: e8 77 03 00 00 call 3b2 <open>
fd1 = open("/utkarsh/2.txt", O_CREATE|O_RDWR);
3b: 59 pop %ecx
3c: 5b pop %ebx
3d: 68 02 02 00 00 push $0x202
42: 68 57 08 00 00 push $0x857
c = 'a';
write(fd, &c, 1);
47: 8d 5d e7 lea -0x19(%ebp),%ebx
fd = open("/utkarsh/1.txt", O_CREATE|O_RDWR);
4a: 89 c7 mov %eax,%edi
fd1 = open("/utkarsh/2.txt", O_CREATE|O_RDWR);
4c: e8 61 03 00 00 call 3b2 <open>
write(fd, &c, 1);
51: 83 c4 0c add $0xc,%esp
fd1 = open("/utkarsh/2.txt", O_CREATE|O_RDWR);
54: 89 c6 mov %eax,%esi
c = 'a';
56: c6 45 e7 61 movb $0x61,-0x19(%ebp)
write(fd, &c, 1);
5a: 6a 01 push $0x1
5c: 53 push %ebx
5d: 57 push %edi
5e: e8 2f 03 00 00 call 392 <write>
write(fd1, &c, 1);
63: 83 c4 0c add $0xc,%esp
66: 6a 01 push $0x1
68: 53 push %ebx
69: 56 push %esi
6a: e8 23 03 00 00 call 392 <write>
c = 'a';
write(fd, &c, 1);
6f: 83 c4 0c add $0xc,%esp
c = 'a';
72: c6 45 e7 61 movb $0x61,-0x19(%ebp)
write(fd, &c, 1);
76: 6a 01 push $0x1
78: 53 push %ebx
79: 57 push %edi
7a: e8 13 03 00 00 call 392 <write>
write(fd1, &c, 1);
7f: 83 c4 0c add $0xc,%esp
82: 6a 01 push $0x1
84: 53 push %ebx
85: 56 push %esi
86: e8 07 03 00 00 call 392 <write>
c = 'a';
write(fd, &c, 1);
8b: 83 c4 0c add $0xc,%esp
c = 'a';
8e: c6 45 e7 61 movb $0x61,-0x19(%ebp)
write(fd, &c, 1);
92: 6a 01 push $0x1
94: 53 push %ebx
95: 57 push %edi
96: e8 f7 02 00 00 call 392 <write>
write(fd1, &c, 1);
9b: 83 c4 0c add $0xc,%esp
9e: 6a 01 push $0x1
a0: 53 push %ebx
a1: 56 push %esi
a2: e8 eb 02 00 00 call 392 <write>
c = 'a';
write(fd, &c, 1);
a7: 83 c4 0c add $0xc,%esp
c = 'a';
aa: c6 45 e7 61 movb $0x61,-0x19(%ebp)
write(fd, &c, 1);
ae: 6a 01 push $0x1
b0: 53 push %ebx
b1: 57 push %edi
b2: e8 db 02 00 00 call 392 <write>
write(fd1, &c, 1);
b7: 83 c4 0c add $0xc,%esp
ba: 6a 01 push $0x1
bc: 53 push %ebx
bd: 56 push %esi
be: e8 cf 02 00 00 call 392 <write>
c = 'a';
write(fd, &c, 1);
c3: 83 c4 0c add $0xc,%esp
c = 'a';
c6: c6 45 e7 61 movb $0x61,-0x19(%ebp)
write(fd, &c, 1);
ca: 6a 01 push $0x1
cc: 53 push %ebx
cd: 57 push %edi
ce: e8 bf 02 00 00 call 392 <write>
write(fd1, &c, 1);
d3: 83 c4 0c add $0xc,%esp
d6: 6a 01 push $0x1
d8: 53 push %ebx
d9: 56 push %esi
da: e8 b3 02 00 00 call 392 <write>
c = '\n';
write(fd, &c, 1);
df: 83 c4 0c add $0xc,%esp
c = '\n';
e2: c6 45 e7 0a movb $0xa,-0x19(%ebp)
write(fd, &c, 1);
e6: 6a 01 push $0x1
e8: 53 push %ebx
e9: 57 push %edi
ea: e8 a3 02 00 00 call 392 <write>
write(fd1, &c, 1);
ef: 83 c4 0c add $0xc,%esp
f2: 6a 01 push $0x1
f4: 53 push %ebx
f5: 56 push %esi
f6: e8 97 02 00 00 call 392 <write>
close(fd);
fb: 89 3c 24 mov %edi,(%esp)
fe: e8 97 02 00 00 call 39a <close>
close(fd1);
103: 89 34 24 mov %esi,(%esp)
106: e8 8f 02 00 00 call 39a <close>
}
10b: 31 c0 xor %eax,%eax
10d: 8d 65 f0 lea -0x10(%ebp),%esp
110: 59 pop %ecx
111: 5b pop %ebx
112: 5e pop %esi
113: 5f pop %edi
114: 5d pop %ebp
115: 8d 61 fc lea -0x4(%ecx),%esp
118: c3 ret
119: 66 90 xchg %ax,%ax
11b: 66 90 xchg %ax,%ax
11d: 66 90 xchg %ax,%ax
11f: 90 nop
00000120 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, const char *t)
{
120: 55 push %ebp
121: 89 e5 mov %esp,%ebp
123: 53 push %ebx
124: 8b 45 08 mov 0x8(%ebp),%eax
127: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
12a: 89 c2 mov %eax,%edx
12c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
130: 83 c1 01 add $0x1,%ecx
133: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
137: 83 c2 01 add $0x1,%edx
13a: 84 db test %bl,%bl
13c: 88 5a ff mov %bl,-0x1(%edx)
13f: 75 ef jne 130 <strcpy+0x10>
;
return os;
}
141: 5b pop %ebx
142: 5d pop %ebp
143: c3 ret
144: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
14a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000150 <strcmp>:
int
strcmp(const char *p, const char *q)
{
150: 55 push %ebp
151: 89 e5 mov %esp,%ebp
153: 53 push %ebx
154: 8b 55 08 mov 0x8(%ebp),%edx
157: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
15a: 0f b6 02 movzbl (%edx),%eax
15d: 0f b6 19 movzbl (%ecx),%ebx
160: 84 c0 test %al,%al
162: 75 1c jne 180 <strcmp+0x30>
164: eb 2a jmp 190 <strcmp+0x40>
166: 8d 76 00 lea 0x0(%esi),%esi
169: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
170: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
173: 0f b6 02 movzbl (%edx),%eax
p++, q++;
176: 83 c1 01 add $0x1,%ecx
179: 0f b6 19 movzbl (%ecx),%ebx
while(*p && *p == *q)
17c: 84 c0 test %al,%al
17e: 74 10 je 190 <strcmp+0x40>
180: 38 d8 cmp %bl,%al
182: 74 ec je 170 <strcmp+0x20>
return (uchar)*p - (uchar)*q;
184: 29 d8 sub %ebx,%eax
}
186: 5b pop %ebx
187: 5d pop %ebp
188: c3 ret
189: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
190: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
192: 29 d8 sub %ebx,%eax
}
194: 5b pop %ebx
195: 5d pop %ebp
196: c3 ret
197: 89 f6 mov %esi,%esi
199: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000001a0 <strlen>:
uint
strlen(const char *s)
{
1a0: 55 push %ebp
1a1: 89 e5 mov %esp,%ebp
1a3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
1a6: 80 39 00 cmpb $0x0,(%ecx)
1a9: 74 15 je 1c0 <strlen+0x20>
1ab: 31 d2 xor %edx,%edx
1ad: 8d 76 00 lea 0x0(%esi),%esi
1b0: 83 c2 01 add $0x1,%edx
1b3: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
1b7: 89 d0 mov %edx,%eax
1b9: 75 f5 jne 1b0 <strlen+0x10>
;
return n;
}
1bb: 5d pop %ebp
1bc: c3 ret
1bd: 8d 76 00 lea 0x0(%esi),%esi
for(n = 0; s[n]; n++)
1c0: 31 c0 xor %eax,%eax
}
1c2: 5d pop %ebp
1c3: c3 ret
1c4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1ca: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000001d0 <memset>:
void*
memset(void *dst, int c, uint n)
{
1d0: 55 push %ebp
1d1: 89 e5 mov %esp,%ebp
1d3: 57 push %edi
1d4: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
1d7: 8b 4d 10 mov 0x10(%ebp),%ecx
1da: 8b 45 0c mov 0xc(%ebp),%eax
1dd: 89 d7 mov %edx,%edi
1df: fc cld
1e0: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
1e2: 89 d0 mov %edx,%eax
1e4: 5f pop %edi
1e5: 5d pop %ebp
1e6: c3 ret
1e7: 89 f6 mov %esi,%esi
1e9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000001f0 <strchr>:
char*
strchr(const char *s, char c)
{
1f0: 55 push %ebp
1f1: 89 e5 mov %esp,%ebp
1f3: 53 push %ebx
1f4: 8b 45 08 mov 0x8(%ebp),%eax
1f7: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
1fa: 0f b6 10 movzbl (%eax),%edx
1fd: 84 d2 test %dl,%dl
1ff: 74 1d je 21e <strchr+0x2e>
if(*s == c)
201: 38 d3 cmp %dl,%bl
203: 89 d9 mov %ebx,%ecx
205: 75 0d jne 214 <strchr+0x24>
207: eb 17 jmp 220 <strchr+0x30>
209: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
210: 38 ca cmp %cl,%dl
212: 74 0c je 220 <strchr+0x30>
for(; *s; s++)
214: 83 c0 01 add $0x1,%eax
217: 0f b6 10 movzbl (%eax),%edx
21a: 84 d2 test %dl,%dl
21c: 75 f2 jne 210 <strchr+0x20>
return (char*)s;
return 0;
21e: 31 c0 xor %eax,%eax
}
220: 5b pop %ebx
221: 5d pop %ebp
222: c3 ret
223: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
229: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000230 <gets>:
char*
gets(char *buf, int max)
{
230: 55 push %ebp
231: 89 e5 mov %esp,%ebp
233: 57 push %edi
234: 56 push %esi
235: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
236: 31 f6 xor %esi,%esi
238: 89 f3 mov %esi,%ebx
{
23a: 83 ec 1c sub $0x1c,%esp
23d: 8b 7d 08 mov 0x8(%ebp),%edi
for(i=0; i+1 < max; ){
240: eb 2f jmp 271 <gets+0x41>
242: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
cc = read(0, &c, 1);
248: 8d 45 e7 lea -0x19(%ebp),%eax
24b: 83 ec 04 sub $0x4,%esp
24e: 6a 01 push $0x1
250: 50 push %eax
251: 6a 00 push $0x0
253: e8 32 01 00 00 call 38a <read>
if(cc < 1)
258: 83 c4 10 add $0x10,%esp
25b: 85 c0 test %eax,%eax
25d: 7e 1c jle 27b <gets+0x4b>
break;
buf[i++] = c;
25f: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
263: 83 c7 01 add $0x1,%edi
266: 88 47 ff mov %al,-0x1(%edi)
if(c == '\n' || c == '\r')
269: 3c 0a cmp $0xa,%al
26b: 74 23 je 290 <gets+0x60>
26d: 3c 0d cmp $0xd,%al
26f: 74 1f je 290 <gets+0x60>
for(i=0; i+1 < max; ){
271: 83 c3 01 add $0x1,%ebx
274: 3b 5d 0c cmp 0xc(%ebp),%ebx
277: 89 fe mov %edi,%esi
279: 7c cd jl 248 <gets+0x18>
27b: 89 f3 mov %esi,%ebx
break;
}
buf[i] = '\0';
return buf;
}
27d: 8b 45 08 mov 0x8(%ebp),%eax
buf[i] = '\0';
280: c6 03 00 movb $0x0,(%ebx)
}
283: 8d 65 f4 lea -0xc(%ebp),%esp
286: 5b pop %ebx
287: 5e pop %esi
288: 5f pop %edi
289: 5d pop %ebp
28a: c3 ret
28b: 90 nop
28c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
290: 8b 75 08 mov 0x8(%ebp),%esi
293: 8b 45 08 mov 0x8(%ebp),%eax
296: 01 de add %ebx,%esi
298: 89 f3 mov %esi,%ebx
buf[i] = '\0';
29a: c6 03 00 movb $0x0,(%ebx)
}
29d: 8d 65 f4 lea -0xc(%ebp),%esp
2a0: 5b pop %ebx
2a1: 5e pop %esi
2a2: 5f pop %edi
2a3: 5d pop %ebp
2a4: c3 ret
2a5: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
2a9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
000002b0 <stat>:
int
stat(const char *n, struct stat *st)
{
2b0: 55 push %ebp
2b1: 89 e5 mov %esp,%ebp
2b3: 56 push %esi
2b4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
2b5: 83 ec 08 sub $0x8,%esp
2b8: 6a 00 push $0x0
2ba: ff 75 08 pushl 0x8(%ebp)
2bd: e8 f0 00 00 00 call 3b2 <open>
if(fd < 0)
2c2: 83 c4 10 add $0x10,%esp
2c5: 85 c0 test %eax,%eax
2c7: 78 27 js 2f0 <stat+0x40>
return -1;
r = fstat(fd, st);
2c9: 83 ec 08 sub $0x8,%esp
2cc: ff 75 0c pushl 0xc(%ebp)
2cf: 89 c3 mov %eax,%ebx
2d1: 50 push %eax
2d2: e8 f3 00 00 00 call 3ca <fstat>
close(fd);
2d7: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
2da: 89 c6 mov %eax,%esi
close(fd);
2dc: e8 b9 00 00 00 call 39a <close>
return r;
2e1: 83 c4 10 add $0x10,%esp
}
2e4: 8d 65 f8 lea -0x8(%ebp),%esp
2e7: 89 f0 mov %esi,%eax
2e9: 5b pop %ebx
2ea: 5e pop %esi
2eb: 5d pop %ebp
2ec: c3 ret
2ed: 8d 76 00 lea 0x0(%esi),%esi
return -1;
2f0: be ff ff ff ff mov $0xffffffff,%esi
2f5: eb ed jmp 2e4 <stat+0x34>
2f7: 89 f6 mov %esi,%esi
2f9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000300 <atoi>:
int
atoi(const char *s)
{
300: 55 push %ebp
301: 89 e5 mov %esp,%ebp
303: 53 push %ebx
304: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
307: 0f be 11 movsbl (%ecx),%edx
30a: 8d 42 d0 lea -0x30(%edx),%eax
30d: 3c 09 cmp $0x9,%al
n = 0;
30f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
314: 77 1f ja 335 <atoi+0x35>
316: 8d 76 00 lea 0x0(%esi),%esi
319: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
320: 8d 04 80 lea (%eax,%eax,4),%eax
323: 83 c1 01 add $0x1,%ecx
326: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
32a: 0f be 11 movsbl (%ecx),%edx
32d: 8d 5a d0 lea -0x30(%edx),%ebx
330: 80 fb 09 cmp $0x9,%bl
333: 76 eb jbe 320 <atoi+0x20>
return n;
}
335: 5b pop %ebx
336: 5d pop %ebp
337: c3 ret
338: 90 nop
339: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000340 <memmove>:
void*
memmove(void *vdst, const void *vsrc, int n)
{
340: 55 push %ebp
341: 89 e5 mov %esp,%ebp
343: 56 push %esi
344: 53 push %ebx
345: 8b 5d 10 mov 0x10(%ebp),%ebx
348: 8b 45 08 mov 0x8(%ebp),%eax
34b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst;
const char *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
34e: 85 db test %ebx,%ebx
350: 7e 14 jle 366 <memmove+0x26>
352: 31 d2 xor %edx,%edx
354: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
358: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
35c: 88 0c 10 mov %cl,(%eax,%edx,1)
35f: 83 c2 01 add $0x1,%edx
while(n-- > 0)
362: 39 d3 cmp %edx,%ebx
364: 75 f2 jne 358 <memmove+0x18>
return vdst;
}
366: 5b pop %ebx
367: 5e pop %esi
368: 5d pop %ebp
369: c3 ret
0000036a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
36a: b8 01 00 00 00 mov $0x1,%eax
36f: cd 40 int $0x40
371: c3 ret
00000372 <exit>:
SYSCALL(exit)
372: b8 02 00 00 00 mov $0x2,%eax
377: cd 40 int $0x40
379: c3 ret
0000037a <wait>:
SYSCALL(wait)
37a: b8 03 00 00 00 mov $0x3,%eax
37f: cd 40 int $0x40
381: c3 ret
00000382 <pipe>:
SYSCALL(pipe)
382: b8 04 00 00 00 mov $0x4,%eax
387: cd 40 int $0x40
389: c3 ret
0000038a <read>:
SYSCALL(read)
38a: b8 05 00 00 00 mov $0x5,%eax
38f: cd 40 int $0x40
391: c3 ret
00000392 <write>:
SYSCALL(write)
392: b8 10 00 00 00 mov $0x10,%eax
397: cd 40 int $0x40
399: c3 ret
0000039a <close>:
SYSCALL(close)
39a: b8 15 00 00 00 mov $0x15,%eax
39f: cd 40 int $0x40
3a1: c3 ret
000003a2 <kill>:
SYSCALL(kill)
3a2: b8 06 00 00 00 mov $0x6,%eax
3a7: cd 40 int $0x40
3a9: c3 ret
000003aa <exec>:
SYSCALL(exec)
3aa: b8 07 00 00 00 mov $0x7,%eax
3af: cd 40 int $0x40
3b1: c3 ret
000003b2 <open>:
SYSCALL(open)
3b2: b8 0f 00 00 00 mov $0xf,%eax
3b7: cd 40 int $0x40
3b9: c3 ret
000003ba <mknod>:
SYSCALL(mknod)
3ba: b8 11 00 00 00 mov $0x11,%eax
3bf: cd 40 int $0x40
3c1: c3 ret
000003c2 <unlink>:
SYSCALL(unlink)
3c2: b8 12 00 00 00 mov $0x12,%eax
3c7: cd 40 int $0x40
3c9: c3 ret
000003ca <fstat>:
SYSCALL(fstat)
3ca: b8 08 00 00 00 mov $0x8,%eax
3cf: cd 40 int $0x40
3d1: c3 ret
000003d2 <link>:
SYSCALL(link)
3d2: b8 13 00 00 00 mov $0x13,%eax
3d7: cd 40 int $0x40
3d9: c3 ret
000003da <mkdir>:
SYSCALL(mkdir)
3da: b8 14 00 00 00 mov $0x14,%eax
3df: cd 40 int $0x40
3e1: c3 ret
000003e2 <chdir>:
SYSCALL(chdir)
3e2: b8 09 00 00 00 mov $0x9,%eax
3e7: cd 40 int $0x40
3e9: c3 ret
000003ea <dup>:
SYSCALL(dup)
3ea: b8 0a 00 00 00 mov $0xa,%eax
3ef: cd 40 int $0x40
3f1: c3 ret
000003f2 <getpid>:
SYSCALL(getpid)
3f2: b8 0b 00 00 00 mov $0xb,%eax
3f7: cd 40 int $0x40
3f9: c3 ret
000003fa <sbrk>:
SYSCALL(sbrk)
3fa: b8 0c 00 00 00 mov $0xc,%eax
3ff: cd 40 int $0x40
401: c3 ret
00000402 <sleep>:
SYSCALL(sleep)
402: b8 0d 00 00 00 mov $0xd,%eax
407: cd 40 int $0x40
409: c3 ret
0000040a <uptime>:
SYSCALL(uptime)
40a: b8 0e 00 00 00 mov $0xe,%eax
40f: cd 40 int $0x40
411: c3 ret
00000412 <cps>:
SYSCALL(cps)
412: b8 16 00 00 00 mov $0x16,%eax
417: cd 40 int $0x40
419: c3 ret
0000041a <chpr>:
SYSCALL(chpr)
41a: b8 17 00 00 00 mov $0x17,%eax
41f: cd 40 int $0x40
421: c3 ret
00000422 <pwd>:
SYSCALL(pwd)
422: b8 18 00 00 00 mov $0x18,%eax
427: cd 40 int $0x40
429: c3 ret
0000042a <mv>:
SYSCALL(mv)
42a: b8 19 00 00 00 mov $0x19,%eax
42f: cd 40 int $0x40
431: c3 ret
432: 66 90 xchg %ax,%ax
434: 66 90 xchg %ax,%ax
436: 66 90 xchg %ax,%ax
438: 66 90 xchg %ax,%ax
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 70 08 00 00 movzbl 0x870(%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 dd fe ff ff call 392 <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, const 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 6d fe ff ff call 392 <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 0c fe ff ff call 392 <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 f3 fd ff ff call 392 <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