_cat: file format elf32-i386 Disassembly of section .text: 00000000
: printf(1, "cat: read error\n"); exit(); } } 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: be 01 00 00 00 mov $0x1,%esi 14: 53 push %ebx 15: 51 push %ecx 16: 83 ec 18 sub $0x18,%esp 19: 8b 01 mov (%ecx),%eax 1b: 8b 59 04 mov 0x4(%ecx),%ebx 1e: 89 45 e4 mov %eax,-0x1c(%ebp) 21: 83 c3 04 add $0x4,%ebx int fd, i; if (argc <= 1) { 24: 83 f8 01 cmp $0x1,%eax 27: 7e 54 jle 7d 29: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi cat(0); exit(); } for (i = 1; i < argc; i++) { if ((fd = open(argv[i], 0)) < 0) { 30: 83 ec 08 sub $0x8,%esp 33: 6a 00 push $0x0 35: ff 33 push (%ebx) 37: e8 8f 03 00 00 call 3cb 3c: 83 c4 10 add $0x10,%esp 3f: 89 c7 mov %eax,%edi 41: 85 c0 test %eax,%eax 43: 78 24 js 69 printf(1, "cat: cannot open %s\n", argv[i]); exit(); } cat(fd); 45: 83 ec 0c sub $0xc,%esp for (i = 1; i < argc; i++) { 48: 83 c6 01 add $0x1,%esi 4b: 83 c3 04 add $0x4,%ebx cat(fd); 4e: 50 push %eax 4f: e8 3c 00 00 00 call 90 close(fd); 54: 89 3c 24 mov %edi,(%esp) 57: e8 9f 03 00 00 call 3fb for (i = 1; i < argc; i++) { 5c: 83 c4 10 add $0x10,%esp 5f: 39 75 e4 cmp %esi,-0x1c(%ebp) 62: 75 cc jne 30 } exit(); 64: e8 fa 02 00 00 call 363 printf(1, "cat: cannot open %s\n", argv[i]); 69: 50 push %eax 6a: ff 33 push (%ebx) 6c: 68 1b 08 00 00 push $0x81b 71: 6a 01 push $0x1 73: e8 58 04 00 00 call 4d0 exit(); 78: e8 e6 02 00 00 call 363 cat(0); 7d: 83 ec 0c sub $0xc,%esp 80: 6a 00 push $0x0 82: e8 09 00 00 00 call 90 exit(); 87: e8 d7 02 00 00 call 363 8c: 66 90 xchg %ax,%ax 8e: 66 90 xchg %ax,%ax 00000090 : void cat(int fd) { 90: 55 push %ebp 91: 89 e5 mov %esp,%ebp 93: 56 push %esi 94: 8b 75 08 mov 0x8(%ebp),%esi 97: 53 push %ebx while ((n = read(fd, buf, sizeof(buf))) > 0) { 98: eb 1d jmp b7 9a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if (write(1, buf, n) != n) { a0: 83 ec 04 sub $0x4,%esp a3: 53 push %ebx a4: 68 80 0b 00 00 push $0xb80 a9: 6a 01 push $0x1 ab: e8 23 03 00 00 call 3d3 b0: 83 c4 10 add $0x10,%esp b3: 39 d8 cmp %ebx,%eax b5: 75 25 jne dc while ((n = read(fd, buf, sizeof(buf))) > 0) { b7: 83 ec 04 sub $0x4,%esp ba: 68 00 02 00 00 push $0x200 bf: 68 80 0b 00 00 push $0xb80 c4: 56 push %esi c5: e8 b1 02 00 00 call 37b ca: 83 c4 10 add $0x10,%esp cd: 89 c3 mov %eax,%ebx cf: 85 c0 test %eax,%eax d1: 7f cd jg a0 if (n < 0) { d3: 75 1b jne f0 } d5: 8d 65 f8 lea -0x8(%ebp),%esp d8: 5b pop %ebx d9: 5e pop %esi da: 5d pop %ebp db: c3 ret printf(1, "cat: write error\n"); dc: 83 ec 08 sub $0x8,%esp df: 68 f8 07 00 00 push $0x7f8 e4: 6a 01 push $0x1 e6: e8 e5 03 00 00 call 4d0 exit(); eb: e8 73 02 00 00 call 363 printf(1, "cat: read error\n"); f0: 50 push %eax f1: 50 push %eax f2: 68 0a 08 00 00 push $0x80a f7: 6a 01 push $0x1 f9: e8 d2 03 00 00 call 4d0 exit(); fe: e8 60 02 00 00 call 363 103: 66 90 xchg %ax,%ax 105: 66 90 xchg %ax,%ax 107: 66 90 xchg %ax,%ax 109: 66 90 xchg %ax,%ax 10b: 66 90 xchg %ax,%ax 10d: 66 90 xchg %ax,%ax 10f: 90 nop 00000110 : #include "stat.h" #include "fcntl.h" #include "user.h" #include "x86.h" char*strcpy(char *s, const char *t) { 110: 55 push %ebp char *os; os = s; while ((*s++ = *t++) != 0) { 111: 31 c0 xor %eax,%eax char*strcpy(char *s, const char *t) { 113: 89 e5 mov %esp,%ebp 115: 53 push %ebx 116: 8b 4d 08 mov 0x8(%ebp),%ecx 119: 8b 5d 0c mov 0xc(%ebp),%ebx 11c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi while ((*s++ = *t++) != 0) { 120: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx 124: 88 14 01 mov %dl,(%ecx,%eax,1) 127: 83 c0 01 add $0x1,%eax 12a: 84 d2 test %dl,%dl 12c: 75 f2 jne 120 ; } return os; } 12e: 8b 5d fc mov -0x4(%ebp),%ebx 131: 89 c8 mov %ecx,%eax 133: c9 leave 134: c3 ret 135: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 13c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000140 : int strcmp(const char *p, const char *q) { 140: 55 push %ebp 141: 89 e5 mov %esp,%ebp 143: 53 push %ebx 144: 8b 55 08 mov 0x8(%ebp),%edx 147: 8b 4d 0c mov 0xc(%ebp),%ecx while (*p && *p == *q) { 14a: 0f b6 02 movzbl (%edx),%eax 14d: 84 c0 test %al,%al 14f: 75 17 jne 168 151: eb 3a jmp 18d 153: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 157: 90 nop 158: 0f b6 42 01 movzbl 0x1(%edx),%eax p++, q++; 15c: 83 c2 01 add $0x1,%edx 15f: 8d 59 01 lea 0x1(%ecx),%ebx while (*p && *p == *q) { 162: 84 c0 test %al,%al 164: 74 1a je 180 p++, q++; 166: 89 d9 mov %ebx,%ecx while (*p && *p == *q) { 168: 0f b6 19 movzbl (%ecx),%ebx 16b: 38 c3 cmp %al,%bl 16d: 74 e9 je 158 } return (uchar) * p - (uchar) * q; 16f: 29 d8 sub %ebx,%eax } 171: 8b 5d fc mov -0x4(%ebp),%ebx 174: c9 leave 175: c3 ret 176: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 17d: 8d 76 00 lea 0x0(%esi),%esi return (uchar) * p - (uchar) * q; 180: 0f b6 59 01 movzbl 0x1(%ecx),%ebx 184: 31 c0 xor %eax,%eax 186: 29 d8 sub %ebx,%eax } 188: 8b 5d fc mov -0x4(%ebp),%ebx 18b: c9 leave 18c: c3 ret return (uchar) * p - (uchar) * q; 18d: 0f b6 19 movzbl (%ecx),%ebx 190: 31 c0 xor %eax,%eax 192: eb db jmp 16f 194: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 19b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 19f: 90 nop 000001a0 : uint strlen(const char *s) { 1a0: 55 push %ebp 1a1: 89 e5 mov %esp,%ebp 1a3: 8b 55 08 mov 0x8(%ebp),%edx int n; for (n = 0; s[n]; n++) { 1a6: 80 3a 00 cmpb $0x0,(%edx) 1a9: 74 15 je 1c0 1ab: 31 c0 xor %eax,%eax 1ad: 8d 76 00 lea 0x0(%esi),%esi 1b0: 83 c0 01 add $0x1,%eax 1b3: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1) 1b7: 89 c1 mov %eax,%ecx 1b9: 75 f5 jne 1b0 ; } return n; } 1bb: 89 c8 mov %ecx,%eax 1bd: 5d pop %ebp 1be: c3 ret 1bf: 90 nop for (n = 0; s[n]; n++) { 1c0: 31 c9 xor %ecx,%ecx } 1c2: 5d pop %ebp 1c3: 89 c8 mov %ecx,%eax 1c5: c3 ret 1c6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1cd: 8d 76 00 lea 0x0(%esi),%esi 000001d0 : 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 "d" (port), "0" (addr), "1" (cnt) : "cc"); } 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: 8b 7d fc mov -0x4(%ebp),%edi 1e5: 89 d0 mov %edx,%eax 1e7: c9 leave 1e8: c3 ret 1e9: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 000001f0 : char* strchr(const char *s, char c) { 1f0: 55 push %ebp 1f1: 89 e5 mov %esp,%ebp 1f3: 8b 45 08 mov 0x8(%ebp),%eax 1f6: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx for (; *s; s++) { 1fa: 0f b6 10 movzbl (%eax),%edx 1fd: 84 d2 test %dl,%dl 1ff: 75 12 jne 213 201: eb 1d jmp 220 203: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 207: 90 nop 208: 0f b6 50 01 movzbl 0x1(%eax),%edx 20c: 83 c0 01 add $0x1,%eax 20f: 84 d2 test %dl,%dl 211: 74 0d je 220 if (*s == c) { 213: 38 d1 cmp %dl,%cl 215: 75 f1 jne 208 return (char*)s; } } return 0; } 217: 5d pop %ebp 218: c3 ret 219: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return 0; 220: 31 c0 xor %eax,%eax } 222: 5d pop %ebp 223: c3 ret 224: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 22b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 22f: 90 nop 00000230 : char* gets(char *buf, int max) { 230: 55 push %ebp 231: 89 e5 mov %esp,%ebp 233: 57 push %edi 234: 56 push %esi int i, cc; char c; for (i = 0; i + 1 < max;) { cc = read(0, &c, 1); 235: 8d 7d e7 lea -0x19(%ebp),%edi char* gets(char *buf, int max) { 238: 53 push %ebx for (i = 0; i + 1 < max;) { 239: 31 db xor %ebx,%ebx char* gets(char *buf, int max) { 23b: 83 ec 1c sub $0x1c,%esp for (i = 0; i + 1 < max;) { 23e: eb 27 jmp 267 cc = read(0, &c, 1); 240: 83 ec 04 sub $0x4,%esp 243: 6a 01 push $0x1 245: 57 push %edi 246: 6a 00 push $0x0 248: e8 2e 01 00 00 call 37b if (cc < 1) { 24d: 83 c4 10 add $0x10,%esp 250: 85 c0 test %eax,%eax 252: 7e 1d jle 271 break; } buf[i++] = c; 254: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 258: 8b 55 08 mov 0x8(%ebp),%edx 25b: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if (c == '\n' || c == '\r') { 25f: 3c 0a cmp $0xa,%al 261: 74 1d je 280 263: 3c 0d cmp $0xd,%al 265: 74 19 je 280 for (i = 0; i + 1 < max;) { 267: 89 de mov %ebx,%esi 269: 83 c3 01 add $0x1,%ebx 26c: 3b 5d 0c cmp 0xc(%ebp),%ebx 26f: 7c cf jl 240 break; } } buf[i] = '\0'; 271: 8b 45 08 mov 0x8(%ebp),%eax 274: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 278: 8d 65 f4 lea -0xc(%ebp),%esp 27b: 5b pop %ebx 27c: 5e pop %esi 27d: 5f pop %edi 27e: 5d pop %ebp 27f: c3 ret buf[i] = '\0'; 280: 8b 45 08 mov 0x8(%ebp),%eax 283: 89 de mov %ebx,%esi 285: c6 04 30 00 movb $0x0,(%eax,%esi,1) } 289: 8d 65 f4 lea -0xc(%ebp),%esp 28c: 5b pop %ebx 28d: 5e pop %esi 28e: 5f pop %edi 28f: 5d pop %ebp 290: c3 ret 291: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 298: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 29f: 90 nop 000002a0 : int stat(const char *n, struct stat *st) { 2a0: 55 push %ebp 2a1: 89 e5 mov %esp,%ebp 2a3: 56 push %esi 2a4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 2a5: 83 ec 08 sub $0x8,%esp 2a8: 6a 00 push $0x0 2aa: ff 75 08 push 0x8(%ebp) 2ad: e8 19 01 00 00 call 3cb if (fd < 0) { 2b2: 83 c4 10 add $0x10,%esp 2b5: 85 c0 test %eax,%eax 2b7: 78 27 js 2e0 return -1; } r = fstat(fd, st); 2b9: 83 ec 08 sub $0x8,%esp 2bc: ff 75 0c push 0xc(%ebp) 2bf: 89 c3 mov %eax,%ebx 2c1: 50 push %eax 2c2: e8 cc 00 00 00 call 393 close(fd); 2c7: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 2ca: 89 c6 mov %eax,%esi close(fd); 2cc: e8 2a 01 00 00 call 3fb return r; 2d1: 83 c4 10 add $0x10,%esp } 2d4: 8d 65 f8 lea -0x8(%ebp),%esp 2d7: 89 f0 mov %esi,%eax 2d9: 5b pop %ebx 2da: 5e pop %esi 2db: 5d pop %ebp 2dc: c3 ret 2dd: 8d 76 00 lea 0x0(%esi),%esi return -1; 2e0: be ff ff ff ff mov $0xffffffff,%esi 2e5: eb ed jmp 2d4 2e7: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 2ee: 66 90 xchg %ax,%ax 000002f0 : int atoi(const char *s) { 2f0: 55 push %ebp 2f1: 89 e5 mov %esp,%ebp 2f3: 53 push %ebx 2f4: 8b 55 08 mov 0x8(%ebp),%edx int n; n = 0; while ('0' <= *s && *s <= '9') { 2f7: 0f be 02 movsbl (%edx),%eax 2fa: 8d 48 d0 lea -0x30(%eax),%ecx 2fd: 80 f9 09 cmp $0x9,%cl n = 0; 300: b9 00 00 00 00 mov $0x0,%ecx while ('0' <= *s && *s <= '9') { 305: 77 1e ja 325 307: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 30e: 66 90 xchg %ax,%ax n = n * 10 + *s++ - '0'; 310: 83 c2 01 add $0x1,%edx 313: 8d 0c 89 lea (%ecx,%ecx,4),%ecx 316: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx while ('0' <= *s && *s <= '9') { 31a: 0f be 02 movsbl (%edx),%eax 31d: 8d 58 d0 lea -0x30(%eax),%ebx 320: 80 fb 09 cmp $0x9,%bl 323: 76 eb jbe 310 } return n; } 325: 8b 5d fc mov -0x4(%ebp),%ebx 328: 89 c8 mov %ecx,%eax 32a: c9 leave 32b: c3 ret 32c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000330 : void* memmove(void *vdst, const void *vsrc, int n) { 330: 55 push %ebp 331: 89 e5 mov %esp,%ebp 333: 57 push %edi 334: 8b 45 10 mov 0x10(%ebp),%eax 337: 8b 55 08 mov 0x8(%ebp),%edx 33a: 56 push %esi 33b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while (n-- > 0) { 33e: 85 c0 test %eax,%eax 340: 7e 13 jle 355 342: 01 d0 add %edx,%eax dst = vdst; 344: 89 d7 mov %edx,%edi 346: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 34d: 8d 76 00 lea 0x0(%esi),%esi *dst++ = *src++; 350: a4 movsb %ds:(%esi),%es:(%edi) while (n-- > 0) { 351: 39 f8 cmp %edi,%eax 353: 75 fb jne 350 } return vdst; } 355: 5e pop %esi 356: 89 d0 mov %edx,%eax 358: 5f pop %edi 359: 5d pop %ebp 35a: c3 ret 0000035b : name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 35b: b8 01 00 00 00 mov $0x1,%eax 360: cd 40 int $0x40 362: c3 ret 00000363 : SYSCALL(exit) 363: b8 02 00 00 00 mov $0x2,%eax 368: cd 40 int $0x40 36a: c3 ret 0000036b : SYSCALL(wait) 36b: b8 03 00 00 00 mov $0x3,%eax 370: cd 40 int $0x40 372: c3 ret 00000373 : SYSCALL(pipe) 373: b8 04 00 00 00 mov $0x4,%eax 378: cd 40 int $0x40 37a: c3 ret 0000037b : SYSCALL(read) 37b: b8 05 00 00 00 mov $0x5,%eax 380: cd 40 int $0x40 382: c3 ret 00000383 : SYSCALL(kill) 383: b8 06 00 00 00 mov $0x6,%eax 388: cd 40 int $0x40 38a: c3 ret 0000038b : SYSCALL(exec) 38b: b8 07 00 00 00 mov $0x7,%eax 390: cd 40 int $0x40 392: c3 ret 00000393 : SYSCALL(fstat) 393: b8 08 00 00 00 mov $0x8,%eax 398: cd 40 int $0x40 39a: c3 ret 0000039b : SYSCALL(chdir) 39b: b8 09 00 00 00 mov $0x9,%eax 3a0: cd 40 int $0x40 3a2: c3 ret 000003a3 : SYSCALL(dup) 3a3: b8 0a 00 00 00 mov $0xa,%eax 3a8: cd 40 int $0x40 3aa: c3 ret 000003ab : SYSCALL(getpid) 3ab: b8 0b 00 00 00 mov $0xb,%eax 3b0: cd 40 int $0x40 3b2: c3 ret 000003b3 : SYSCALL(sbrk) 3b3: b8 0c 00 00 00 mov $0xc,%eax 3b8: cd 40 int $0x40 3ba: c3 ret 000003bb : SYSCALL(sleep) 3bb: b8 0d 00 00 00 mov $0xd,%eax 3c0: cd 40 int $0x40 3c2: c3 ret 000003c3 : SYSCALL(uptime) 3c3: b8 0e 00 00 00 mov $0xe,%eax 3c8: cd 40 int $0x40 3ca: c3 ret 000003cb : SYSCALL(open) 3cb: b8 0f 00 00 00 mov $0xf,%eax 3d0: cd 40 int $0x40 3d2: c3 ret 000003d3 : SYSCALL(write) 3d3: b8 10 00 00 00 mov $0x10,%eax 3d8: cd 40 int $0x40 3da: c3 ret 000003db : SYSCALL(mknod) 3db: b8 11 00 00 00 mov $0x11,%eax 3e0: cd 40 int $0x40 3e2: c3 ret 000003e3 : SYSCALL(unlink) 3e3: b8 12 00 00 00 mov $0x12,%eax 3e8: cd 40 int $0x40 3ea: c3 ret 000003eb : SYSCALL(link) 3eb: b8 13 00 00 00 mov $0x13,%eax 3f0: cd 40 int $0x40 3f2: c3 ret 000003f3 : SYSCALL(mkdir) 3f3: b8 14 00 00 00 mov $0x14,%eax 3f8: cd 40 int $0x40 3fa: c3 ret 000003fb : SYSCALL(close) 3fb: b8 15 00 00 00 mov $0x15,%eax 400: cd 40 int $0x40 402: c3 ret 00000403 : SYSCALL(getch) 403: b8 16 00 00 00 mov $0x16,%eax 408: cd 40 int $0x40 40a: c3 ret 0000040b : SYSCALL(greeting) 40b: b8 17 00 00 00 mov $0x17,%eax 410: cd 40 int $0x40 412: c3 ret 00000413 : SYSCALL(shutdown) 413: b8 18 00 00 00 mov $0x18,%eax 418: cd 40 int $0x40 41a: c3 ret 41b: 66 90 xchg %ax,%ax 41d: 66 90 xchg %ax,%ax 41f: 90 nop 00000420 : static void putc(int fd, char c) { write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 420: 55 push %ebp 421: 89 e5 mov %esp,%ebp 423: 57 push %edi 424: 56 push %esi 425: 53 push %ebx 426: 83 ec 3c sub $0x3c,%esp 429: 89 4d c4 mov %ecx,-0x3c(%ebp) uint x; neg = 0; if (sgn && xx < 0) { neg = 1; x = -xx; 42c: 89 d1 mov %edx,%ecx static void printint(int fd, int xx, int base, int sgn) { 42e: 89 45 b8 mov %eax,-0x48(%ebp) if (sgn && xx < 0) { 431: 85 d2 test %edx,%edx 433: 0f 89 7f 00 00 00 jns 4b8 439: f6 45 08 01 testb $0x1,0x8(%ebp) 43d: 74 79 je 4b8 neg = 1; 43f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp) x = -xx; 446: f7 d9 neg %ecx } else { x = xx; } i = 0; 448: 31 db xor %ebx,%ebx 44a: 8d 75 d7 lea -0x29(%ebp),%esi 44d: 8d 76 00 lea 0x0(%esi),%esi do { buf[i++] = digits[x % base]; 450: 89 c8 mov %ecx,%eax 452: 31 d2 xor %edx,%edx 454: 89 cf mov %ecx,%edi 456: f7 75 c4 divl -0x3c(%ebp) 459: 0f b6 92 90 08 00 00 movzbl 0x890(%edx),%edx 460: 89 45 c0 mov %eax,-0x40(%ebp) 463: 89 d8 mov %ebx,%eax 465: 8d 5b 01 lea 0x1(%ebx),%ebx } while ((x /= base) != 0); 468: 8b 4d c0 mov -0x40(%ebp),%ecx buf[i++] = digits[x % base]; 46b: 88 14 1e mov %dl,(%esi,%ebx,1) while ((x /= base) != 0); 46e: 39 7d c4 cmp %edi,-0x3c(%ebp) 471: 76 dd jbe 450 if (neg) { 473: 8b 4d bc mov -0x44(%ebp),%ecx 476: 85 c9 test %ecx,%ecx 478: 74 0c je 486 buf[i++] = '-'; 47a: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1) buf[i++] = digits[x % base]; 47f: 89 d8 mov %ebx,%eax buf[i++] = '-'; 481: ba 2d 00 00 00 mov $0x2d,%edx } while (--i >= 0) { 486: 8b 7d b8 mov -0x48(%ebp),%edi 489: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx 48d: eb 07 jmp 496 48f: 90 nop putc(fd, buf[i]); 490: 0f b6 13 movzbl (%ebx),%edx 493: 83 eb 01 sub $0x1,%ebx write(fd, &c, 1); 496: 83 ec 04 sub $0x4,%esp 499: 88 55 d7 mov %dl,-0x29(%ebp) 49c: 6a 01 push $0x1 49e: 56 push %esi 49f: 57 push %edi 4a0: e8 2e ff ff ff call 3d3 while (--i >= 0) { 4a5: 83 c4 10 add $0x10,%esp 4a8: 39 de cmp %ebx,%esi 4aa: 75 e4 jne 490 } } 4ac: 8d 65 f4 lea -0xc(%ebp),%esp 4af: 5b pop %ebx 4b0: 5e pop %esi 4b1: 5f pop %edi 4b2: 5d pop %ebp 4b3: c3 ret 4b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 4b8: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp) 4bf: eb 87 jmp 448 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 : // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 4d0: 55 push %ebp 4d1: 89 e5 mov %esp,%ebp 4d3: 57 push %edi 4d4: 56 push %esi 4d5: 53 push %ebx 4d6: 83 ec 2c sub $0x2c,%esp int c, i, state; uint *ap; state = 0; ap = (uint*)(void*)&fmt + 1; for (i = 0; fmt[i]; i++) { 4d9: 8b 5d 0c mov 0xc(%ebp),%ebx void printf(int fd, const char *fmt, ...) { 4dc: 8b 75 08 mov 0x8(%ebp),%esi for (i = 0; fmt[i]; i++) { 4df: 0f b6 13 movzbl (%ebx),%edx 4e2: 84 d2 test %dl,%dl 4e4: 74 6a je 550 ap = (uint*)(void*)&fmt + 1; 4e6: 8d 45 10 lea 0x10(%ebp),%eax 4e9: 83 c3 01 add $0x1,%ebx write(fd, &c, 1); 4ec: 8d 7d e7 lea -0x19(%ebp),%edi state = 0; 4ef: 31 c9 xor %ecx,%ecx ap = (uint*)(void*)&fmt + 1; 4f1: 89 45 d0 mov %eax,-0x30(%ebp) 4f4: eb 36 jmp 52c 4f6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 4fd: 8d 76 00 lea 0x0(%esi),%esi 500: 89 4d d4 mov %ecx,-0x2c(%ebp) c = fmt[i] & 0xff; if (state == 0) { if (c == '%') { state = '%'; 503: b9 25 00 00 00 mov $0x25,%ecx if (c == '%') { 508: 83 f8 25 cmp $0x25,%eax 50b: 74 15 je 522 write(fd, &c, 1); 50d: 83 ec 04 sub $0x4,%esp 510: 88 55 e7 mov %dl,-0x19(%ebp) 513: 6a 01 push $0x1 515: 57 push %edi 516: 56 push %esi 517: e8 b7 fe ff ff call 3d3 51c: 8b 4d d4 mov -0x2c(%ebp),%ecx } else { putc(fd, c); 51f: 83 c4 10 add $0x10,%esp for (i = 0; fmt[i]; i++) { 522: 0f b6 13 movzbl (%ebx),%edx 525: 83 c3 01 add $0x1,%ebx 528: 84 d2 test %dl,%dl 52a: 74 24 je 550 c = fmt[i] & 0xff; 52c: 0f b6 c2 movzbl %dl,%eax if (state == 0) { 52f: 85 c9 test %ecx,%ecx 531: 74 cd je 500 } } else if (state == '%') { 533: 83 f9 25 cmp $0x25,%ecx 536: 75 ea jne 522 if (c == 'd') { 538: 83 f8 25 cmp $0x25,%eax 53b: 0f 84 07 01 00 00 je 648 541: 83 e8 63 sub $0x63,%eax 544: 83 f8 15 cmp $0x15,%eax 547: 77 17 ja 560 549: ff 24 85 38 08 00 00 jmp *0x838(,%eax,4) putc(fd, c); } state = 0; } } } 550: 8d 65 f4 lea -0xc(%ebp),%esp 553: 5b pop %ebx 554: 5e pop %esi 555: 5f pop %edi 556: 5d pop %ebp 557: c3 ret 558: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 55f: 90 nop write(fd, &c, 1); 560: 83 ec 04 sub $0x4,%esp 563: 88 55 d4 mov %dl,-0x2c(%ebp) 566: 6a 01 push $0x1 568: 57 push %edi 569: 56 push %esi 56a: c6 45 e7 25 movb $0x25,-0x19(%ebp) 56e: e8 60 fe ff ff call 3d3 putc(fd, c); 573: 0f b6 55 d4 movzbl -0x2c(%ebp),%edx write(fd, &c, 1); 577: 83 c4 0c add $0xc,%esp 57a: 88 55 e7 mov %dl,-0x19(%ebp) 57d: 6a 01 push $0x1 57f: 57 push %edi 580: 56 push %esi 581: e8 4d fe ff ff call 3d3 putc(fd, c); 586: 83 c4 10 add $0x10,%esp state = 0; 589: 31 c9 xor %ecx,%ecx 58b: eb 95 jmp 522 58d: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 590: 83 ec 0c sub $0xc,%esp 593: b9 10 00 00 00 mov $0x10,%ecx 598: 6a 00 push $0x0 59a: 8b 45 d0 mov -0x30(%ebp),%eax 59d: 8b 10 mov (%eax),%edx 59f: 89 f0 mov %esi,%eax 5a1: e8 7a fe ff ff call 420 ap++; 5a6: 83 45 d0 04 addl $0x4,-0x30(%ebp) 5aa: 83 c4 10 add $0x10,%esp state = 0; 5ad: 31 c9 xor %ecx,%ecx 5af: e9 6e ff ff ff jmp 522 5b4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 5b8: 8b 45 d0 mov -0x30(%ebp),%eax 5bb: 8b 10 mov (%eax),%edx ap++; 5bd: 83 c0 04 add $0x4,%eax 5c0: 89 45 d0 mov %eax,-0x30(%ebp) if (s == 0) { 5c3: 85 d2 test %edx,%edx 5c5: 0f 84 8d 00 00 00 je 658 while (*s != 0) { 5cb: 0f b6 02 movzbl (%edx),%eax state = 0; 5ce: 31 c9 xor %ecx,%ecx while (*s != 0) { 5d0: 84 c0 test %al,%al 5d2: 0f 84 4a ff ff ff je 522 5d8: 89 5d d4 mov %ebx,-0x2c(%ebp) 5db: 89 d3 mov %edx,%ebx 5dd: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 5e0: 83 ec 04 sub $0x4,%esp s++; 5e3: 83 c3 01 add $0x1,%ebx 5e6: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 5e9: 6a 01 push $0x1 5eb: 57 push %edi 5ec: 56 push %esi 5ed: e8 e1 fd ff ff call 3d3 while (*s != 0) { 5f2: 0f b6 03 movzbl (%ebx),%eax 5f5: 83 c4 10 add $0x10,%esp 5f8: 84 c0 test %al,%al 5fa: 75 e4 jne 5e0 state = 0; 5fc: 8b 5d d4 mov -0x2c(%ebp),%ebx 5ff: 31 c9 xor %ecx,%ecx 601: e9 1c ff ff ff jmp 522 606: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 60d: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 10, 1); 610: 83 ec 0c sub $0xc,%esp 613: b9 0a 00 00 00 mov $0xa,%ecx 618: 6a 01 push $0x1 61a: e9 7b ff ff ff jmp 59a 61f: 90 nop putc(fd, *ap); 620: 8b 45 d0 mov -0x30(%ebp),%eax write(fd, &c, 1); 623: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 626: 8b 00 mov (%eax),%eax write(fd, &c, 1); 628: 6a 01 push $0x1 62a: 57 push %edi 62b: 56 push %esi putc(fd, *ap); 62c: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 62f: e8 9f fd ff ff call 3d3 ap++; 634: 83 45 d0 04 addl $0x4,-0x30(%ebp) 638: 83 c4 10 add $0x10,%esp state = 0; 63b: 31 c9 xor %ecx,%ecx 63d: e9 e0 fe ff ff jmp 522 642: 8d b6 00 00 00 00 lea 0x0(%esi),%esi putc(fd, c); 648: 88 55 e7 mov %dl,-0x19(%ebp) write(fd, &c, 1); 64b: 83 ec 04 sub $0x4,%esp 64e: e9 2a ff ff ff jmp 57d 653: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 657: 90 nop s = "(null)"; 658: ba 30 08 00 00 mov $0x830,%edx while (*s != 0) { 65d: 89 5d d4 mov %ebx,-0x2c(%ebp) 660: b8 28 00 00 00 mov $0x28,%eax 665: 89 d3 mov %edx,%ebx 667: e9 74 ff ff ff jmp 5e0 66c: 66 90 xchg %ax,%ax 66e: 66 90 xchg %ax,%ax 00000670 : typedef union header Header; static Header base; static Header *freep; void free(void *ap) { 670: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) { 671: a1 80 0d 00 00 mov 0xd80,%eax void free(void *ap) { 676: 89 e5 mov %esp,%ebp 678: 57 push %edi 679: 56 push %esi 67a: 53 push %ebx 67b: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 67e: 8d 4b f8 lea -0x8(%ebx),%ecx for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) { 681: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 688: 89 c2 mov %eax,%edx 68a: 8b 00 mov (%eax),%eax 68c: 39 ca cmp %ecx,%edx 68e: 73 30 jae 6c0 690: 39 c1 cmp %eax,%ecx 692: 72 04 jb 698 if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { 694: 39 c2 cmp %eax,%edx 696: 72 f0 jb 688 break; } } if (bp + bp->s.size == p->s.ptr) { 698: 8b 73 fc mov -0x4(%ebx),%esi 69b: 8d 3c f1 lea (%ecx,%esi,8),%edi 69e: 39 f8 cmp %edi,%eax 6a0: 74 30 je 6d2 bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; 6a2: 89 43 f8 mov %eax,-0x8(%ebx) } else { bp->s.ptr = p->s.ptr; } if (p + p->s.size == bp) { 6a5: 8b 42 04 mov 0x4(%edx),%eax 6a8: 8d 34 c2 lea (%edx,%eax,8),%esi 6ab: 39 f1 cmp %esi,%ecx 6ad: 74 3a je 6e9 p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; 6af: 89 0a mov %ecx,(%edx) } else { p->s.ptr = bp; } freep = p; } 6b1: 5b pop %ebx freep = p; 6b2: 89 15 80 0d 00 00 mov %edx,0xd80 } 6b8: 5e pop %esi 6b9: 5f pop %edi 6ba: 5d pop %ebp 6bb: c3 ret 6bc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { 6c0: 39 c2 cmp %eax,%edx 6c2: 72 c4 jb 688 6c4: 39 c1 cmp %eax,%ecx 6c6: 73 c0 jae 688 if (bp + bp->s.size == p->s.ptr) { 6c8: 8b 73 fc mov -0x4(%ebx),%esi 6cb: 8d 3c f1 lea (%ecx,%esi,8),%edi 6ce: 39 f8 cmp %edi,%eax 6d0: 75 d0 jne 6a2 bp->s.size += p->s.ptr->s.size; 6d2: 03 70 04 add 0x4(%eax),%esi 6d5: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 6d8: 8b 02 mov (%edx),%eax 6da: 8b 00 mov (%eax),%eax 6dc: 89 43 f8 mov %eax,-0x8(%ebx) if (p + p->s.size == bp) { 6df: 8b 42 04 mov 0x4(%edx),%eax 6e2: 8d 34 c2 lea (%edx,%eax,8),%esi 6e5: 39 f1 cmp %esi,%ecx 6e7: 75 c6 jne 6af p->s.size += bp->s.size; 6e9: 03 43 fc add -0x4(%ebx),%eax freep = p; 6ec: 89 15 80 0d 00 00 mov %edx,0xd80 p->s.size += bp->s.size; 6f2: 89 42 04 mov %eax,0x4(%edx) p->s.ptr = bp->s.ptr; 6f5: 8b 4b f8 mov -0x8(%ebx),%ecx 6f8: 89 0a mov %ecx,(%edx) } 6fa: 5b pop %ebx 6fb: 5e pop %esi 6fc: 5f pop %edi 6fd: 5d pop %ebp 6fe: c3 ret 6ff: 90 nop 00000700 : hp->s.size = nu; free((void*)(hp + 1)); return freep; } void* malloc(uint nbytes) { 700: 55 push %ebp 701: 89 e5 mov %esp,%ebp 703: 57 push %edi 704: 56 push %esi 705: 53 push %ebx 706: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 709: 8b 45 08 mov 0x8(%ebp),%eax if ((prevp = freep) == 0) { 70c: 8b 3d 80 0d 00 00 mov 0xd80,%edi nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 712: 8d 70 07 lea 0x7(%eax),%esi 715: c1 ee 03 shr $0x3,%esi 718: 83 c6 01 add $0x1,%esi if ((prevp = freep) == 0) { 71b: 85 ff test %edi,%edi 71d: 0f 84 9d 00 00 00 je 7c0 base.s.ptr = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 723: 8b 17 mov (%edi),%edx if (p->s.size >= nunits) { 725: 8b 4a 04 mov 0x4(%edx),%ecx 728: 39 f1 cmp %esi,%ecx 72a: 73 6a jae 796 72c: bb 00 10 00 00 mov $0x1000,%ebx 731: 39 de cmp %ebx,%esi 733: 0f 43 de cmovae %esi,%ebx p = sbrk(nu * sizeof(Header)); 736: 8d 04 dd 00 00 00 00 lea 0x0(,%ebx,8),%eax 73d: 89 45 e4 mov %eax,-0x1c(%ebp) 740: eb 17 jmp 759 742: 8d b6 00 00 00 00 lea 0x0(%esi),%esi for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 748: 8b 02 mov (%edx),%eax if (p->s.size >= nunits) { 74a: 8b 48 04 mov 0x4(%eax),%ecx 74d: 39 f1 cmp %esi,%ecx 74f: 73 4f jae 7a0 p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if (p == freep) { 751: 8b 3d 80 0d 00 00 mov 0xd80,%edi 757: 89 c2 mov %eax,%edx 759: 39 d7 cmp %edx,%edi 75b: 75 eb jne 748 p = sbrk(nu * sizeof(Header)); 75d: 83 ec 0c sub $0xc,%esp 760: ff 75 e4 push -0x1c(%ebp) 763: e8 4b fc ff ff call 3b3 if (p == (char*)-1) { 768: 83 c4 10 add $0x10,%esp 76b: 83 f8 ff cmp $0xffffffff,%eax 76e: 74 1c je 78c hp->s.size = nu; 770: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 773: 83 ec 0c sub $0xc,%esp 776: 83 c0 08 add $0x8,%eax 779: 50 push %eax 77a: e8 f1 fe ff ff call 670 return freep; 77f: 8b 15 80 0d 00 00 mov 0xd80,%edx if ((p = morecore(nunits)) == 0) { 785: 83 c4 10 add $0x10,%esp 788: 85 d2 test %edx,%edx 78a: 75 bc jne 748 return 0; } } } } 78c: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 78f: 31 c0 xor %eax,%eax } 791: 5b pop %ebx 792: 5e pop %esi 793: 5f pop %edi 794: 5d pop %ebp 795: c3 ret if (p->s.size >= nunits) { 796: 89 d0 mov %edx,%eax 798: 89 fa mov %edi,%edx 79a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if (p->s.size == nunits) { 7a0: 39 ce cmp %ecx,%esi 7a2: 74 4c je 7f0 p->s.size -= nunits; 7a4: 29 f1 sub %esi,%ecx 7a6: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 7a9: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 7ac: 89 70 04 mov %esi,0x4(%eax) freep = prevp; 7af: 89 15 80 0d 00 00 mov %edx,0xd80 } 7b5: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 7b8: 83 c0 08 add $0x8,%eax } 7bb: 5b pop %ebx 7bc: 5e pop %esi 7bd: 5f pop %edi 7be: 5d pop %ebp 7bf: c3 ret base.s.ptr = freep = prevp = &base; 7c0: c7 05 80 0d 00 00 84 movl $0xd84,0xd80 7c7: 0d 00 00 base.s.size = 0; 7ca: bf 84 0d 00 00 mov $0xd84,%edi base.s.ptr = freep = prevp = &base; 7cf: c7 05 84 0d 00 00 84 movl $0xd84,0xd84 7d6: 0d 00 00 for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 7d9: 89 fa mov %edi,%edx base.s.size = 0; 7db: c7 05 88 0d 00 00 00 movl $0x0,0xd88 7e2: 00 00 00 if (p->s.size >= nunits) { 7e5: e9 42 ff ff ff jmp 72c 7ea: 8d b6 00 00 00 00 lea 0x0(%esi),%esi prevp->s.ptr = p->s.ptr; 7f0: 8b 08 mov (%eax),%ecx 7f2: 89 0a mov %ecx,(%edx) 7f4: eb b9 jmp 7af