forked from hengyin/cs153_lab3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho.asm
1220 lines (1144 loc) · 42.9 KB
/
echo.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
_echo: file format elf32-i386
Disassembly of section .text:
00001000 <main>:
#include "stat.h"
#include "user.h"
int
main(int argc, char *argv[])
{
1000: 55 push %ebp
1001: 89 e5 mov %esp,%ebp
1003: 57 push %edi
1004: 56 push %esi
1005: 53 push %ebx
1006: 83 e4 f0 and $0xfffffff0,%esp
1009: 83 ec 10 sub $0x10,%esp
100c: 8b 75 08 mov 0x8(%ebp),%esi
100f: 8b 7d 0c mov 0xc(%ebp),%edi
int i;
for(i = 1; i < argc; i++)
1012: 83 fe 01 cmp $0x1,%esi
1015: 7e 58 jle 106f <main+0x6f>
1017: bb 01 00 00 00 mov $0x1,%ebx
101c: eb 26 jmp 1044 <main+0x44>
101e: 66 90 xchg %ax,%ax
printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
1020: c7 44 24 0c a1 17 00 movl $0x17a1,0xc(%esp)
1027: 00
1028: 8b 44 9f fc mov -0x4(%edi,%ebx,4),%eax
102c: c7 44 24 04 a3 17 00 movl $0x17a3,0x4(%esp)
1033: 00
1034: c7 04 24 01 00 00 00 movl $0x1,(%esp)
103b: 89 44 24 08 mov %eax,0x8(%esp)
103f: e8 bc 03 00 00 call 1400 <printf>
1044: 83 c3 01 add $0x1,%ebx
1047: 39 f3 cmp %esi,%ebx
1049: 75 d5 jne 1020 <main+0x20>
104b: c7 44 24 0c a8 17 00 movl $0x17a8,0xc(%esp)
1052: 00
1053: 8b 44 9f fc mov -0x4(%edi,%ebx,4),%eax
1057: c7 44 24 04 a3 17 00 movl $0x17a3,0x4(%esp)
105e: 00
105f: c7 04 24 01 00 00 00 movl $0x1,(%esp)
1066: 89 44 24 08 mov %eax,0x8(%esp)
106a: e8 91 03 00 00 call 1400 <printf>
exit();
106f: e8 2e 02 00 00 call 12a2 <exit>
1074: 66 90 xchg %ax,%ax
1076: 66 90 xchg %ax,%ax
1078: 66 90 xchg %ax,%ax
107a: 66 90 xchg %ax,%ax
107c: 66 90 xchg %ax,%ax
107e: 66 90 xchg %ax,%ax
00001080 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
1080: 55 push %ebp
1081: 89 e5 mov %esp,%ebp
1083: 8b 45 08 mov 0x8(%ebp),%eax
1086: 8b 4d 0c mov 0xc(%ebp),%ecx
1089: 53 push %ebx
char *os;
os = s;
while((*s++ = *t++) != 0)
108a: 89 c2 mov %eax,%edx
108c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
1090: 83 c1 01 add $0x1,%ecx
1093: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
1097: 83 c2 01 add $0x1,%edx
109a: 84 db test %bl,%bl
109c: 88 5a ff mov %bl,-0x1(%edx)
109f: 75 ef jne 1090 <strcpy+0x10>
;
return os;
}
10a1: 5b pop %ebx
10a2: 5d pop %ebp
10a3: c3 ret
10a4: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
10aa: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000010b0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
10b0: 55 push %ebp
10b1: 89 e5 mov %esp,%ebp
10b3: 8b 55 08 mov 0x8(%ebp),%edx
10b6: 53 push %ebx
10b7: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
10ba: 0f b6 02 movzbl (%edx),%eax
10bd: 84 c0 test %al,%al
10bf: 74 2d je 10ee <strcmp+0x3e>
10c1: 0f b6 19 movzbl (%ecx),%ebx
10c4: 38 d8 cmp %bl,%al
10c6: 74 0e je 10d6 <strcmp+0x26>
10c8: eb 2b jmp 10f5 <strcmp+0x45>
10ca: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
10d0: 38 c8 cmp %cl,%al
10d2: 75 15 jne 10e9 <strcmp+0x39>
p++, q++;
10d4: 89 d9 mov %ebx,%ecx
10d6: 83 c2 01 add $0x1,%edx
while(*p && *p == *q)
10d9: 0f b6 02 movzbl (%edx),%eax
p++, q++;
10dc: 8d 59 01 lea 0x1(%ecx),%ebx
while(*p && *p == *q)
10df: 0f b6 49 01 movzbl 0x1(%ecx),%ecx
10e3: 84 c0 test %al,%al
10e5: 75 e9 jne 10d0 <strcmp+0x20>
10e7: 31 c0 xor %eax,%eax
return (uchar)*p - (uchar)*q;
10e9: 29 c8 sub %ecx,%eax
}
10eb: 5b pop %ebx
10ec: 5d pop %ebp
10ed: c3 ret
10ee: 0f b6 09 movzbl (%ecx),%ecx
while(*p && *p == *q)
10f1: 31 c0 xor %eax,%eax
10f3: eb f4 jmp 10e9 <strcmp+0x39>
10f5: 0f b6 cb movzbl %bl,%ecx
10f8: eb ef jmp 10e9 <strcmp+0x39>
10fa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
00001100 <strlen>:
uint
strlen(char *s)
{
1100: 55 push %ebp
1101: 89 e5 mov %esp,%ebp
1103: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
1106: 80 39 00 cmpb $0x0,(%ecx)
1109: 74 12 je 111d <strlen+0x1d>
110b: 31 d2 xor %edx,%edx
110d: 8d 76 00 lea 0x0(%esi),%esi
1110: 83 c2 01 add $0x1,%edx
1113: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
1117: 89 d0 mov %edx,%eax
1119: 75 f5 jne 1110 <strlen+0x10>
;
return n;
}
111b: 5d pop %ebp
111c: c3 ret
for(n = 0; s[n]; n++)
111d: 31 c0 xor %eax,%eax
}
111f: 5d pop %ebp
1120: c3 ret
1121: eb 0d jmp 1130 <memset>
1123: 90 nop
1124: 90 nop
1125: 90 nop
1126: 90 nop
1127: 90 nop
1128: 90 nop
1129: 90 nop
112a: 90 nop
112b: 90 nop
112c: 90 nop
112d: 90 nop
112e: 90 nop
112f: 90 nop
00001130 <memset>:
void*
memset(void *dst, int c, uint n)
{
1130: 55 push %ebp
1131: 89 e5 mov %esp,%ebp
1133: 8b 55 08 mov 0x8(%ebp),%edx
1136: 57 push %edi
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
1137: 8b 4d 10 mov 0x10(%ebp),%ecx
113a: 8b 45 0c mov 0xc(%ebp),%eax
113d: 89 d7 mov %edx,%edi
113f: fc cld
1140: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
1142: 89 d0 mov %edx,%eax
1144: 5f pop %edi
1145: 5d pop %ebp
1146: c3 ret
1147: 89 f6 mov %esi,%esi
1149: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00001150 <strchr>:
char*
strchr(const char *s, char c)
{
1150: 55 push %ebp
1151: 89 e5 mov %esp,%ebp
1153: 8b 45 08 mov 0x8(%ebp),%eax
1156: 53 push %ebx
1157: 8b 55 0c mov 0xc(%ebp),%edx
for(; *s; s++)
115a: 0f b6 18 movzbl (%eax),%ebx
115d: 84 db test %bl,%bl
115f: 74 1d je 117e <strchr+0x2e>
if(*s == c)
1161: 38 d3 cmp %dl,%bl
1163: 89 d1 mov %edx,%ecx
1165: 75 0d jne 1174 <strchr+0x24>
1167: eb 17 jmp 1180 <strchr+0x30>
1169: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
1170: 38 ca cmp %cl,%dl
1172: 74 0c je 1180 <strchr+0x30>
for(; *s; s++)
1174: 83 c0 01 add $0x1,%eax
1177: 0f b6 10 movzbl (%eax),%edx
117a: 84 d2 test %dl,%dl
117c: 75 f2 jne 1170 <strchr+0x20>
return (char*)s;
return 0;
117e: 31 c0 xor %eax,%eax
}
1180: 5b pop %ebx
1181: 5d pop %ebp
1182: c3 ret
1183: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1189: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00001190 <gets>:
char*
gets(char *buf, int max)
{
1190: 55 push %ebp
1191: 89 e5 mov %esp,%ebp
1193: 57 push %edi
1194: 56 push %esi
int i, cc;
char c;
for(i=0; i+1 < max; ){
1195: 31 f6 xor %esi,%esi
{
1197: 53 push %ebx
1198: 83 ec 2c sub $0x2c,%esp
cc = read(0, &c, 1);
119b: 8d 7d e7 lea -0x19(%ebp),%edi
for(i=0; i+1 < max; ){
119e: eb 31 jmp 11d1 <gets+0x41>
cc = read(0, &c, 1);
11a0: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
11a7: 00
11a8: 89 7c 24 04 mov %edi,0x4(%esp)
11ac: c7 04 24 00 00 00 00 movl $0x0,(%esp)
11b3: e8 02 01 00 00 call 12ba <read>
if(cc < 1)
11b8: 85 c0 test %eax,%eax
11ba: 7e 1d jle 11d9 <gets+0x49>
break;
buf[i++] = c;
11bc: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
for(i=0; i+1 < max; ){
11c0: 89 de mov %ebx,%esi
buf[i++] = c;
11c2: 8b 55 08 mov 0x8(%ebp),%edx
if(c == '\n' || c == '\r')
11c5: 3c 0d cmp $0xd,%al
buf[i++] = c;
11c7: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
11cb: 74 0c je 11d9 <gets+0x49>
11cd: 3c 0a cmp $0xa,%al
11cf: 74 08 je 11d9 <gets+0x49>
for(i=0; i+1 < max; ){
11d1: 8d 5e 01 lea 0x1(%esi),%ebx
11d4: 3b 5d 0c cmp 0xc(%ebp),%ebx
11d7: 7c c7 jl 11a0 <gets+0x10>
break;
}
buf[i] = '\0';
11d9: 8b 45 08 mov 0x8(%ebp),%eax
11dc: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
11e0: 83 c4 2c add $0x2c,%esp
11e3: 5b pop %ebx
11e4: 5e pop %esi
11e5: 5f pop %edi
11e6: 5d pop %ebp
11e7: c3 ret
11e8: 90 nop
11e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000011f0 <stat>:
int
stat(char *n, struct stat *st)
{
11f0: 55 push %ebp
11f1: 89 e5 mov %esp,%ebp
11f3: 56 push %esi
11f4: 53 push %ebx
11f5: 83 ec 10 sub $0x10,%esp
int fd;
int r;
fd = open(n, O_RDONLY);
11f8: 8b 45 08 mov 0x8(%ebp),%eax
11fb: c7 44 24 04 00 00 00 movl $0x0,0x4(%esp)
1202: 00
1203: 89 04 24 mov %eax,(%esp)
1206: e8 d7 00 00 00 call 12e2 <open>
if(fd < 0)
120b: 85 c0 test %eax,%eax
fd = open(n, O_RDONLY);
120d: 89 c3 mov %eax,%ebx
if(fd < 0)
120f: 78 27 js 1238 <stat+0x48>
return -1;
r = fstat(fd, st);
1211: 8b 45 0c mov 0xc(%ebp),%eax
1214: 89 1c 24 mov %ebx,(%esp)
1217: 89 44 24 04 mov %eax,0x4(%esp)
121b: e8 da 00 00 00 call 12fa <fstat>
close(fd);
1220: 89 1c 24 mov %ebx,(%esp)
r = fstat(fd, st);
1223: 89 c6 mov %eax,%esi
close(fd);
1225: e8 a0 00 00 00 call 12ca <close>
return r;
122a: 89 f0 mov %esi,%eax
}
122c: 83 c4 10 add $0x10,%esp
122f: 5b pop %ebx
1230: 5e pop %esi
1231: 5d pop %ebp
1232: c3 ret
1233: 90 nop
1234: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
return -1;
1238: b8 ff ff ff ff mov $0xffffffff,%eax
123d: eb ed jmp 122c <stat+0x3c>
123f: 90 nop
00001240 <atoi>:
int
atoi(const char *s)
{
1240: 55 push %ebp
1241: 89 e5 mov %esp,%ebp
1243: 8b 4d 08 mov 0x8(%ebp),%ecx
1246: 53 push %ebx
int n;
n = 0;
while('0' <= *s && *s <= '9')
1247: 0f be 11 movsbl (%ecx),%edx
124a: 8d 42 d0 lea -0x30(%edx),%eax
124d: 3c 09 cmp $0x9,%al
n = 0;
124f: b8 00 00 00 00 mov $0x0,%eax
while('0' <= *s && *s <= '9')
1254: 77 17 ja 126d <atoi+0x2d>
1256: 66 90 xchg %ax,%ax
n = n*10 + *s++ - '0';
1258: 83 c1 01 add $0x1,%ecx
125b: 8d 04 80 lea (%eax,%eax,4),%eax
125e: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
while('0' <= *s && *s <= '9')
1262: 0f be 11 movsbl (%ecx),%edx
1265: 8d 5a d0 lea -0x30(%edx),%ebx
1268: 80 fb 09 cmp $0x9,%bl
126b: 76 eb jbe 1258 <atoi+0x18>
return n;
}
126d: 5b pop %ebx
126e: 5d pop %ebp
126f: c3 ret
00001270 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
1270: 55 push %ebp
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
1271: 31 d2 xor %edx,%edx
{
1273: 89 e5 mov %esp,%ebp
1275: 56 push %esi
1276: 8b 45 08 mov 0x8(%ebp),%eax
1279: 53 push %ebx
127a: 8b 5d 10 mov 0x10(%ebp),%ebx
127d: 8b 75 0c mov 0xc(%ebp),%esi
while(n-- > 0)
1280: 85 db test %ebx,%ebx
1282: 7e 12 jle 1296 <memmove+0x26>
1284: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
1288: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
128c: 88 0c 10 mov %cl,(%eax,%edx,1)
128f: 83 c2 01 add $0x1,%edx
while(n-- > 0)
1292: 39 da cmp %ebx,%edx
1294: 75 f2 jne 1288 <memmove+0x18>
return vdst;
}
1296: 5b pop %ebx
1297: 5e pop %esi
1298: 5d pop %ebp
1299: c3 ret
0000129a <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
129a: b8 01 00 00 00 mov $0x1,%eax
129f: cd 40 int $0x40
12a1: c3 ret
000012a2 <exit>:
SYSCALL(exit)
12a2: b8 02 00 00 00 mov $0x2,%eax
12a7: cd 40 int $0x40
12a9: c3 ret
000012aa <wait>:
SYSCALL(wait)
12aa: b8 03 00 00 00 mov $0x3,%eax
12af: cd 40 int $0x40
12b1: c3 ret
000012b2 <pipe>:
SYSCALL(pipe)
12b2: b8 04 00 00 00 mov $0x4,%eax
12b7: cd 40 int $0x40
12b9: c3 ret
000012ba <read>:
SYSCALL(read)
12ba: b8 05 00 00 00 mov $0x5,%eax
12bf: cd 40 int $0x40
12c1: c3 ret
000012c2 <write>:
SYSCALL(write)
12c2: b8 10 00 00 00 mov $0x10,%eax
12c7: cd 40 int $0x40
12c9: c3 ret
000012ca <close>:
SYSCALL(close)
12ca: b8 15 00 00 00 mov $0x15,%eax
12cf: cd 40 int $0x40
12d1: c3 ret
000012d2 <kill>:
SYSCALL(kill)
12d2: b8 06 00 00 00 mov $0x6,%eax
12d7: cd 40 int $0x40
12d9: c3 ret
000012da <exec>:
SYSCALL(exec)
12da: b8 07 00 00 00 mov $0x7,%eax
12df: cd 40 int $0x40
12e1: c3 ret
000012e2 <open>:
SYSCALL(open)
12e2: b8 0f 00 00 00 mov $0xf,%eax
12e7: cd 40 int $0x40
12e9: c3 ret
000012ea <mknod>:
SYSCALL(mknod)
12ea: b8 11 00 00 00 mov $0x11,%eax
12ef: cd 40 int $0x40
12f1: c3 ret
000012f2 <unlink>:
SYSCALL(unlink)
12f2: b8 12 00 00 00 mov $0x12,%eax
12f7: cd 40 int $0x40
12f9: c3 ret
000012fa <fstat>:
SYSCALL(fstat)
12fa: b8 08 00 00 00 mov $0x8,%eax
12ff: cd 40 int $0x40
1301: c3 ret
00001302 <link>:
SYSCALL(link)
1302: b8 13 00 00 00 mov $0x13,%eax
1307: cd 40 int $0x40
1309: c3 ret
0000130a <mkdir>:
SYSCALL(mkdir)
130a: b8 14 00 00 00 mov $0x14,%eax
130f: cd 40 int $0x40
1311: c3 ret
00001312 <chdir>:
SYSCALL(chdir)
1312: b8 09 00 00 00 mov $0x9,%eax
1317: cd 40 int $0x40
1319: c3 ret
0000131a <dup>:
SYSCALL(dup)
131a: b8 0a 00 00 00 mov $0xa,%eax
131f: cd 40 int $0x40
1321: c3 ret
00001322 <getpid>:
SYSCALL(getpid)
1322: b8 0b 00 00 00 mov $0xb,%eax
1327: cd 40 int $0x40
1329: c3 ret
0000132a <sbrk>:
SYSCALL(sbrk)
132a: b8 0c 00 00 00 mov $0xc,%eax
132f: cd 40 int $0x40
1331: c3 ret
00001332 <sleep>:
SYSCALL(sleep)
1332: b8 0d 00 00 00 mov $0xd,%eax
1337: cd 40 int $0x40
1339: c3 ret
0000133a <uptime>:
SYSCALL(uptime)
133a: b8 0e 00 00 00 mov $0xe,%eax
133f: cd 40 int $0x40
1341: c3 ret
00001342 <shm_open>:
SYSCALL(shm_open)
1342: b8 16 00 00 00 mov $0x16,%eax
1347: cd 40 int $0x40
1349: c3 ret
0000134a <shm_close>:
SYSCALL(shm_close)
134a: b8 17 00 00 00 mov $0x17,%eax
134f: cd 40 int $0x40
1351: c3 ret
1352: 66 90 xchg %ax,%ax
1354: 66 90 xchg %ax,%ax
1356: 66 90 xchg %ax,%ax
1358: 66 90 xchg %ax,%ax
135a: 66 90 xchg %ax,%ax
135c: 66 90 xchg %ax,%ax
135e: 66 90 xchg %ax,%ax
00001360 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
1360: 55 push %ebp
1361: 89 e5 mov %esp,%ebp
1363: 57 push %edi
1364: 56 push %esi
1365: 89 c6 mov %eax,%esi
1367: 53 push %ebx
1368: 83 ec 4c sub $0x4c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
136b: 8b 5d 08 mov 0x8(%ebp),%ebx
136e: 85 db test %ebx,%ebx
1370: 74 09 je 137b <printint+0x1b>
1372: 89 d0 mov %edx,%eax
1374: c1 e8 1f shr $0x1f,%eax
1377: 84 c0 test %al,%al
1379: 75 75 jne 13f0 <printint+0x90>
neg = 1;
x = -xx;
} else {
x = xx;
137b: 89 d0 mov %edx,%eax
neg = 0;
137d: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
1384: 89 75 c0 mov %esi,-0x40(%ebp)
}
i = 0;
1387: 31 ff xor %edi,%edi
1389: 89 ce mov %ecx,%esi
138b: 8d 5d d7 lea -0x29(%ebp),%ebx
138e: eb 02 jmp 1392 <printint+0x32>
do{
buf[i++] = digits[x % base];
1390: 89 cf mov %ecx,%edi
1392: 31 d2 xor %edx,%edx
1394: f7 f6 div %esi
1396: 8d 4f 01 lea 0x1(%edi),%ecx
1399: 0f b6 92 b1 17 00 00 movzbl 0x17b1(%edx),%edx
}while((x /= base) != 0);
13a0: 85 c0 test %eax,%eax
buf[i++] = digits[x % base];
13a2: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
13a5: 75 e9 jne 1390 <printint+0x30>
if(neg)
13a7: 8b 55 c4 mov -0x3c(%ebp),%edx
buf[i++] = digits[x % base];
13aa: 89 c8 mov %ecx,%eax
13ac: 8b 75 c0 mov -0x40(%ebp),%esi
if(neg)
13af: 85 d2 test %edx,%edx
13b1: 74 08 je 13bb <printint+0x5b>
buf[i++] = '-';
13b3: 8d 4f 02 lea 0x2(%edi),%ecx
13b6: c6 44 05 d8 2d movb $0x2d,-0x28(%ebp,%eax,1)
while(--i >= 0)
13bb: 8d 79 ff lea -0x1(%ecx),%edi
13be: 66 90 xchg %ax,%ax
13c0: 0f b6 44 3d d8 movzbl -0x28(%ebp,%edi,1),%eax
13c5: 83 ef 01 sub $0x1,%edi
write(fd, &c, 1);
13c8: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
13cf: 00
13d0: 89 5c 24 04 mov %ebx,0x4(%esp)
13d4: 89 34 24 mov %esi,(%esp)
13d7: 88 45 d7 mov %al,-0x29(%ebp)
13da: e8 e3 fe ff ff call 12c2 <write>
while(--i >= 0)
13df: 83 ff ff cmp $0xffffffff,%edi
13e2: 75 dc jne 13c0 <printint+0x60>
putc(fd, buf[i]);
}
13e4: 83 c4 4c add $0x4c,%esp
13e7: 5b pop %ebx
13e8: 5e pop %esi
13e9: 5f pop %edi
13ea: 5d pop %ebp
13eb: c3 ret
13ec: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
x = -xx;
13f0: 89 d0 mov %edx,%eax
13f2: f7 d8 neg %eax
neg = 1;
13f4: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
13fb: eb 87 jmp 1384 <printint+0x24>
13fd: 8d 76 00 lea 0x0(%esi),%esi
00001400 <printf>:
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
1400: 55 push %ebp
1401: 89 e5 mov %esp,%ebp
1403: 57 push %edi
char *s;
int c, i, state;
uint *ap;
state = 0;
1404: 31 ff xor %edi,%edi
{
1406: 56 push %esi
1407: 53 push %ebx
1408: 83 ec 3c sub $0x3c,%esp
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
140b: 8b 5d 0c mov 0xc(%ebp),%ebx
ap = (uint*)(void*)&fmt + 1;
140e: 8d 45 10 lea 0x10(%ebp),%eax
{
1411: 8b 75 08 mov 0x8(%ebp),%esi
ap = (uint*)(void*)&fmt + 1;
1414: 89 45 d4 mov %eax,-0x2c(%ebp)
for(i = 0; fmt[i]; i++){
1417: 0f b6 13 movzbl (%ebx),%edx
141a: 83 c3 01 add $0x1,%ebx
141d: 84 d2 test %dl,%dl
141f: 75 39 jne 145a <printf+0x5a>
1421: e9 c2 00 00 00 jmp 14e8 <printf+0xe8>
1426: 66 90 xchg %ax,%ax
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
1428: 83 fa 25 cmp $0x25,%edx
142b: 0f 84 bf 00 00 00 je 14f0 <printf+0xf0>
write(fd, &c, 1);
1431: 8d 45 e2 lea -0x1e(%ebp),%eax
1434: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
143b: 00
143c: 89 44 24 04 mov %eax,0x4(%esp)
1440: 89 34 24 mov %esi,(%esp)
state = '%';
} else {
putc(fd, c);
1443: 88 55 e2 mov %dl,-0x1e(%ebp)
write(fd, &c, 1);
1446: e8 77 fe ff ff call 12c2 <write>
144b: 83 c3 01 add $0x1,%ebx
for(i = 0; fmt[i]; i++){
144e: 0f b6 53 ff movzbl -0x1(%ebx),%edx
1452: 84 d2 test %dl,%dl
1454: 0f 84 8e 00 00 00 je 14e8 <printf+0xe8>
if(state == 0){
145a: 85 ff test %edi,%edi
c = fmt[i] & 0xff;
145c: 0f be c2 movsbl %dl,%eax
if(state == 0){
145f: 74 c7 je 1428 <printf+0x28>
}
} else if(state == '%'){
1461: 83 ff 25 cmp $0x25,%edi
1464: 75 e5 jne 144b <printf+0x4b>
if(c == 'd'){
1466: 83 fa 64 cmp $0x64,%edx
1469: 0f 84 31 01 00 00 je 15a0 <printf+0x1a0>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
146f: 25 f7 00 00 00 and $0xf7,%eax
1474: 83 f8 70 cmp $0x70,%eax
1477: 0f 84 83 00 00 00 je 1500 <printf+0x100>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
147d: 83 fa 73 cmp $0x73,%edx
1480: 0f 84 a2 00 00 00 je 1528 <printf+0x128>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
1486: 83 fa 63 cmp $0x63,%edx
1489: 0f 84 35 01 00 00 je 15c4 <printf+0x1c4>
putc(fd, *ap);
ap++;
} else if(c == '%'){
148f: 83 fa 25 cmp $0x25,%edx
1492: 0f 84 e0 00 00 00 je 1578 <printf+0x178>
write(fd, &c, 1);
1498: 8d 45 e6 lea -0x1a(%ebp),%eax
149b: 83 c3 01 add $0x1,%ebx
149e: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
14a5: 00
} else {
// Unknown % sequence. Print it to draw attention.
putc(fd, '%');
putc(fd, c);
}
state = 0;
14a6: 31 ff xor %edi,%edi
write(fd, &c, 1);
14a8: 89 44 24 04 mov %eax,0x4(%esp)
14ac: 89 34 24 mov %esi,(%esp)
14af: 89 55 d0 mov %edx,-0x30(%ebp)
14b2: c6 45 e6 25 movb $0x25,-0x1a(%ebp)
14b6: e8 07 fe ff ff call 12c2 <write>
putc(fd, c);
14bb: 8b 55 d0 mov -0x30(%ebp),%edx
write(fd, &c, 1);
14be: 8d 45 e7 lea -0x19(%ebp),%eax
14c1: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
14c8: 00
14c9: 89 44 24 04 mov %eax,0x4(%esp)
14cd: 89 34 24 mov %esi,(%esp)
putc(fd, c);
14d0: 88 55 e7 mov %dl,-0x19(%ebp)
write(fd, &c, 1);
14d3: e8 ea fd ff ff call 12c2 <write>
for(i = 0; fmt[i]; i++){
14d8: 0f b6 53 ff movzbl -0x1(%ebx),%edx
14dc: 84 d2 test %dl,%dl
14de: 0f 85 76 ff ff ff jne 145a <printf+0x5a>
14e4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
}
}
}
14e8: 83 c4 3c add $0x3c,%esp
14eb: 5b pop %ebx
14ec: 5e pop %esi
14ed: 5f pop %edi
14ee: 5d pop %ebp
14ef: c3 ret
state = '%';
14f0: bf 25 00 00 00 mov $0x25,%edi
14f5: e9 51 ff ff ff jmp 144b <printf+0x4b>
14fa: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 16, 0);
1500: 8b 45 d4 mov -0x2c(%ebp),%eax
1503: b9 10 00 00 00 mov $0x10,%ecx
state = 0;
1508: 31 ff xor %edi,%edi
printint(fd, *ap, 16, 0);
150a: c7 04 24 00 00 00 00 movl $0x0,(%esp)
1511: 8b 10 mov (%eax),%edx
1513: 89 f0 mov %esi,%eax
1515: e8 46 fe ff ff call 1360 <printint>
ap++;
151a: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
151e: e9 28 ff ff ff jmp 144b <printf+0x4b>
1523: 90 nop
1524: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
s = (char*)*ap;
1528: 8b 45 d4 mov -0x2c(%ebp),%eax
ap++;
152b: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
s = (char*)*ap;
152f: 8b 38 mov (%eax),%edi
s = "(null)";
1531: b8 aa 17 00 00 mov $0x17aa,%eax
1536: 85 ff test %edi,%edi
1538: 0f 44 f8 cmove %eax,%edi
while(*s != 0){
153b: 0f b6 07 movzbl (%edi),%eax
153e: 84 c0 test %al,%al
1540: 74 2a je 156c <printf+0x16c>
1542: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
1548: 88 45 e3 mov %al,-0x1d(%ebp)
write(fd, &c, 1);
154b: 8d 45 e3 lea -0x1d(%ebp),%eax
s++;
154e: 83 c7 01 add $0x1,%edi
write(fd, &c, 1);
1551: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
1558: 00
1559: 89 44 24 04 mov %eax,0x4(%esp)
155d: 89 34 24 mov %esi,(%esp)
1560: e8 5d fd ff ff call 12c2 <write>
while(*s != 0){
1565: 0f b6 07 movzbl (%edi),%eax
1568: 84 c0 test %al,%al
156a: 75 dc jne 1548 <printf+0x148>
state = 0;
156c: 31 ff xor %edi,%edi
156e: e9 d8 fe ff ff jmp 144b <printf+0x4b>
1573: 90 nop
1574: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
write(fd, &c, 1);
1578: 8d 45 e5 lea -0x1b(%ebp),%eax
state = 0;
157b: 31 ff xor %edi,%edi
write(fd, &c, 1);
157d: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
1584: 00
1585: 89 44 24 04 mov %eax,0x4(%esp)
1589: 89 34 24 mov %esi,(%esp)
158c: c6 45 e5 25 movb $0x25,-0x1b(%ebp)
1590: e8 2d fd ff ff call 12c2 <write>
1595: e9 b1 fe ff ff jmp 144b <printf+0x4b>
159a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
printint(fd, *ap, 10, 1);
15a0: 8b 45 d4 mov -0x2c(%ebp),%eax
15a3: b9 0a 00 00 00 mov $0xa,%ecx
state = 0;
15a8: 66 31 ff xor %di,%di
printint(fd, *ap, 10, 1);
15ab: c7 04 24 01 00 00 00 movl $0x1,(%esp)
15b2: 8b 10 mov (%eax),%edx
15b4: 89 f0 mov %esi,%eax
15b6: e8 a5 fd ff ff call 1360 <printint>
ap++;
15bb: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
15bf: e9 87 fe ff ff jmp 144b <printf+0x4b>
putc(fd, *ap);
15c4: 8b 45 d4 mov -0x2c(%ebp),%eax
state = 0;
15c7: 31 ff xor %edi,%edi
putc(fd, *ap);
15c9: 8b 00 mov (%eax),%eax
write(fd, &c, 1);
15cb: c7 44 24 08 01 00 00 movl $0x1,0x8(%esp)
15d2: 00
15d3: 89 34 24 mov %esi,(%esp)
putc(fd, *ap);
15d6: 88 45 e4 mov %al,-0x1c(%ebp)
write(fd, &c, 1);
15d9: 8d 45 e4 lea -0x1c(%ebp),%eax
15dc: 89 44 24 04 mov %eax,0x4(%esp)
15e0: e8 dd fc ff ff call 12c2 <write>
ap++;
15e5: 83 45 d4 04 addl $0x4,-0x2c(%ebp)
15e9: e9 5d fe ff ff jmp 144b <printf+0x4b>
15ee: 66 90 xchg %ax,%ax
000015f0 <free>:
static Header base;
static Header *freep;
void
free(void *ap)
{
15f0: 55 push %ebp
Header *bp, *p;
bp = (Header*)ap - 1;
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
15f1: a1 6c 1a 00 00 mov 0x1a6c,%eax
{
15f6: 89 e5 mov %esp,%ebp
15f8: 57 push %edi
15f9: 56 push %esi
15fa: 53 push %ebx
15fb: 8b 5d 08 mov 0x8(%ebp),%ebx
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
15fe: 8b 08 mov (%eax),%ecx
bp = (Header*)ap - 1;
1600: 8d 53 f8 lea -0x8(%ebx),%edx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
1603: 39 d0 cmp %edx,%eax
1605: 72 11 jb 1618 <free+0x28>
1607: 90 nop
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
1608: 39 c8 cmp %ecx,%eax
160a: 72 04 jb 1610 <free+0x20>
160c: 39 ca cmp %ecx,%edx
160e: 72 10 jb 1620 <free+0x30>
1610: 89 c8 mov %ecx,%eax
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
1612: 39 d0 cmp %edx,%eax
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
1614: 8b 08 mov (%eax),%ecx
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
1616: 73 f0 jae 1608 <free+0x18>
1618: 39 ca cmp %ecx,%edx
161a: 72 04 jb 1620 <free+0x30>
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
161c: 39 c8 cmp %ecx,%eax
161e: 72 f0 jb 1610 <free+0x20>
break;
if(bp + bp->s.size == p->s.ptr){
1620: 8b 73 fc mov -0x4(%ebx),%esi
1623: 8d 3c f2 lea (%edx,%esi,8),%edi
1626: 39 cf cmp %ecx,%edi
1628: 74 1e je 1648 <free+0x58>
bp->s.size += p->s.ptr->s.size;
bp->s.ptr = p->s.ptr->s.ptr;
} else
bp->s.ptr = p->s.ptr;
162a: 89 4b f8 mov %ecx,-0x8(%ebx)
if(p + p->s.size == bp){
162d: 8b 48 04 mov 0x4(%eax),%ecx
1630: 8d 34 c8 lea (%eax,%ecx,8),%esi
1633: 39 f2 cmp %esi,%edx
1635: 74 28 je 165f <free+0x6f>
p->s.size += bp->s.size;
p->s.ptr = bp->s.ptr;
} else
p->s.ptr = bp;
1637: 89 10 mov %edx,(%eax)
freep = p;
1639: a3 6c 1a 00 00 mov %eax,0x1a6c
}
163e: 5b pop %ebx
163f: 5e pop %esi
1640: 5f pop %edi
1641: 5d pop %ebp