_ls: file format elf32-i386 Disassembly of section .text: 00000000
: close(fd); } 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 push -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: bb 01 00 00 00 mov $0x1,%ebx 15: 51 push %ecx 16: 83 ec 08 sub $0x8,%esp 19: 8b 31 mov (%ecx),%esi 1b: 8b 79 04 mov 0x4(%ecx),%edi int i; if(argc < 2){ 1e: 83 fe 01 cmp $0x1,%esi 21: 7e 1f jle 42 23: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 27: 90 nop ls("."); exit(); } for(i=1; i for(i=1; i exit(); 3d: e8 51 05 00 00 call 593 ls("."); 42: 83 ec 0c sub $0xc,%esp 45: 68 80 0a 00 00 push $0xa80 4a: e8 b1 00 00 00 call 100 exit(); 4f: e8 3f 05 00 00 call 593 54: 66 90 xchg %ax,%ax 56: 66 90 xchg %ax,%ax 58: 66 90 xchg %ax,%ax 5a: 66 90 xchg %ax,%ax 5c: 66 90 xchg %ax,%ax 5e: 66 90 xchg %ax,%ax 00000060 : { 60: 55 push %ebp 61: 89 e5 mov %esp,%ebp 63: 56 push %esi 64: 53 push %ebx 65: 8b 75 08 mov 0x8(%ebp),%esi for(p=path+strlen(path); p >= path && *p != '/'; p--) 68: 83 ec 0c sub $0xc,%esp 6b: 56 push %esi 6c: e8 5f 03 00 00 call 3d0 71: 83 c4 10 add $0x10,%esp 74: 01 f0 add %esi,%eax 76: 89 c3 mov %eax,%ebx 78: 73 0f jae 89 7a: eb 12 jmp 8e 7c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 80: 8d 43 ff lea -0x1(%ebx),%eax 83: 39 c6 cmp %eax,%esi 85: 77 0a ja 91 87: 89 c3 mov %eax,%ebx 89: 80 3b 2f cmpb $0x2f,(%ebx) 8c: 75 f2 jne 80 p++; 8e: 83 c3 01 add $0x1,%ebx if(strlen(p) >= DIRSIZ) 91: 83 ec 0c sub $0xc,%esp 94: 53 push %ebx 95: e8 36 03 00 00 call 3d0 9a: 83 c4 10 add $0x10,%esp 9d: 83 f8 0d cmp $0xd,%eax a0: 77 4a ja ec memmove(buf, p, strlen(p)); a2: 83 ec 0c sub $0xc,%esp a5: 53 push %ebx a6: e8 25 03 00 00 call 3d0 ab: 83 c4 0c add $0xc,%esp ae: 50 push %eax af: 53 push %ebx b0: 68 14 0e 00 00 push $0xe14 b5: e8 a6 04 00 00 call 560 memset(buf+strlen(p), ' ', DIRSIZ-strlen(p)); ba: 89 1c 24 mov %ebx,(%esp) bd: e8 0e 03 00 00 call 3d0 c2: 89 1c 24 mov %ebx,(%esp) return buf; c5: bb 14 0e 00 00 mov $0xe14,%ebx memset(buf+strlen(p), ' ', DIRSIZ-strlen(p)); ca: 89 c6 mov %eax,%esi cc: e8 ff 02 00 00 call 3d0 d1: ba 0e 00 00 00 mov $0xe,%edx d6: 83 c4 0c add $0xc,%esp d9: 29 f2 sub %esi,%edx db: 05 14 0e 00 00 add $0xe14,%eax e0: 52 push %edx e1: 6a 20 push $0x20 e3: 50 push %eax e4: e8 17 03 00 00 call 400 return buf; e9: 83 c4 10 add $0x10,%esp } ec: 8d 65 f8 lea -0x8(%ebp),%esp ef: 89 d8 mov %ebx,%eax f1: 5b pop %ebx f2: 5e pop %esi f3: 5d pop %ebp f4: c3 ret f5: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000100 : { 100: 55 push %ebp 101: 89 e5 mov %esp,%ebp 103: 57 push %edi 104: 56 push %esi 105: 53 push %ebx 106: 81 ec 64 02 00 00 sub $0x264,%esp 10c: 8b 7d 08 mov 0x8(%ebp),%edi if((fd = open(path, 0)) < 0){ 10f: 6a 00 push $0x0 111: 57 push %edi 112: e8 e4 04 00 00 call 5fb 117: 83 c4 10 add $0x10,%esp 11a: 85 c0 test %eax,%eax 11c: 0f 88 9e 01 00 00 js 2c0 if(fstat(fd, &st) < 0){ 122: 83 ec 08 sub $0x8,%esp 125: 8d b5 d4 fd ff ff lea -0x22c(%ebp),%esi 12b: 89 c3 mov %eax,%ebx 12d: 56 push %esi 12e: 50 push %eax 12f: e8 8f 04 00 00 call 5c3 134: 83 c4 10 add $0x10,%esp 137: 85 c0 test %eax,%eax 139: 0f 88 c1 01 00 00 js 300 switch(st.type){ 13f: 0f b7 85 d4 fd ff ff movzwl -0x22c(%ebp),%eax 146: 66 83 f8 01 cmp $0x1,%ax 14a: 74 64 je 1b0 14c: 66 83 f8 02 cmp $0x2,%ax 150: 74 1e je 170 close(fd); 152: 83 ec 0c sub $0xc,%esp 155: 53 push %ebx 156: e8 d0 04 00 00 call 62b 15b: 83 c4 10 add $0x10,%esp } 15e: 8d 65 f4 lea -0xc(%ebp),%esp 161: 5b pop %ebx 162: 5e pop %esi 163: 5f pop %edi 164: 5d pop %ebp 165: c3 ret 166: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 16d: 8d 76 00 lea 0x0(%esi),%esi printf(1, "%s %d %d %d\n", fmtname(path), st.type, st.ino, st.size); 170: 83 ec 0c sub $0xc,%esp 173: 8b 95 e4 fd ff ff mov -0x21c(%ebp),%edx 179: 8b b5 dc fd ff ff mov -0x224(%ebp),%esi 17f: 57 push %edi 180: 89 95 b4 fd ff ff mov %edx,-0x24c(%ebp) 186: e8 d5 fe ff ff call 60 18b: 8b 95 b4 fd ff ff mov -0x24c(%ebp),%edx 191: 59 pop %ecx 192: 5f pop %edi 193: 52 push %edx 194: 56 push %esi 195: 6a 02 push $0x2 197: 50 push %eax 198: 68 60 0a 00 00 push $0xa60 19d: 6a 01 push $0x1 19f: e8 6c 05 00 00 call 710 break; 1a4: 83 c4 20 add $0x20,%esp 1a7: eb a9 jmp 152 1a9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi if(strlen(path) + 1 + DIRSIZ + 1 > sizeof buf){ 1b0: 83 ec 0c sub $0xc,%esp 1b3: 57 push %edi 1b4: e8 17 02 00 00 call 3d0 1b9: 83 c4 10 add $0x10,%esp 1bc: 83 c0 10 add $0x10,%eax 1bf: 3d 00 02 00 00 cmp $0x200,%eax 1c4: 0f 87 16 01 00 00 ja 2e0 strcpy(buf, path); 1ca: 83 ec 08 sub $0x8,%esp 1cd: 57 push %edi 1ce: 8d bd e8 fd ff ff lea -0x218(%ebp),%edi 1d4: 57 push %edi 1d5: e8 66 01 00 00 call 340 p = buf+strlen(buf); 1da: 89 3c 24 mov %edi,(%esp) 1dd: e8 ee 01 00 00 call 3d0 while(read(fd, &de, sizeof(de)) == sizeof(de)){ 1e2: 83 c4 10 add $0x10,%esp p = buf+strlen(buf); 1e5: 01 f8 add %edi,%eax *p++ = '/'; 1e7: 8d 48 01 lea 0x1(%eax),%ecx p = buf+strlen(buf); 1ea: 89 85 a8 fd ff ff mov %eax,-0x258(%ebp) *p++ = '/'; 1f0: 89 8d a4 fd ff ff mov %ecx,-0x25c(%ebp) 1f6: c6 00 2f movb $0x2f,(%eax) while(read(fd, &de, sizeof(de)) == sizeof(de)){ 1f9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 200: 83 ec 04 sub $0x4,%esp 203: 8d 85 c4 fd ff ff lea -0x23c(%ebp),%eax 209: 6a 10 push $0x10 20b: 50 push %eax 20c: 53 push %ebx 20d: e8 99 03 00 00 call 5ab 212: 83 c4 10 add $0x10,%esp 215: 83 f8 10 cmp $0x10,%eax 218: 0f 85 34 ff ff ff jne 152 if(de.inum == 0) 21e: 66 83 bd c4 fd ff ff cmpw $0x0,-0x23c(%ebp) 225: 00 226: 74 d8 je 200 memmove(p, de.name, DIRSIZ); 228: 83 ec 04 sub $0x4,%esp 22b: 8d 85 c6 fd ff ff lea -0x23a(%ebp),%eax 231: 6a 0e push $0xe 233: 50 push %eax 234: ff b5 a4 fd ff ff push -0x25c(%ebp) 23a: e8 21 03 00 00 call 560 p[DIRSIZ] = 0; 23f: 8b 85 a8 fd ff ff mov -0x258(%ebp),%eax 245: c6 40 0f 00 movb $0x0,0xf(%eax) if(stat(buf, &st) < 0){ 249: 58 pop %eax 24a: 5a pop %edx 24b: 56 push %esi 24c: 57 push %edi 24d: e8 7e 02 00 00 call 4d0 252: 83 c4 10 add $0x10,%esp 255: 85 c0 test %eax,%eax 257: 0f 88 cb 00 00 00 js 328 printf(1, "%s %d %d %d\n", fmtname(buf), st.type, st.ino, st.size); 25d: 83 ec 0c sub $0xc,%esp 260: 8b 8d e4 fd ff ff mov -0x21c(%ebp),%ecx 266: 8b 95 dc fd ff ff mov -0x224(%ebp),%edx 26c: 57 push %edi 26d: 0f bf 85 d4 fd ff ff movswl -0x22c(%ebp),%eax 274: 89 8d ac fd ff ff mov %ecx,-0x254(%ebp) 27a: 89 95 b0 fd ff ff mov %edx,-0x250(%ebp) 280: 89 85 b4 fd ff ff mov %eax,-0x24c(%ebp) 286: e8 d5 fd ff ff call 60 28b: 5a pop %edx 28c: 8b 95 b0 fd ff ff mov -0x250(%ebp),%edx 292: 59 pop %ecx 293: 8b 8d ac fd ff ff mov -0x254(%ebp),%ecx 299: 51 push %ecx 29a: 52 push %edx 29b: ff b5 b4 fd ff ff push -0x24c(%ebp) 2a1: 50 push %eax 2a2: 68 60 0a 00 00 push $0xa60 2a7: 6a 01 push $0x1 2a9: e8 62 04 00 00 call 710 2ae: 83 c4 20 add $0x20,%esp 2b1: e9 4a ff ff ff jmp 200 2b6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 2bd: 8d 76 00 lea 0x0(%esi),%esi printf(2, "ls: cannot open %s\n", path); 2c0: 83 ec 04 sub $0x4,%esp 2c3: 57 push %edi 2c4: 68 38 0a 00 00 push $0xa38 2c9: 6a 02 push $0x2 2cb: e8 40 04 00 00 call 710 return; 2d0: 83 c4 10 add $0x10,%esp } 2d3: 8d 65 f4 lea -0xc(%ebp),%esp 2d6: 5b pop %ebx 2d7: 5e pop %esi 2d8: 5f pop %edi 2d9: 5d pop %ebp 2da: c3 ret 2db: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 2df: 90 nop printf(1, "ls: path too long\n"); 2e0: 83 ec 08 sub $0x8,%esp 2e3: 68 6d 0a 00 00 push $0xa6d 2e8: 6a 01 push $0x1 2ea: e8 21 04 00 00 call 710 break; 2ef: 83 c4 10 add $0x10,%esp 2f2: e9 5b fe ff ff jmp 152 2f7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 2fe: 66 90 xchg %ax,%ax printf(2, "ls: cannot stat %s\n", path); 300: 83 ec 04 sub $0x4,%esp 303: 57 push %edi 304: 68 4c 0a 00 00 push $0xa4c 309: 6a 02 push $0x2 30b: e8 00 04 00 00 call 710 close(fd); 310: 89 1c 24 mov %ebx,(%esp) 313: e8 13 03 00 00 call 62b return; 318: 83 c4 10 add $0x10,%esp } 31b: 8d 65 f4 lea -0xc(%ebp),%esp 31e: 5b pop %ebx 31f: 5e pop %esi 320: 5f pop %edi 321: 5d pop %ebp 322: c3 ret 323: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 327: 90 nop printf(1, "ls: cannot stat %s\n", buf); 328: 83 ec 04 sub $0x4,%esp 32b: 57 push %edi 32c: 68 4c 0a 00 00 push $0xa4c 331: 6a 01 push $0x1 333: e8 d8 03 00 00 call 710 continue; 338: 83 c4 10 add $0x10,%esp 33b: e9 c0 fe ff ff jmp 200 00000340 : #include "stat.h" #include "fcntl.h" #include "user.h" #include "x86.h" char*strcpy(char *s, const char *t) { 340: 55 push %ebp char *os; os = s; while ((*s++ = *t++) != 0) { 341: 31 c0 xor %eax,%eax char*strcpy(char *s, const char *t) { 343: 89 e5 mov %esp,%ebp 345: 53 push %ebx 346: 8b 4d 08 mov 0x8(%ebp),%ecx 349: 8b 5d 0c mov 0xc(%ebp),%ebx 34c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi while ((*s++ = *t++) != 0) { 350: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx 354: 88 14 01 mov %dl,(%ecx,%eax,1) 357: 83 c0 01 add $0x1,%eax 35a: 84 d2 test %dl,%dl 35c: 75 f2 jne 350 ; } return os; } 35e: 8b 5d fc mov -0x4(%ebp),%ebx 361: 89 c8 mov %ecx,%eax 363: c9 leave 364: c3 ret 365: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 36c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000370 : int strcmp(const char *p, const char *q) { 370: 55 push %ebp 371: 89 e5 mov %esp,%ebp 373: 53 push %ebx 374: 8b 55 08 mov 0x8(%ebp),%edx 377: 8b 4d 0c mov 0xc(%ebp),%ecx while (*p && *p == *q) { 37a: 0f b6 02 movzbl (%edx),%eax 37d: 84 c0 test %al,%al 37f: 75 17 jne 398 381: eb 3a jmp 3bd 383: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 387: 90 nop 388: 0f b6 42 01 movzbl 0x1(%edx),%eax p++, q++; 38c: 83 c2 01 add $0x1,%edx 38f: 8d 59 01 lea 0x1(%ecx),%ebx while (*p && *p == *q) { 392: 84 c0 test %al,%al 394: 74 1a je 3b0 p++, q++; 396: 89 d9 mov %ebx,%ecx while (*p && *p == *q) { 398: 0f b6 19 movzbl (%ecx),%ebx 39b: 38 c3 cmp %al,%bl 39d: 74 e9 je 388 } return (uchar) * p - (uchar) * q; 39f: 29 d8 sub %ebx,%eax } 3a1: 8b 5d fc mov -0x4(%ebp),%ebx 3a4: c9 leave 3a5: c3 ret 3a6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 3ad: 8d 76 00 lea 0x0(%esi),%esi return (uchar) * p - (uchar) * q; 3b0: 0f b6 59 01 movzbl 0x1(%ecx),%ebx 3b4: 31 c0 xor %eax,%eax 3b6: 29 d8 sub %ebx,%eax } 3b8: 8b 5d fc mov -0x4(%ebp),%ebx 3bb: c9 leave 3bc: c3 ret return (uchar) * p - (uchar) * q; 3bd: 0f b6 19 movzbl (%ecx),%ebx 3c0: 31 c0 xor %eax,%eax 3c2: eb db jmp 39f 3c4: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 3cb: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 3cf: 90 nop 000003d0 : uint strlen(const char *s) { 3d0: 55 push %ebp 3d1: 89 e5 mov %esp,%ebp 3d3: 8b 55 08 mov 0x8(%ebp),%edx int n; for (n = 0; s[n]; n++) { 3d6: 80 3a 00 cmpb $0x0,(%edx) 3d9: 74 15 je 3f0 3db: 31 c0 xor %eax,%eax 3dd: 8d 76 00 lea 0x0(%esi),%esi 3e0: 83 c0 01 add $0x1,%eax 3e3: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1) 3e7: 89 c1 mov %eax,%ecx 3e9: 75 f5 jne 3e0 ; } return n; } 3eb: 89 c8 mov %ecx,%eax 3ed: 5d pop %ebp 3ee: c3 ret 3ef: 90 nop for (n = 0; s[n]; n++) { 3f0: 31 c9 xor %ecx,%ecx } 3f2: 5d pop %ebp 3f3: 89 c8 mov %ecx,%eax 3f5: c3 ret 3f6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 3fd: 8d 76 00 lea 0x0(%esi),%esi 00000400 : void* memset(void *dst, int c, uint n) { 400: 55 push %ebp 401: 89 e5 mov %esp,%ebp 403: 57 push %edi 404: 8b 55 08 mov 0x8(%ebp),%edx "d" (port), "0" (addr), "1" (cnt) : "cc"); } static inline void stosb(void *addr, int data, int cnt) { asm volatile ("cld; rep stosb" : 407: 8b 4d 10 mov 0x10(%ebp),%ecx 40a: 8b 45 0c mov 0xc(%ebp),%eax 40d: 89 d7 mov %edx,%edi 40f: fc cld 410: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 412: 8b 7d fc mov -0x4(%ebp),%edi 415: 89 d0 mov %edx,%eax 417: c9 leave 418: c3 ret 419: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000420 : char* strchr(const char *s, char c) { 420: 55 push %ebp 421: 89 e5 mov %esp,%ebp 423: 8b 45 08 mov 0x8(%ebp),%eax 426: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx for (; *s; s++) { 42a: 0f b6 10 movzbl (%eax),%edx 42d: 84 d2 test %dl,%dl 42f: 75 12 jne 443 431: eb 1d jmp 450 433: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 437: 90 nop 438: 0f b6 50 01 movzbl 0x1(%eax),%edx 43c: 83 c0 01 add $0x1,%eax 43f: 84 d2 test %dl,%dl 441: 74 0d je 450 if (*s == c) { 443: 38 d1 cmp %dl,%cl 445: 75 f1 jne 438 return (char*)s; } } return 0; } 447: 5d pop %ebp 448: c3 ret 449: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return 0; 450: 31 c0 xor %eax,%eax } 452: 5d pop %ebp 453: c3 ret 454: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 45b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 45f: 90 nop 00000460 : char* gets(char *buf, int max) { 460: 55 push %ebp 461: 89 e5 mov %esp,%ebp 463: 57 push %edi 464: 56 push %esi int i, cc; char c; for (i = 0; i + 1 < max;) { cc = read(0, &c, 1); 465: 8d 7d e7 lea -0x19(%ebp),%edi char* gets(char *buf, int max) { 468: 53 push %ebx for (i = 0; i + 1 < max;) { 469: 31 db xor %ebx,%ebx char* gets(char *buf, int max) { 46b: 83 ec 1c sub $0x1c,%esp for (i = 0; i + 1 < max;) { 46e: eb 27 jmp 497 cc = read(0, &c, 1); 470: 83 ec 04 sub $0x4,%esp 473: 6a 01 push $0x1 475: 57 push %edi 476: 6a 00 push $0x0 478: e8 2e 01 00 00 call 5ab if (cc < 1) { 47d: 83 c4 10 add $0x10,%esp 480: 85 c0 test %eax,%eax 482: 7e 1d jle 4a1 break; } buf[i++] = c; 484: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 488: 8b 55 08 mov 0x8(%ebp),%edx 48b: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if (c == '\n' || c == '\r') { 48f: 3c 0a cmp $0xa,%al 491: 74 1d je 4b0 493: 3c 0d cmp $0xd,%al 495: 74 19 je 4b0 for (i = 0; i + 1 < max;) { 497: 89 de mov %ebx,%esi 499: 83 c3 01 add $0x1,%ebx 49c: 3b 5d 0c cmp 0xc(%ebp),%ebx 49f: 7c cf jl 470 break; } } buf[i] = '\0'; 4a1: 8b 45 08 mov 0x8(%ebp),%eax 4a4: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 4a8: 8d 65 f4 lea -0xc(%ebp),%esp 4ab: 5b pop %ebx 4ac: 5e pop %esi 4ad: 5f pop %edi 4ae: 5d pop %ebp 4af: c3 ret buf[i] = '\0'; 4b0: 8b 45 08 mov 0x8(%ebp),%eax 4b3: 89 de mov %ebx,%esi 4b5: c6 04 30 00 movb $0x0,(%eax,%esi,1) } 4b9: 8d 65 f4 lea -0xc(%ebp),%esp 4bc: 5b pop %ebx 4bd: 5e pop %esi 4be: 5f pop %edi 4bf: 5d pop %ebp 4c0: c3 ret 4c1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 4c8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 4cf: 90 nop 000004d0 : int stat(const char *n, struct stat *st) { 4d0: 55 push %ebp 4d1: 89 e5 mov %esp,%ebp 4d3: 56 push %esi 4d4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 4d5: 83 ec 08 sub $0x8,%esp 4d8: 6a 00 push $0x0 4da: ff 75 08 push 0x8(%ebp) 4dd: e8 19 01 00 00 call 5fb if (fd < 0) { 4e2: 83 c4 10 add $0x10,%esp 4e5: 85 c0 test %eax,%eax 4e7: 78 27 js 510 return -1; } r = fstat(fd, st); 4e9: 83 ec 08 sub $0x8,%esp 4ec: ff 75 0c push 0xc(%ebp) 4ef: 89 c3 mov %eax,%ebx 4f1: 50 push %eax 4f2: e8 cc 00 00 00 call 5c3 close(fd); 4f7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 4fa: 89 c6 mov %eax,%esi close(fd); 4fc: e8 2a 01 00 00 call 62b return r; 501: 83 c4 10 add $0x10,%esp } 504: 8d 65 f8 lea -0x8(%ebp),%esp 507: 89 f0 mov %esi,%eax 509: 5b pop %ebx 50a: 5e pop %esi 50b: 5d pop %ebp 50c: c3 ret 50d: 8d 76 00 lea 0x0(%esi),%esi return -1; 510: be ff ff ff ff mov $0xffffffff,%esi 515: eb ed jmp 504 517: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 51e: 66 90 xchg %ax,%ax 00000520 : int atoi(const char *s) { 520: 55 push %ebp 521: 89 e5 mov %esp,%ebp 523: 53 push %ebx 524: 8b 55 08 mov 0x8(%ebp),%edx int n; n = 0; while ('0' <= *s && *s <= '9') { 527: 0f be 02 movsbl (%edx),%eax 52a: 8d 48 d0 lea -0x30(%eax),%ecx 52d: 80 f9 09 cmp $0x9,%cl n = 0; 530: b9 00 00 00 00 mov $0x0,%ecx while ('0' <= *s && *s <= '9') { 535: 77 1e ja 555 537: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 53e: 66 90 xchg %ax,%ax n = n * 10 + *s++ - '0'; 540: 83 c2 01 add $0x1,%edx 543: 8d 0c 89 lea (%ecx,%ecx,4),%ecx 546: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx while ('0' <= *s && *s <= '9') { 54a: 0f be 02 movsbl (%edx),%eax 54d: 8d 58 d0 lea -0x30(%eax),%ebx 550: 80 fb 09 cmp $0x9,%bl 553: 76 eb jbe 540 } return n; } 555: 8b 5d fc mov -0x4(%ebp),%ebx 558: 89 c8 mov %ecx,%eax 55a: c9 leave 55b: c3 ret 55c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000560 : void* memmove(void *vdst, const void *vsrc, int n) { 560: 55 push %ebp 561: 89 e5 mov %esp,%ebp 563: 57 push %edi 564: 8b 45 10 mov 0x10(%ebp),%eax 567: 8b 55 08 mov 0x8(%ebp),%edx 56a: 56 push %esi 56b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while (n-- > 0) { 56e: 85 c0 test %eax,%eax 570: 7e 13 jle 585 572: 01 d0 add %edx,%eax dst = vdst; 574: 89 d7 mov %edx,%edi 576: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 57d: 8d 76 00 lea 0x0(%esi),%esi *dst++ = *src++; 580: a4 movsb %ds:(%esi),%es:(%edi) while (n-- > 0) { 581: 39 f8 cmp %edi,%eax 583: 75 fb jne 580 } return vdst; } 585: 5e pop %esi 586: 89 d0 mov %edx,%eax 588: 5f pop %edi 589: 5d pop %ebp 58a: c3 ret 0000058b : name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 58b: b8 01 00 00 00 mov $0x1,%eax 590: cd 40 int $0x40 592: c3 ret 00000593 : SYSCALL(exit) 593: b8 02 00 00 00 mov $0x2,%eax 598: cd 40 int $0x40 59a: c3 ret 0000059b : SYSCALL(wait) 59b: b8 03 00 00 00 mov $0x3,%eax 5a0: cd 40 int $0x40 5a2: c3 ret 000005a3 : SYSCALL(pipe) 5a3: b8 04 00 00 00 mov $0x4,%eax 5a8: cd 40 int $0x40 5aa: c3 ret 000005ab : SYSCALL(read) 5ab: b8 05 00 00 00 mov $0x5,%eax 5b0: cd 40 int $0x40 5b2: c3 ret 000005b3 : SYSCALL(kill) 5b3: b8 06 00 00 00 mov $0x6,%eax 5b8: cd 40 int $0x40 5ba: c3 ret 000005bb : SYSCALL(exec) 5bb: b8 07 00 00 00 mov $0x7,%eax 5c0: cd 40 int $0x40 5c2: c3 ret 000005c3 : SYSCALL(fstat) 5c3: b8 08 00 00 00 mov $0x8,%eax 5c8: cd 40 int $0x40 5ca: c3 ret 000005cb : SYSCALL(chdir) 5cb: b8 09 00 00 00 mov $0x9,%eax 5d0: cd 40 int $0x40 5d2: c3 ret 000005d3 : SYSCALL(dup) 5d3: b8 0a 00 00 00 mov $0xa,%eax 5d8: cd 40 int $0x40 5da: c3 ret 000005db : SYSCALL(getpid) 5db: b8 0b 00 00 00 mov $0xb,%eax 5e0: cd 40 int $0x40 5e2: c3 ret 000005e3 : SYSCALL(sbrk) 5e3: b8 0c 00 00 00 mov $0xc,%eax 5e8: cd 40 int $0x40 5ea: c3 ret 000005eb : SYSCALL(sleep) 5eb: b8 0d 00 00 00 mov $0xd,%eax 5f0: cd 40 int $0x40 5f2: c3 ret 000005f3 : SYSCALL(uptime) 5f3: b8 0e 00 00 00 mov $0xe,%eax 5f8: cd 40 int $0x40 5fa: c3 ret 000005fb : SYSCALL(open) 5fb: b8 0f 00 00 00 mov $0xf,%eax 600: cd 40 int $0x40 602: c3 ret 00000603 : SYSCALL(write) 603: b8 10 00 00 00 mov $0x10,%eax 608: cd 40 int $0x40 60a: c3 ret 0000060b : SYSCALL(mknod) 60b: b8 11 00 00 00 mov $0x11,%eax 610: cd 40 int $0x40 612: c3 ret 00000613 : SYSCALL(unlink) 613: b8 12 00 00 00 mov $0x12,%eax 618: cd 40 int $0x40 61a: c3 ret 0000061b : SYSCALL(link) 61b: b8 13 00 00 00 mov $0x13,%eax 620: cd 40 int $0x40 622: c3 ret 00000623 : SYSCALL(mkdir) 623: b8 14 00 00 00 mov $0x14,%eax 628: cd 40 int $0x40 62a: c3 ret 0000062b : SYSCALL(close) 62b: b8 15 00 00 00 mov $0x15,%eax 630: cd 40 int $0x40 632: c3 ret 00000633 : SYSCALL(getch) 633: b8 16 00 00 00 mov $0x16,%eax 638: cd 40 int $0x40 63a: c3 ret 0000063b : SYSCALL(greeting) 63b: b8 17 00 00 00 mov $0x17,%eax 640: cd 40 int $0x40 642: c3 ret 00000643 : SYSCALL(shutdown) 643: b8 18 00 00 00 mov $0x18,%eax 648: cd 40 int $0x40 64a: c3 ret 0000064b : SYSCALL(screen) 64b: b8 19 00 00 00 mov $0x19,%eax 650: cd 40 int $0x40 652: c3 ret 00000653 : SYSCALL(cls) 653: b8 1a 00 00 00 mov $0x1a,%eax 658: cd 40 int $0x40 65a: c3 ret 65b: 66 90 xchg %ax,%ax 65d: 66 90 xchg %ax,%ax 65f: 90 nop 00000660 : static void putc(int fd, char c) { write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 660: 55 push %ebp 661: 89 e5 mov %esp,%ebp 663: 57 push %edi 664: 56 push %esi 665: 53 push %ebx 666: 83 ec 3c sub $0x3c,%esp 669: 89 4d c4 mov %ecx,-0x3c(%ebp) uint x; neg = 0; if (sgn && xx < 0) { neg = 1; x = -xx; 66c: 89 d1 mov %edx,%ecx static void printint(int fd, int xx, int base, int sgn) { 66e: 89 45 b8 mov %eax,-0x48(%ebp) if (sgn && xx < 0) { 671: 85 d2 test %edx,%edx 673: 0f 89 7f 00 00 00 jns 6f8 679: f6 45 08 01 testb $0x1,0x8(%ebp) 67d: 74 79 je 6f8 neg = 1; 67f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp) x = -xx; 686: f7 d9 neg %ecx } else { x = xx; } i = 0; 688: 31 db xor %ebx,%ebx 68a: 8d 75 d7 lea -0x29(%ebp),%esi 68d: 8d 76 00 lea 0x0(%esi),%esi do { buf[i++] = digits[x % base]; 690: 89 c8 mov %ecx,%eax 692: 31 d2 xor %edx,%edx 694: 89 cf mov %ecx,%edi 696: f7 75 c4 divl -0x3c(%ebp) 699: 0f b6 92 e4 0a 00 00 movzbl 0xae4(%edx),%edx 6a0: 89 45 c0 mov %eax,-0x40(%ebp) 6a3: 89 d8 mov %ebx,%eax 6a5: 8d 5b 01 lea 0x1(%ebx),%ebx } while ((x /= base) != 0); 6a8: 8b 4d c0 mov -0x40(%ebp),%ecx buf[i++] = digits[x % base]; 6ab: 88 14 1e mov %dl,(%esi,%ebx,1) while ((x /= base) != 0); 6ae: 39 7d c4 cmp %edi,-0x3c(%ebp) 6b1: 76 dd jbe 690 if (neg) { 6b3: 8b 4d bc mov -0x44(%ebp),%ecx 6b6: 85 c9 test %ecx,%ecx 6b8: 74 0c je 6c6 buf[i++] = '-'; 6ba: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1) buf[i++] = digits[x % base]; 6bf: 89 d8 mov %ebx,%eax buf[i++] = '-'; 6c1: ba 2d 00 00 00 mov $0x2d,%edx } while (--i >= 0) { 6c6: 8b 7d b8 mov -0x48(%ebp),%edi 6c9: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx 6cd: eb 07 jmp 6d6 6cf: 90 nop putc(fd, buf[i]); 6d0: 0f b6 13 movzbl (%ebx),%edx 6d3: 83 eb 01 sub $0x1,%ebx write(fd, &c, 1); 6d6: 83 ec 04 sub $0x4,%esp 6d9: 88 55 d7 mov %dl,-0x29(%ebp) 6dc: 6a 01 push $0x1 6de: 56 push %esi 6df: 57 push %edi 6e0: e8 1e ff ff ff call 603 while (--i >= 0) { 6e5: 83 c4 10 add $0x10,%esp 6e8: 39 de cmp %ebx,%esi 6ea: 75 e4 jne 6d0 } } 6ec: 8d 65 f4 lea -0xc(%ebp),%esp 6ef: 5b pop %ebx 6f0: 5e pop %esi 6f1: 5f pop %edi 6f2: 5d pop %ebp 6f3: c3 ret 6f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 6f8: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp) 6ff: eb 87 jmp 688 701: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 708: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 70f: 90 nop 00000710 : // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 710: 55 push %ebp 711: 89 e5 mov %esp,%ebp 713: 57 push %edi 714: 56 push %esi 715: 53 push %ebx 716: 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++) { 719: 8b 5d 0c mov 0xc(%ebp),%ebx void printf(int fd, const char *fmt, ...) { 71c: 8b 75 08 mov 0x8(%ebp),%esi for (i = 0; fmt[i]; i++) { 71f: 0f b6 13 movzbl (%ebx),%edx 722: 84 d2 test %dl,%dl 724: 74 6a je 790 ap = (uint*)(void*)&fmt + 1; 726: 8d 45 10 lea 0x10(%ebp),%eax 729: 83 c3 01 add $0x1,%ebx write(fd, &c, 1); 72c: 8d 7d e7 lea -0x19(%ebp),%edi state = 0; 72f: 31 c9 xor %ecx,%ecx ap = (uint*)(void*)&fmt + 1; 731: 89 45 d0 mov %eax,-0x30(%ebp) 734: eb 36 jmp 76c 736: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 73d: 8d 76 00 lea 0x0(%esi),%esi 740: 89 4d d4 mov %ecx,-0x2c(%ebp) c = fmt[i] & 0xff; if (state == 0) { if (c == '%') { state = '%'; 743: b9 25 00 00 00 mov $0x25,%ecx if (c == '%') { 748: 83 f8 25 cmp $0x25,%eax 74b: 74 15 je 762 write(fd, &c, 1); 74d: 83 ec 04 sub $0x4,%esp 750: 88 55 e7 mov %dl,-0x19(%ebp) 753: 6a 01 push $0x1 755: 57 push %edi 756: 56 push %esi 757: e8 a7 fe ff ff call 603 75c: 8b 4d d4 mov -0x2c(%ebp),%ecx } else { putc(fd, c); 75f: 83 c4 10 add $0x10,%esp for (i = 0; fmt[i]; i++) { 762: 0f b6 13 movzbl (%ebx),%edx 765: 83 c3 01 add $0x1,%ebx 768: 84 d2 test %dl,%dl 76a: 74 24 je 790 c = fmt[i] & 0xff; 76c: 0f b6 c2 movzbl %dl,%eax if (state == 0) { 76f: 85 c9 test %ecx,%ecx 771: 74 cd je 740 } } else if (state == '%') { 773: 83 f9 25 cmp $0x25,%ecx 776: 75 ea jne 762 if (c == 'd') { 778: 83 f8 25 cmp $0x25,%eax 77b: 0f 84 07 01 00 00 je 888 781: 83 e8 63 sub $0x63,%eax 784: 83 f8 15 cmp $0x15,%eax 787: 77 17 ja 7a0 789: ff 24 85 8c 0a 00 00 jmp *0xa8c(,%eax,4) putc(fd, c); } state = 0; } } } 790: 8d 65 f4 lea -0xc(%ebp),%esp 793: 5b pop %ebx 794: 5e pop %esi 795: 5f pop %edi 796: 5d pop %ebp 797: c3 ret 798: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 79f: 90 nop write(fd, &c, 1); 7a0: 83 ec 04 sub $0x4,%esp 7a3: 88 55 d4 mov %dl,-0x2c(%ebp) 7a6: 6a 01 push $0x1 7a8: 57 push %edi 7a9: 56 push %esi 7aa: c6 45 e7 25 movb $0x25,-0x19(%ebp) 7ae: e8 50 fe ff ff call 603 putc(fd, c); 7b3: 0f b6 55 d4 movzbl -0x2c(%ebp),%edx write(fd, &c, 1); 7b7: 83 c4 0c add $0xc,%esp 7ba: 88 55 e7 mov %dl,-0x19(%ebp) 7bd: 6a 01 push $0x1 7bf: 57 push %edi 7c0: 56 push %esi 7c1: e8 3d fe ff ff call 603 putc(fd, c); 7c6: 83 c4 10 add $0x10,%esp state = 0; 7c9: 31 c9 xor %ecx,%ecx 7cb: eb 95 jmp 762 7cd: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 7d0: 83 ec 0c sub $0xc,%esp 7d3: b9 10 00 00 00 mov $0x10,%ecx 7d8: 6a 00 push $0x0 7da: 8b 45 d0 mov -0x30(%ebp),%eax 7dd: 8b 10 mov (%eax),%edx 7df: 89 f0 mov %esi,%eax 7e1: e8 7a fe ff ff call 660 ap++; 7e6: 83 45 d0 04 addl $0x4,-0x30(%ebp) 7ea: 83 c4 10 add $0x10,%esp state = 0; 7ed: 31 c9 xor %ecx,%ecx 7ef: e9 6e ff ff ff jmp 762 7f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 7f8: 8b 45 d0 mov -0x30(%ebp),%eax 7fb: 8b 10 mov (%eax),%edx ap++; 7fd: 83 c0 04 add $0x4,%eax 800: 89 45 d0 mov %eax,-0x30(%ebp) if (s == 0) { 803: 85 d2 test %edx,%edx 805: 0f 84 8d 00 00 00 je 898 while (*s != 0) { 80b: 0f b6 02 movzbl (%edx),%eax state = 0; 80e: 31 c9 xor %ecx,%ecx while (*s != 0) { 810: 84 c0 test %al,%al 812: 0f 84 4a ff ff ff je 762 818: 89 5d d4 mov %ebx,-0x2c(%ebp) 81b: 89 d3 mov %edx,%ebx 81d: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 820: 83 ec 04 sub $0x4,%esp s++; 823: 83 c3 01 add $0x1,%ebx 826: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 829: 6a 01 push $0x1 82b: 57 push %edi 82c: 56 push %esi 82d: e8 d1 fd ff ff call 603 while (*s != 0) { 832: 0f b6 03 movzbl (%ebx),%eax 835: 83 c4 10 add $0x10,%esp 838: 84 c0 test %al,%al 83a: 75 e4 jne 820 state = 0; 83c: 8b 5d d4 mov -0x2c(%ebp),%ebx 83f: 31 c9 xor %ecx,%ecx 841: e9 1c ff ff ff jmp 762 846: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 84d: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 10, 1); 850: 83 ec 0c sub $0xc,%esp 853: b9 0a 00 00 00 mov $0xa,%ecx 858: 6a 01 push $0x1 85a: e9 7b ff ff ff jmp 7da 85f: 90 nop putc(fd, *ap); 860: 8b 45 d0 mov -0x30(%ebp),%eax write(fd, &c, 1); 863: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 866: 8b 00 mov (%eax),%eax write(fd, &c, 1); 868: 6a 01 push $0x1 86a: 57 push %edi 86b: 56 push %esi putc(fd, *ap); 86c: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 86f: e8 8f fd ff ff call 603 ap++; 874: 83 45 d0 04 addl $0x4,-0x30(%ebp) 878: 83 c4 10 add $0x10,%esp state = 0; 87b: 31 c9 xor %ecx,%ecx 87d: e9 e0 fe ff ff jmp 762 882: 8d b6 00 00 00 00 lea 0x0(%esi),%esi putc(fd, c); 888: 88 55 e7 mov %dl,-0x19(%ebp) write(fd, &c, 1); 88b: 83 ec 04 sub $0x4,%esp 88e: e9 2a ff ff ff jmp 7bd 893: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 897: 90 nop s = "(null)"; 898: ba 82 0a 00 00 mov $0xa82,%edx while (*s != 0) { 89d: 89 5d d4 mov %ebx,-0x2c(%ebp) 8a0: b8 28 00 00 00 mov $0x28,%eax 8a5: 89 d3 mov %edx,%ebx 8a7: e9 74 ff ff ff jmp 820 8ac: 66 90 xchg %ax,%ax 8ae: 66 90 xchg %ax,%ax 000008b0 : typedef union header Header; static Header base; static Header *freep; void free(void *ap) { 8b0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) { 8b1: a1 24 0e 00 00 mov 0xe24,%eax void free(void *ap) { 8b6: 89 e5 mov %esp,%ebp 8b8: 57 push %edi 8b9: 56 push %esi 8ba: 53 push %ebx 8bb: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 8be: 8d 4b f8 lea -0x8(%ebx),%ecx for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) { 8c1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 8c8: 89 c2 mov %eax,%edx 8ca: 8b 00 mov (%eax),%eax 8cc: 39 ca cmp %ecx,%edx 8ce: 73 30 jae 900 8d0: 39 c1 cmp %eax,%ecx 8d2: 72 04 jb 8d8 if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { 8d4: 39 c2 cmp %eax,%edx 8d6: 72 f0 jb 8c8 break; } } if (bp + bp->s.size == p->s.ptr) { 8d8: 8b 73 fc mov -0x4(%ebx),%esi 8db: 8d 3c f1 lea (%ecx,%esi,8),%edi 8de: 39 f8 cmp %edi,%eax 8e0: 74 30 je 912 bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; 8e2: 89 43 f8 mov %eax,-0x8(%ebx) } else { bp->s.ptr = p->s.ptr; } if (p + p->s.size == bp) { 8e5: 8b 42 04 mov 0x4(%edx),%eax 8e8: 8d 34 c2 lea (%edx,%eax,8),%esi 8eb: 39 f1 cmp %esi,%ecx 8ed: 74 3a je 929 p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; 8ef: 89 0a mov %ecx,(%edx) } else { p->s.ptr = bp; } freep = p; } 8f1: 5b pop %ebx freep = p; 8f2: 89 15 24 0e 00 00 mov %edx,0xe24 } 8f8: 5e pop %esi 8f9: 5f pop %edi 8fa: 5d pop %ebp 8fb: c3 ret 8fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { 900: 39 c2 cmp %eax,%edx 902: 72 c4 jb 8c8 904: 39 c1 cmp %eax,%ecx 906: 73 c0 jae 8c8 if (bp + bp->s.size == p->s.ptr) { 908: 8b 73 fc mov -0x4(%ebx),%esi 90b: 8d 3c f1 lea (%ecx,%esi,8),%edi 90e: 39 f8 cmp %edi,%eax 910: 75 d0 jne 8e2 bp->s.size += p->s.ptr->s.size; 912: 03 70 04 add 0x4(%eax),%esi 915: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 918: 8b 02 mov (%edx),%eax 91a: 8b 00 mov (%eax),%eax 91c: 89 43 f8 mov %eax,-0x8(%ebx) if (p + p->s.size == bp) { 91f: 8b 42 04 mov 0x4(%edx),%eax 922: 8d 34 c2 lea (%edx,%eax,8),%esi 925: 39 f1 cmp %esi,%ecx 927: 75 c6 jne 8ef p->s.size += bp->s.size; 929: 03 43 fc add -0x4(%ebx),%eax freep = p; 92c: 89 15 24 0e 00 00 mov %edx,0xe24 p->s.size += bp->s.size; 932: 89 42 04 mov %eax,0x4(%edx) p->s.ptr = bp->s.ptr; 935: 8b 4b f8 mov -0x8(%ebx),%ecx 938: 89 0a mov %ecx,(%edx) } 93a: 5b pop %ebx 93b: 5e pop %esi 93c: 5f pop %edi 93d: 5d pop %ebp 93e: c3 ret 93f: 90 nop 00000940 : hp->s.size = nu; free((void*)(hp + 1)); return freep; } void* malloc(uint nbytes) { 940: 55 push %ebp 941: 89 e5 mov %esp,%ebp 943: 57 push %edi 944: 56 push %esi 945: 53 push %ebx 946: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 949: 8b 45 08 mov 0x8(%ebp),%eax if ((prevp = freep) == 0) { 94c: 8b 3d 24 0e 00 00 mov 0xe24,%edi nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 952: 8d 70 07 lea 0x7(%eax),%esi 955: c1 ee 03 shr $0x3,%esi 958: 83 c6 01 add $0x1,%esi if ((prevp = freep) == 0) { 95b: 85 ff test %edi,%edi 95d: 0f 84 9d 00 00 00 je a00 base.s.ptr = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 963: 8b 17 mov (%edi),%edx if (p->s.size >= nunits) { 965: 8b 4a 04 mov 0x4(%edx),%ecx 968: 39 f1 cmp %esi,%ecx 96a: 73 6a jae 9d6 96c: bb 00 10 00 00 mov $0x1000,%ebx 971: 39 de cmp %ebx,%esi 973: 0f 43 de cmovae %esi,%ebx p = sbrk(nu * sizeof(Header)); 976: 8d 04 dd 00 00 00 00 lea 0x0(,%ebx,8),%eax 97d: 89 45 e4 mov %eax,-0x1c(%ebp) 980: eb 17 jmp 999 982: 8d b6 00 00 00 00 lea 0x0(%esi),%esi for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 988: 8b 02 mov (%edx),%eax if (p->s.size >= nunits) { 98a: 8b 48 04 mov 0x4(%eax),%ecx 98d: 39 f1 cmp %esi,%ecx 98f: 73 4f jae 9e0 p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if (p == freep) { 991: 8b 3d 24 0e 00 00 mov 0xe24,%edi 997: 89 c2 mov %eax,%edx 999: 39 d7 cmp %edx,%edi 99b: 75 eb jne 988 p = sbrk(nu * sizeof(Header)); 99d: 83 ec 0c sub $0xc,%esp 9a0: ff 75 e4 push -0x1c(%ebp) 9a3: e8 3b fc ff ff call 5e3 if (p == (char*)-1) { 9a8: 83 c4 10 add $0x10,%esp 9ab: 83 f8 ff cmp $0xffffffff,%eax 9ae: 74 1c je 9cc hp->s.size = nu; 9b0: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 9b3: 83 ec 0c sub $0xc,%esp 9b6: 83 c0 08 add $0x8,%eax 9b9: 50 push %eax 9ba: e8 f1 fe ff ff call 8b0 return freep; 9bf: 8b 15 24 0e 00 00 mov 0xe24,%edx if ((p = morecore(nunits)) == 0) { 9c5: 83 c4 10 add $0x10,%esp 9c8: 85 d2 test %edx,%edx 9ca: 75 bc jne 988 return 0; } } } } 9cc: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 9cf: 31 c0 xor %eax,%eax } 9d1: 5b pop %ebx 9d2: 5e pop %esi 9d3: 5f pop %edi 9d4: 5d pop %ebp 9d5: c3 ret if (p->s.size >= nunits) { 9d6: 89 d0 mov %edx,%eax 9d8: 89 fa mov %edi,%edx 9da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if (p->s.size == nunits) { 9e0: 39 ce cmp %ecx,%esi 9e2: 74 4c je a30 p->s.size -= nunits; 9e4: 29 f1 sub %esi,%ecx 9e6: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 9e9: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 9ec: 89 70 04 mov %esi,0x4(%eax) freep = prevp; 9ef: 89 15 24 0e 00 00 mov %edx,0xe24 } 9f5: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 9f8: 83 c0 08 add $0x8,%eax } 9fb: 5b pop %ebx 9fc: 5e pop %esi 9fd: 5f pop %edi 9fe: 5d pop %ebp 9ff: c3 ret base.s.ptr = freep = prevp = &base; a00: c7 05 24 0e 00 00 28 movl $0xe28,0xe24 a07: 0e 00 00 base.s.size = 0; a0a: bf 28 0e 00 00 mov $0xe28,%edi base.s.ptr = freep = prevp = &base; a0f: c7 05 28 0e 00 00 28 movl $0xe28,0xe28 a16: 0e 00 00 for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { a19: 89 fa mov %edi,%edx base.s.size = 0; a1b: c7 05 2c 0e 00 00 00 movl $0x0,0xe2c a22: 00 00 00 if (p->s.size >= nunits) { a25: e9 42 ff ff ff jmp 96c a2a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi prevp->s.ptr = p->s.ptr; a30: 8b 08 mov (%eax),%ecx a32: 89 0a mov %ecx,(%edx) a34: eb b9 jmp 9ef