-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecho.asm
3250 lines (3044 loc) · 113 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:
00000000 <main>:
#include "stat.h"
#include "user.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 08 sub $0x8,%esp
14: 8b 31 mov (%ecx),%esi
16: 8b 79 04 mov 0x4(%ecx),%edi
int i;
for(i = 1; i < argc; i++)
19: 83 fe 01 cmp $0x1,%esi
1c: 7e 41 jle 5f <main+0x5f>
1e: bb 01 00 00 00 mov $0x1,%ebx
23: eb 1b jmp 40 <main+0x40>
25: 8d 76 00 lea 0x0(%esi),%esi
printf(1, "%s%s", argv[i], i+1 < argc ? " " : "\n");
28: 68 0c 12 00 00 push $0x120c
2d: ff 74 9f fc pushl -0x4(%edi,%ebx,4)
31: 68 0e 12 00 00 push $0x120e
36: 6a 01 push $0x1
38: e8 e3 03 00 00 call 420 <printf>
3d: 83 c4 10 add $0x10,%esp
40: 83 c3 01 add $0x1,%ebx
43: 39 de cmp %ebx,%esi
45: 75 e1 jne 28 <main+0x28>
47: 68 aa 13 00 00 push $0x13aa
4c: ff 74 b7 fc pushl -0x4(%edi,%esi,4)
50: 68 0e 12 00 00 push $0x120e
55: 6a 01 push $0x1
57: e8 c4 03 00 00 call 420 <printf>
5c: 83 c4 10 add $0x10,%esp
exit();
5f: e8 4e 02 00 00 call 2b2 <exit>
64: 66 90 xchg %ax,%ax
66: 66 90 xchg %ax,%ax
68: 66 90 xchg %ax,%ax
6a: 66 90 xchg %ax,%ax
6c: 66 90 xchg %ax,%ax
6e: 66 90 xchg %ax,%ax
00000070 <strcpy>:
#include "user.h"
#include "x86.h"
char*
strcpy(char *s, char *t)
{
70: 55 push %ebp
71: 89 e5 mov %esp,%ebp
73: 53 push %ebx
74: 8b 45 08 mov 0x8(%ebp),%eax
77: 8b 4d 0c mov 0xc(%ebp),%ecx
char *os;
os = s;
while((*s++ = *t++) != 0)
7a: 89 c2 mov %eax,%edx
7c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
80: 83 c1 01 add $0x1,%ecx
83: 0f b6 59 ff movzbl -0x1(%ecx),%ebx
87: 83 c2 01 add $0x1,%edx
8a: 84 db test %bl,%bl
8c: 88 5a ff mov %bl,-0x1(%edx)
8f: 75 ef jne 80 <strcpy+0x10>
;
return os;
}
91: 5b pop %ebx
92: 5d pop %ebp
93: c3 ret
94: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
9a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
000000a0 <strcmp>:
int
strcmp(const char *p, const char *q)
{
a0: 55 push %ebp
a1: 89 e5 mov %esp,%ebp
a3: 56 push %esi
a4: 53 push %ebx
a5: 8b 55 08 mov 0x8(%ebp),%edx
a8: 8b 4d 0c mov 0xc(%ebp),%ecx
while(*p && *p == *q)
ab: 0f b6 02 movzbl (%edx),%eax
ae: 0f b6 19 movzbl (%ecx),%ebx
b1: 84 c0 test %al,%al
b3: 75 1e jne d3 <strcmp+0x33>
b5: eb 29 jmp e0 <strcmp+0x40>
b7: 89 f6 mov %esi,%esi
b9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
p++, q++;
c0: 83 c2 01 add $0x1,%edx
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
c3: 0f b6 02 movzbl (%edx),%eax
p++, q++;
c6: 8d 71 01 lea 0x1(%ecx),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
c9: 0f b6 59 01 movzbl 0x1(%ecx),%ebx
cd: 84 c0 test %al,%al
cf: 74 0f je e0 <strcmp+0x40>
d1: 89 f1 mov %esi,%ecx
d3: 38 d8 cmp %bl,%al
d5: 74 e9 je c0 <strcmp+0x20>
p++, q++;
return (uchar)*p - (uchar)*q;
d7: 29 d8 sub %ebx,%eax
}
d9: 5b pop %ebx
da: 5e pop %esi
db: 5d pop %ebp
dc: c3 ret
dd: 8d 76 00 lea 0x0(%esi),%esi
}
int
strcmp(const char *p, const char *q)
{
while(*p && *p == *q)
e0: 31 c0 xor %eax,%eax
p++, q++;
return (uchar)*p - (uchar)*q;
e2: 29 d8 sub %ebx,%eax
}
e4: 5b pop %ebx
e5: 5e pop %esi
e6: 5d pop %ebp
e7: c3 ret
e8: 90 nop
e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
000000f0 <strlen>:
uint
strlen(char *s)
{
f0: 55 push %ebp
f1: 89 e5 mov %esp,%ebp
f3: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
for(n = 0; s[n]; n++)
f6: 80 39 00 cmpb $0x0,(%ecx)
f9: 74 12 je 10d <strlen+0x1d>
fb: 31 d2 xor %edx,%edx
fd: 8d 76 00 lea 0x0(%esi),%esi
100: 83 c2 01 add $0x1,%edx
103: 80 3c 11 00 cmpb $0x0,(%ecx,%edx,1)
107: 89 d0 mov %edx,%eax
109: 75 f5 jne 100 <strlen+0x10>
;
return n;
}
10b: 5d pop %ebp
10c: c3 ret
uint
strlen(char *s)
{
int n;
for(n = 0; s[n]; n++)
10d: 31 c0 xor %eax,%eax
;
return n;
}
10f: 5d pop %ebp
110: c3 ret
111: eb 0d jmp 120 <memset>
113: 90 nop
114: 90 nop
115: 90 nop
116: 90 nop
117: 90 nop
118: 90 nop
119: 90 nop
11a: 90 nop
11b: 90 nop
11c: 90 nop
11d: 90 nop
11e: 90 nop
11f: 90 nop
00000120 <memset>:
void*
memset(void *dst, int c, uint n)
{
120: 55 push %ebp
121: 89 e5 mov %esp,%ebp
123: 57 push %edi
124: 8b 55 08 mov 0x8(%ebp),%edx
}
static inline void
stosb(void *addr, int data, int cnt)
{
asm volatile("cld; rep stosb" :
127: 8b 4d 10 mov 0x10(%ebp),%ecx
12a: 8b 45 0c mov 0xc(%ebp),%eax
12d: 89 d7 mov %edx,%edi
12f: fc cld
130: f3 aa rep stos %al,%es:(%edi)
stosb(dst, c, n);
return dst;
}
132: 89 d0 mov %edx,%eax
134: 5f pop %edi
135: 5d pop %ebp
136: c3 ret
137: 89 f6 mov %esi,%esi
139: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000140 <strchr>:
char*
strchr(const char *s, char c)
{
140: 55 push %ebp
141: 89 e5 mov %esp,%ebp
143: 53 push %ebx
144: 8b 45 08 mov 0x8(%ebp),%eax
147: 8b 5d 0c mov 0xc(%ebp),%ebx
for(; *s; s++)
14a: 0f b6 10 movzbl (%eax),%edx
14d: 84 d2 test %dl,%dl
14f: 74 1d je 16e <strchr+0x2e>
if(*s == c)
151: 38 d3 cmp %dl,%bl
153: 89 d9 mov %ebx,%ecx
155: 75 0d jne 164 <strchr+0x24>
157: eb 17 jmp 170 <strchr+0x30>
159: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
160: 38 ca cmp %cl,%dl
162: 74 0c je 170 <strchr+0x30>
}
char*
strchr(const char *s, char c)
{
for(; *s; s++)
164: 83 c0 01 add $0x1,%eax
167: 0f b6 10 movzbl (%eax),%edx
16a: 84 d2 test %dl,%dl
16c: 75 f2 jne 160 <strchr+0x20>
if(*s == c)
return (char*)s;
return 0;
16e: 31 c0 xor %eax,%eax
}
170: 5b pop %ebx
171: 5d pop %ebp
172: c3 ret
173: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
179: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000180 <gets>:
char*
gets(char *buf, int max)
{
180: 55 push %ebp
181: 89 e5 mov %esp,%ebp
183: 57 push %edi
184: 56 push %esi
185: 53 push %ebx
int i, cc;
char c;
for(i=0; i+1 < max; ){
186: 31 f6 xor %esi,%esi
cc = read(0, &c, 1);
188: 8d 7d e7 lea -0x19(%ebp),%edi
return 0;
}
char*
gets(char *buf, int max)
{
18b: 83 ec 1c sub $0x1c,%esp
int i, cc;
char c;
for(i=0; i+1 < max; ){
18e: eb 29 jmp 1b9 <gets+0x39>
cc = read(0, &c, 1);
190: 83 ec 04 sub $0x4,%esp
193: 6a 01 push $0x1
195: 57 push %edi
196: 6a 00 push $0x0
198: e8 2d 01 00 00 call 2ca <read>
if(cc < 1)
19d: 83 c4 10 add $0x10,%esp
1a0: 85 c0 test %eax,%eax
1a2: 7e 1d jle 1c1 <gets+0x41>
break;
buf[i++] = c;
1a4: 0f b6 45 e7 movzbl -0x19(%ebp),%eax
1a8: 8b 55 08 mov 0x8(%ebp),%edx
1ab: 89 de mov %ebx,%esi
if(c == '\n' || c == '\r')
1ad: 3c 0a cmp $0xa,%al
for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
buf[i++] = c;
1af: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1)
if(c == '\n' || c == '\r')
1b3: 74 1b je 1d0 <gets+0x50>
1b5: 3c 0d cmp $0xd,%al
1b7: 74 17 je 1d0 <gets+0x50>
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1b9: 8d 5e 01 lea 0x1(%esi),%ebx
1bc: 3b 5d 0c cmp 0xc(%ebp),%ebx
1bf: 7c cf jl 190 <gets+0x10>
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1c1: 8b 45 08 mov 0x8(%ebp),%eax
1c4: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1c8: 8d 65 f4 lea -0xc(%ebp),%esp
1cb: 5b pop %ebx
1cc: 5e pop %esi
1cd: 5f pop %edi
1ce: 5d pop %ebp
1cf: c3 ret
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1d0: 8b 45 08 mov 0x8(%ebp),%eax
gets(char *buf, int max)
{
int i, cc;
char c;
for(i=0; i+1 < max; ){
1d3: 89 de mov %ebx,%esi
break;
buf[i++] = c;
if(c == '\n' || c == '\r')
break;
}
buf[i] = '\0';
1d5: c6 04 30 00 movb $0x0,(%eax,%esi,1)
return buf;
}
1d9: 8d 65 f4 lea -0xc(%ebp),%esp
1dc: 5b pop %ebx
1dd: 5e pop %esi
1de: 5f pop %edi
1df: 5d pop %ebp
1e0: c3 ret
1e1: eb 0d jmp 1f0 <stat>
1e3: 90 nop
1e4: 90 nop
1e5: 90 nop
1e6: 90 nop
1e7: 90 nop
1e8: 90 nop
1e9: 90 nop
1ea: 90 nop
1eb: 90 nop
1ec: 90 nop
1ed: 90 nop
1ee: 90 nop
1ef: 90 nop
000001f0 <stat>:
int
stat(char *n, struct stat *st)
{
1f0: 55 push %ebp
1f1: 89 e5 mov %esp,%ebp
1f3: 56 push %esi
1f4: 53 push %ebx
int fd;
int r;
fd = open(n, O_RDONLY);
1f5: 83 ec 08 sub $0x8,%esp
1f8: 6a 00 push $0x0
1fa: ff 75 08 pushl 0x8(%ebp)
1fd: e8 f0 00 00 00 call 2f2 <open>
if(fd < 0)
202: 83 c4 10 add $0x10,%esp
205: 85 c0 test %eax,%eax
207: 78 27 js 230 <stat+0x40>
return -1;
r = fstat(fd, st);
209: 83 ec 08 sub $0x8,%esp
20c: ff 75 0c pushl 0xc(%ebp)
20f: 89 c3 mov %eax,%ebx
211: 50 push %eax
212: e8 f3 00 00 00 call 30a <fstat>
217: 89 c6 mov %eax,%esi
close(fd);
219: 89 1c 24 mov %ebx,(%esp)
21c: e8 b9 00 00 00 call 2da <close>
return r;
221: 83 c4 10 add $0x10,%esp
224: 89 f0 mov %esi,%eax
}
226: 8d 65 f8 lea -0x8(%ebp),%esp
229: 5b pop %ebx
22a: 5e pop %esi
22b: 5d pop %ebp
22c: c3 ret
22d: 8d 76 00 lea 0x0(%esi),%esi
int fd;
int r;
fd = open(n, O_RDONLY);
if(fd < 0)
return -1;
230: b8 ff ff ff ff mov $0xffffffff,%eax
235: eb ef jmp 226 <stat+0x36>
237: 89 f6 mov %esi,%esi
239: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000240 <atoi>:
return r;
}
int
atoi(const char *s)
{
240: 55 push %ebp
241: 89 e5 mov %esp,%ebp
243: 53 push %ebx
244: 8b 4d 08 mov 0x8(%ebp),%ecx
int n;
n = 0;
while('0' <= *s && *s <= '9')
247: 0f be 11 movsbl (%ecx),%edx
24a: 8d 42 d0 lea -0x30(%edx),%eax
24d: 3c 09 cmp $0x9,%al
24f: b8 00 00 00 00 mov $0x0,%eax
254: 77 1f ja 275 <atoi+0x35>
256: 8d 76 00 lea 0x0(%esi),%esi
259: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
n = n*10 + *s++ - '0';
260: 8d 04 80 lea (%eax,%eax,4),%eax
263: 83 c1 01 add $0x1,%ecx
266: 8d 44 42 d0 lea -0x30(%edx,%eax,2),%eax
atoi(const char *s)
{
int n;
n = 0;
while('0' <= *s && *s <= '9')
26a: 0f be 11 movsbl (%ecx),%edx
26d: 8d 5a d0 lea -0x30(%edx),%ebx
270: 80 fb 09 cmp $0x9,%bl
273: 76 eb jbe 260 <atoi+0x20>
n = n*10 + *s++ - '0';
return n;
}
275: 5b pop %ebx
276: 5d pop %ebp
277: c3 ret
278: 90 nop
279: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi
00000280 <memmove>:
void*
memmove(void *vdst, void *vsrc, int n)
{
280: 55 push %ebp
281: 89 e5 mov %esp,%ebp
283: 56 push %esi
284: 53 push %ebx
285: 8b 5d 10 mov 0x10(%ebp),%ebx
288: 8b 45 08 mov 0x8(%ebp),%eax
28b: 8b 75 0c mov 0xc(%ebp),%esi
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
28e: 85 db test %ebx,%ebx
290: 7e 14 jle 2a6 <memmove+0x26>
292: 31 d2 xor %edx,%edx
294: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
*dst++ = *src++;
298: 0f b6 0c 16 movzbl (%esi,%edx,1),%ecx
29c: 88 0c 10 mov %cl,(%eax,%edx,1)
29f: 83 c2 01 add $0x1,%edx
{
char *dst, *src;
dst = vdst;
src = vsrc;
while(n-- > 0)
2a2: 39 da cmp %ebx,%edx
2a4: 75 f2 jne 298 <memmove+0x18>
*dst++ = *src++;
return vdst;
}
2a6: 5b pop %ebx
2a7: 5e pop %esi
2a8: 5d pop %ebp
2a9: c3 ret
000002aa <fork>:
name: \
movl $SYS_ ## name, %eax; \
int $T_SYSCALL; \
ret
SYSCALL(fork)
2aa: b8 01 00 00 00 mov $0x1,%eax
2af: cd 40 int $0x40
2b1: c3 ret
000002b2 <exit>:
SYSCALL(exit)
2b2: b8 02 00 00 00 mov $0x2,%eax
2b7: cd 40 int $0x40
2b9: c3 ret
000002ba <wait>:
SYSCALL(wait)
2ba: b8 03 00 00 00 mov $0x3,%eax
2bf: cd 40 int $0x40
2c1: c3 ret
000002c2 <pipe>:
SYSCALL(pipe)
2c2: b8 04 00 00 00 mov $0x4,%eax
2c7: cd 40 int $0x40
2c9: c3 ret
000002ca <read>:
SYSCALL(read)
2ca: b8 05 00 00 00 mov $0x5,%eax
2cf: cd 40 int $0x40
2d1: c3 ret
000002d2 <write>:
SYSCALL(write)
2d2: b8 10 00 00 00 mov $0x10,%eax
2d7: cd 40 int $0x40
2d9: c3 ret
000002da <close>:
SYSCALL(close)
2da: b8 15 00 00 00 mov $0x15,%eax
2df: cd 40 int $0x40
2e1: c3 ret
000002e2 <kill>:
SYSCALL(kill)
2e2: b8 06 00 00 00 mov $0x6,%eax
2e7: cd 40 int $0x40
2e9: c3 ret
000002ea <exec>:
SYSCALL(exec)
2ea: b8 07 00 00 00 mov $0x7,%eax
2ef: cd 40 int $0x40
2f1: c3 ret
000002f2 <open>:
SYSCALL(open)
2f2: b8 0f 00 00 00 mov $0xf,%eax
2f7: cd 40 int $0x40
2f9: c3 ret
000002fa <mknod>:
SYSCALL(mknod)
2fa: b8 11 00 00 00 mov $0x11,%eax
2ff: cd 40 int $0x40
301: c3 ret
00000302 <unlink>:
SYSCALL(unlink)
302: b8 12 00 00 00 mov $0x12,%eax
307: cd 40 int $0x40
309: c3 ret
0000030a <fstat>:
SYSCALL(fstat)
30a: b8 08 00 00 00 mov $0x8,%eax
30f: cd 40 int $0x40
311: c3 ret
00000312 <link>:
SYSCALL(link)
312: b8 13 00 00 00 mov $0x13,%eax
317: cd 40 int $0x40
319: c3 ret
0000031a <mkdir>:
SYSCALL(mkdir)
31a: b8 14 00 00 00 mov $0x14,%eax
31f: cd 40 int $0x40
321: c3 ret
00000322 <chdir>:
SYSCALL(chdir)
322: b8 09 00 00 00 mov $0x9,%eax
327: cd 40 int $0x40
329: c3 ret
0000032a <dup>:
SYSCALL(dup)
32a: b8 0a 00 00 00 mov $0xa,%eax
32f: cd 40 int $0x40
331: c3 ret
00000332 <getpid>:
SYSCALL(getpid)
332: b8 0b 00 00 00 mov $0xb,%eax
337: cd 40 int $0x40
339: c3 ret
0000033a <sbrk>:
SYSCALL(sbrk)
33a: b8 0c 00 00 00 mov $0xc,%eax
33f: cd 40 int $0x40
341: c3 ret
00000342 <sleep>:
SYSCALL(sleep)
342: b8 0d 00 00 00 mov $0xd,%eax
347: cd 40 int $0x40
349: c3 ret
0000034a <uptime>:
SYSCALL(uptime)
34a: b8 0e 00 00 00 mov $0xe,%eax
34f: cd 40 int $0x40
351: c3 ret
00000352 <signal>:
/* assignment 2 adding code */
SYSCALL(signal)
352: b8 16 00 00 00 mov $0x16,%eax
357: cd 40 int $0x40
359: c3 ret
0000035a <sigsend>:
SYSCALL(sigsend)
35a: b8 17 00 00 00 mov $0x17,%eax
35f: cd 40 int $0x40
361: c3 ret
00000362 <sigreturn>:
SYSCALL(sigreturn)
362: b8 18 00 00 00 mov $0x18,%eax
367: cd 40 int $0x40
369: c3 ret
0000036a <alarm>:
SYSCALL(alarm)
36a: b8 19 00 00 00 mov $0x19,%eax
36f: cd 40 int $0x40
371: c3 ret
372: 66 90 xchg %ax,%ax
374: 66 90 xchg %ax,%ax
376: 66 90 xchg %ax,%ax
378: 66 90 xchg %ax,%ax
37a: 66 90 xchg %ax,%ax
37c: 66 90 xchg %ax,%ax
37e: 66 90 xchg %ax,%ax
00000380 <printint>:
write(fd, &c, 1);
}
static void
printint(int fd, int xx, int base, int sgn)
{
380: 55 push %ebp
381: 89 e5 mov %esp,%ebp
383: 57 push %edi
384: 56 push %esi
385: 53 push %ebx
386: 89 c6 mov %eax,%esi
388: 83 ec 3c sub $0x3c,%esp
char buf[16];
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
38b: 8b 5d 08 mov 0x8(%ebp),%ebx
38e: 85 db test %ebx,%ebx
390: 74 7e je 410 <printint+0x90>
392: 89 d0 mov %edx,%eax
394: c1 e8 1f shr $0x1f,%eax
397: 84 c0 test %al,%al
399: 74 75 je 410 <printint+0x90>
neg = 1;
x = -xx;
39b: 89 d0 mov %edx,%eax
int i, neg;
uint x;
neg = 0;
if(sgn && xx < 0){
neg = 1;
39d: c7 45 c4 01 00 00 00 movl $0x1,-0x3c(%ebp)
x = -xx;
3a4: f7 d8 neg %eax
3a6: 89 75 c0 mov %esi,-0x40(%ebp)
} else {
x = xx;
}
i = 0;
3a9: 31 ff xor %edi,%edi
3ab: 8d 5d d7 lea -0x29(%ebp),%ebx
3ae: 89 ce mov %ecx,%esi
3b0: eb 08 jmp 3ba <printint+0x3a>
3b2: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
do{
buf[i++] = digits[x % base];
3b8: 89 cf mov %ecx,%edi
3ba: 31 d2 xor %edx,%edx
3bc: 8d 4f 01 lea 0x1(%edi),%ecx
3bf: f7 f6 div %esi
3c1: 0f b6 92 1c 12 00 00 movzbl 0x121c(%edx),%edx
}while((x /= base) != 0);
3c8: 85 c0 test %eax,%eax
x = xx;
}
i = 0;
do{
buf[i++] = digits[x % base];
3ca: 88 14 0b mov %dl,(%ebx,%ecx,1)
}while((x /= base) != 0);
3cd: 75 e9 jne 3b8 <printint+0x38>
if(neg)
3cf: 8b 45 c4 mov -0x3c(%ebp),%eax
3d2: 8b 75 c0 mov -0x40(%ebp),%esi
3d5: 85 c0 test %eax,%eax
3d7: 74 08 je 3e1 <printint+0x61>
buf[i++] = '-';
3d9: c6 44 0d d8 2d movb $0x2d,-0x28(%ebp,%ecx,1)
3de: 8d 4f 02 lea 0x2(%edi),%ecx
3e1: 8d 7c 0d d7 lea -0x29(%ebp,%ecx,1),%edi
3e5: 8d 76 00 lea 0x0(%esi),%esi
3e8: 0f b6 07 movzbl (%edi),%eax
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
3eb: 83 ec 04 sub $0x4,%esp
3ee: 83 ef 01 sub $0x1,%edi
3f1: 6a 01 push $0x1
3f3: 53 push %ebx
3f4: 56 push %esi
3f5: 88 45 d7 mov %al,-0x29(%ebp)
3f8: e8 d5 fe ff ff call 2d2 <write>
buf[i++] = digits[x % base];
}while((x /= base) != 0);
if(neg)
buf[i++] = '-';
while(--i >= 0)
3fd: 83 c4 10 add $0x10,%esp
400: 39 df cmp %ebx,%edi
402: 75 e4 jne 3e8 <printint+0x68>
putc(fd, buf[i]);
}
404: 8d 65 f4 lea -0xc(%ebp),%esp
407: 5b pop %ebx
408: 5e pop %esi
409: 5f pop %edi
40a: 5d pop %ebp
40b: c3 ret
40c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
neg = 0;
if(sgn && xx < 0){
neg = 1;
x = -xx;
} else {
x = xx;
410: 89 d0 mov %edx,%eax
static char digits[] = "0123456789ABCDEF";
char buf[16];
int i, neg;
uint x;
neg = 0;
412: c7 45 c4 00 00 00 00 movl $0x0,-0x3c(%ebp)
419: eb 8b jmp 3a6 <printint+0x26>
41b: 90 nop
41c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi
00000420 <printf>:
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
420: 55 push %ebp
421: 89 e5 mov %esp,%ebp
423: 57 push %edi
424: 56 push %esi
425: 53 push %ebx
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
426: 8d 45 10 lea 0x10(%ebp),%eax
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
429: 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++){
42c: 8b 75 0c mov 0xc(%ebp),%esi
}
// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
42f: 8b 7d 08 mov 0x8(%ebp),%edi
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
432: 89 45 d0 mov %eax,-0x30(%ebp)
435: 0f b6 1e movzbl (%esi),%ebx
438: 83 c6 01 add $0x1,%esi
43b: 84 db test %bl,%bl
43d: 0f 84 b0 00 00 00 je 4f3 <printf+0xd3>
443: 31 d2 xor %edx,%edx
445: eb 39 jmp 480 <printf+0x60>
447: 89 f6 mov %esi,%esi
449: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
450: 83 f8 25 cmp $0x25,%eax
453: 89 55 d4 mov %edx,-0x2c(%ebp)
state = '%';
456: ba 25 00 00 00 mov $0x25,%edx
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
if(c == '%'){
45b: 74 18 je 475 <printf+0x55>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
45d: 8d 45 e2 lea -0x1e(%ebp),%eax
460: 83 ec 04 sub $0x4,%esp
463: 88 5d e2 mov %bl,-0x1e(%ebp)
466: 6a 01 push $0x1
468: 50 push %eax
469: 57 push %edi
46a: e8 63 fe ff ff call 2d2 <write>
46f: 8b 55 d4 mov -0x2c(%ebp),%edx
472: 83 c4 10 add $0x10,%esp
475: 83 c6 01 add $0x1,%esi
int c, i, state;
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
478: 0f b6 5e ff movzbl -0x1(%esi),%ebx
47c: 84 db test %bl,%bl
47e: 74 73 je 4f3 <printf+0xd3>
c = fmt[i] & 0xff;
if(state == 0){
480: 85 d2 test %edx,%edx
uint *ap;
state = 0;
ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
482: 0f be cb movsbl %bl,%ecx
485: 0f b6 c3 movzbl %bl,%eax
if(state == 0){
488: 74 c6 je 450 <printf+0x30>
if(c == '%'){
state = '%';
} else {
putc(fd, c);
}
} else if(state == '%'){
48a: 83 fa 25 cmp $0x25,%edx
48d: 75 e6 jne 475 <printf+0x55>
if(c == 'd'){
48f: 83 f8 64 cmp $0x64,%eax
492: 0f 84 f8 00 00 00 je 590 <printf+0x170>
printint(fd, *ap, 10, 1);
ap++;
} else if(c == 'x' || c == 'p'){
498: 81 e1 f7 00 00 00 and $0xf7,%ecx
49e: 83 f9 70 cmp $0x70,%ecx
4a1: 74 5d je 500 <printf+0xe0>
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
4a3: 83 f8 73 cmp $0x73,%eax
4a6: 0f 84 84 00 00 00 je 530 <printf+0x110>
s = "(null)";
while(*s != 0){
putc(fd, *s);
s++;
}
} else if(c == 'c'){
4ac: 83 f8 63 cmp $0x63,%eax
4af: 0f 84 ea 00 00 00 je 59f <printf+0x17f>
putc(fd, *ap);
ap++;
} else if(c == '%'){
4b5: 83 f8 25 cmp $0x25,%eax
4b8: 0f 84 c2 00 00 00 je 580 <printf+0x160>
#include "user.h"
static void
putc(int fd, char c)
{
write(fd, &c, 1);
4be: 8d 45 e7 lea -0x19(%ebp),%eax
4c1: 83 ec 04 sub $0x4,%esp
4c4: c6 45 e7 25 movb $0x25,-0x19(%ebp)
4c8: 6a 01 push $0x1
4ca: 50 push %eax
4cb: 57 push %edi
4cc: e8 01 fe ff ff call 2d2 <write>
4d1: 83 c4 0c add $0xc,%esp
4d4: 8d 45 e6 lea -0x1a(%ebp),%eax
4d7: 88 5d e6 mov %bl,-0x1a(%ebp)
4da: 6a 01 push $0x1
4dc: 50 push %eax