_argtest: file format elf32-i386 Disassembly of section .text: 00000000
: #include "types.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 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: 51 push %ecx 11: 83 ec 08 sub $0x8,%esp 14: 8b 31 mov (%ecx),%esi 16: 8b 79 04 mov 0x4(%ecx),%edi for (int i = 1; i < argc; i++) { 19: 83 fe 01 cmp $0x1,%esi 1c: 7e 24 jle 42 1e: bb 01 00 00 00 mov $0x1,%ebx 23: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 27: 90 nop printf(1, "Arg %d: %s\n", i, argv[i]); 28: ff 34 9f push (%edi,%ebx,4) 2b: 53 push %ebx for (int i = 1; i < argc; i++) { 2c: 83 c3 01 add $0x1,%ebx printf(1, "Arg %d: %s\n", i, argv[i]); 2f: 68 38 07 00 00 push $0x738 34: 6a 01 push $0x1 36: e8 d5 03 00 00 call 410 for (int i = 1; i < argc; i++) { 3b: 83 c4 10 add $0x10,%esp 3e: 39 de cmp %ebx,%esi 40: 75 e6 jne 28 } exit(); 42: e8 5c 02 00 00 call 2a3 47: 66 90 xchg %ax,%ax 49: 66 90 xchg %ax,%ax 4b: 66 90 xchg %ax,%ax 4d: 66 90 xchg %ax,%ax 4f: 90 nop 00000050 : #include "stat.h" #include "fcntl.h" #include "user.h" #include "x86.h" char*strcpy(char *s, const char *t) { 50: 55 push %ebp char *os; os = s; while ((*s++ = *t++) != 0) { 51: 31 c0 xor %eax,%eax char*strcpy(char *s, const char *t) { 53: 89 e5 mov %esp,%ebp 55: 53 push %ebx 56: 8b 4d 08 mov 0x8(%ebp),%ecx 59: 8b 5d 0c mov 0xc(%ebp),%ebx 5c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi while ((*s++ = *t++) != 0) { 60: 0f b6 14 03 movzbl (%ebx,%eax,1),%edx 64: 88 14 01 mov %dl,(%ecx,%eax,1) 67: 83 c0 01 add $0x1,%eax 6a: 84 d2 test %dl,%dl 6c: 75 f2 jne 60 ; } return os; } 6e: 8b 5d fc mov -0x4(%ebp),%ebx 71: 89 c8 mov %ecx,%eax 73: c9 leave 74: c3 ret 75: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 7c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000080 : int strcmp(const char *p, const char *q) { 80: 55 push %ebp 81: 89 e5 mov %esp,%ebp 83: 53 push %ebx 84: 8b 55 08 mov 0x8(%ebp),%edx 87: 8b 4d 0c mov 0xc(%ebp),%ecx while (*p && *p == *q) { 8a: 0f b6 02 movzbl (%edx),%eax 8d: 84 c0 test %al,%al 8f: 75 17 jne a8 91: eb 3a jmp cd 93: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 97: 90 nop 98: 0f b6 42 01 movzbl 0x1(%edx),%eax p++, q++; 9c: 83 c2 01 add $0x1,%edx 9f: 8d 59 01 lea 0x1(%ecx),%ebx while (*p && *p == *q) { a2: 84 c0 test %al,%al a4: 74 1a je c0 p++, q++; a6: 89 d9 mov %ebx,%ecx while (*p && *p == *q) { a8: 0f b6 19 movzbl (%ecx),%ebx ab: 38 c3 cmp %al,%bl ad: 74 e9 je 98 } return (uchar) * p - (uchar) * q; af: 29 d8 sub %ebx,%eax } b1: 8b 5d fc mov -0x4(%ebp),%ebx b4: c9 leave b5: c3 ret b6: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi bd: 8d 76 00 lea 0x0(%esi),%esi return (uchar) * p - (uchar) * q; c0: 0f b6 59 01 movzbl 0x1(%ecx),%ebx c4: 31 c0 xor %eax,%eax c6: 29 d8 sub %ebx,%eax } c8: 8b 5d fc mov -0x4(%ebp),%ebx cb: c9 leave cc: c3 ret return (uchar) * p - (uchar) * q; cd: 0f b6 19 movzbl (%ecx),%ebx d0: 31 c0 xor %eax,%eax d2: eb db jmp af d4: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi db: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi df: 90 nop 000000e0 : uint strlen(const char *s) { e0: 55 push %ebp e1: 89 e5 mov %esp,%ebp e3: 8b 55 08 mov 0x8(%ebp),%edx int n; for (n = 0; s[n]; n++) { e6: 80 3a 00 cmpb $0x0,(%edx) e9: 74 15 je 100 eb: 31 c0 xor %eax,%eax ed: 8d 76 00 lea 0x0(%esi),%esi f0: 83 c0 01 add $0x1,%eax f3: 80 3c 02 00 cmpb $0x0,(%edx,%eax,1) f7: 89 c1 mov %eax,%ecx f9: 75 f5 jne f0 ; } return n; } fb: 89 c8 mov %ecx,%eax fd: 5d pop %ebp fe: c3 ret ff: 90 nop for (n = 0; s[n]; n++) { 100: 31 c9 xor %ecx,%ecx } 102: 5d pop %ebp 103: 89 c8 mov %ecx,%eax 105: c3 ret 106: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 10d: 8d 76 00 lea 0x0(%esi),%esi 00000110 : void* memset(void *dst, int c, uint n) { 110: 55 push %ebp 111: 89 e5 mov %esp,%ebp 113: 57 push %edi 114: 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" : 117: 8b 4d 10 mov 0x10(%ebp),%ecx 11a: 8b 45 0c mov 0xc(%ebp),%eax 11d: 89 d7 mov %edx,%edi 11f: fc cld 120: f3 aa rep stos %al,%es:(%edi) stosb(dst, c, n); return dst; } 122: 8b 7d fc mov -0x4(%ebp),%edi 125: 89 d0 mov %edx,%eax 127: c9 leave 128: c3 ret 129: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 00000130 : char* strchr(const char *s, char c) { 130: 55 push %ebp 131: 89 e5 mov %esp,%ebp 133: 8b 45 08 mov 0x8(%ebp),%eax 136: 0f b6 4d 0c movzbl 0xc(%ebp),%ecx for (; *s; s++) { 13a: 0f b6 10 movzbl (%eax),%edx 13d: 84 d2 test %dl,%dl 13f: 75 12 jne 153 141: eb 1d jmp 160 143: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 147: 90 nop 148: 0f b6 50 01 movzbl 0x1(%eax),%edx 14c: 83 c0 01 add $0x1,%eax 14f: 84 d2 test %dl,%dl 151: 74 0d je 160 if (*s == c) { 153: 38 d1 cmp %dl,%cl 155: 75 f1 jne 148 return (char*)s; } } return 0; } 157: 5d pop %ebp 158: c3 ret 159: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi return 0; 160: 31 c0 xor %eax,%eax } 162: 5d pop %ebp 163: c3 ret 164: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 16b: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 16f: 90 nop 00000170 : char* gets(char *buf, int max) { 170: 55 push %ebp 171: 89 e5 mov %esp,%ebp 173: 57 push %edi 174: 56 push %esi int i, cc; char c; for (i = 0; i + 1 < max;) { cc = read(0, &c, 1); 175: 8d 7d e7 lea -0x19(%ebp),%edi char* gets(char *buf, int max) { 178: 53 push %ebx for (i = 0; i + 1 < max;) { 179: 31 db xor %ebx,%ebx char* gets(char *buf, int max) { 17b: 83 ec 1c sub $0x1c,%esp for (i = 0; i + 1 < max;) { 17e: eb 27 jmp 1a7 cc = read(0, &c, 1); 180: 83 ec 04 sub $0x4,%esp 183: 6a 01 push $0x1 185: 57 push %edi 186: 6a 00 push $0x0 188: e8 2e 01 00 00 call 2bb if (cc < 1) { 18d: 83 c4 10 add $0x10,%esp 190: 85 c0 test %eax,%eax 192: 7e 1d jle 1b1 break; } buf[i++] = c; 194: 0f b6 45 e7 movzbl -0x19(%ebp),%eax 198: 8b 55 08 mov 0x8(%ebp),%edx 19b: 88 44 1a ff mov %al,-0x1(%edx,%ebx,1) if (c == '\n' || c == '\r') { 19f: 3c 0a cmp $0xa,%al 1a1: 74 1d je 1c0 1a3: 3c 0d cmp $0xd,%al 1a5: 74 19 je 1c0 for (i = 0; i + 1 < max;) { 1a7: 89 de mov %ebx,%esi 1a9: 83 c3 01 add $0x1,%ebx 1ac: 3b 5d 0c cmp 0xc(%ebp),%ebx 1af: 7c cf jl 180 break; } } buf[i] = '\0'; 1b1: 8b 45 08 mov 0x8(%ebp),%eax 1b4: c6 04 30 00 movb $0x0,(%eax,%esi,1) return buf; } 1b8: 8d 65 f4 lea -0xc(%ebp),%esp 1bb: 5b pop %ebx 1bc: 5e pop %esi 1bd: 5f pop %edi 1be: 5d pop %ebp 1bf: c3 ret buf[i] = '\0'; 1c0: 8b 45 08 mov 0x8(%ebp),%eax 1c3: 89 de mov %ebx,%esi 1c5: c6 04 30 00 movb $0x0,(%eax,%esi,1) } 1c9: 8d 65 f4 lea -0xc(%ebp),%esp 1cc: 5b pop %ebx 1cd: 5e pop %esi 1ce: 5f pop %edi 1cf: 5d pop %ebp 1d0: c3 ret 1d1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1d8: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 1df: 90 nop 000001e0 : int stat(const char *n, struct stat *st) { 1e0: 55 push %ebp 1e1: 89 e5 mov %esp,%ebp 1e3: 56 push %esi 1e4: 53 push %ebx int fd; int r; fd = open(n, O_RDONLY); 1e5: 83 ec 08 sub $0x8,%esp 1e8: 6a 00 push $0x0 1ea: ff 75 08 push 0x8(%ebp) 1ed: e8 19 01 00 00 call 30b if (fd < 0) { 1f2: 83 c4 10 add $0x10,%esp 1f5: 85 c0 test %eax,%eax 1f7: 78 27 js 220 return -1; } r = fstat(fd, st); 1f9: 83 ec 08 sub $0x8,%esp 1fc: ff 75 0c push 0xc(%ebp) 1ff: 89 c3 mov %eax,%ebx 201: 50 push %eax 202: e8 cc 00 00 00 call 2d3 close(fd); 207: 89 1c 24 mov %ebx,(%esp) r = fstat(fd, st); 20a: 89 c6 mov %eax,%esi close(fd); 20c: e8 2a 01 00 00 call 33b return r; 211: 83 c4 10 add $0x10,%esp } 214: 8d 65 f8 lea -0x8(%ebp),%esp 217: 89 f0 mov %esi,%eax 219: 5b pop %ebx 21a: 5e pop %esi 21b: 5d pop %ebp 21c: c3 ret 21d: 8d 76 00 lea 0x0(%esi),%esi return -1; 220: be ff ff ff ff mov $0xffffffff,%esi 225: eb ed jmp 214 227: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 22e: 66 90 xchg %ax,%ax 00000230 : int atoi(const char *s) { 230: 55 push %ebp 231: 89 e5 mov %esp,%ebp 233: 53 push %ebx 234: 8b 55 08 mov 0x8(%ebp),%edx int n; n = 0; while ('0' <= *s && *s <= '9') { 237: 0f be 02 movsbl (%edx),%eax 23a: 8d 48 d0 lea -0x30(%eax),%ecx 23d: 80 f9 09 cmp $0x9,%cl n = 0; 240: b9 00 00 00 00 mov $0x0,%ecx while ('0' <= *s && *s <= '9') { 245: 77 1e ja 265 247: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 24e: 66 90 xchg %ax,%ax n = n * 10 + *s++ - '0'; 250: 83 c2 01 add $0x1,%edx 253: 8d 0c 89 lea (%ecx,%ecx,4),%ecx 256: 8d 4c 48 d0 lea -0x30(%eax,%ecx,2),%ecx while ('0' <= *s && *s <= '9') { 25a: 0f be 02 movsbl (%edx),%eax 25d: 8d 58 d0 lea -0x30(%eax),%ebx 260: 80 fb 09 cmp $0x9,%bl 263: 76 eb jbe 250 } return n; } 265: 8b 5d fc mov -0x4(%ebp),%ebx 268: 89 c8 mov %ecx,%eax 26a: c9 leave 26b: c3 ret 26c: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 00000270 : void* memmove(void *vdst, const void *vsrc, int n) { 270: 55 push %ebp 271: 89 e5 mov %esp,%ebp 273: 57 push %edi 274: 8b 45 10 mov 0x10(%ebp),%eax 277: 8b 55 08 mov 0x8(%ebp),%edx 27a: 56 push %esi 27b: 8b 75 0c mov 0xc(%ebp),%esi char *dst; const char *src; dst = vdst; src = vsrc; while (n-- > 0) { 27e: 85 c0 test %eax,%eax 280: 7e 13 jle 295 282: 01 d0 add %edx,%eax dst = vdst; 284: 89 d7 mov %edx,%edi 286: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 28d: 8d 76 00 lea 0x0(%esi),%esi *dst++ = *src++; 290: a4 movsb %ds:(%esi),%es:(%edi) while (n-- > 0) { 291: 39 f8 cmp %edi,%eax 293: 75 fb jne 290 } return vdst; } 295: 5e pop %esi 296: 89 d0 mov %edx,%eax 298: 5f pop %edi 299: 5d pop %ebp 29a: c3 ret 0000029b : name: \ movl $SYS_ ## name, %eax; \ int $T_SYSCALL; \ ret SYSCALL(fork) 29b: b8 01 00 00 00 mov $0x1,%eax 2a0: cd 40 int $0x40 2a2: c3 ret 000002a3 : SYSCALL(exit) 2a3: b8 02 00 00 00 mov $0x2,%eax 2a8: cd 40 int $0x40 2aa: c3 ret 000002ab : SYSCALL(wait) 2ab: b8 03 00 00 00 mov $0x3,%eax 2b0: cd 40 int $0x40 2b2: c3 ret 000002b3 : SYSCALL(pipe) 2b3: b8 04 00 00 00 mov $0x4,%eax 2b8: cd 40 int $0x40 2ba: c3 ret 000002bb : SYSCALL(read) 2bb: b8 05 00 00 00 mov $0x5,%eax 2c0: cd 40 int $0x40 2c2: c3 ret 000002c3 : SYSCALL(kill) 2c3: b8 06 00 00 00 mov $0x6,%eax 2c8: cd 40 int $0x40 2ca: c3 ret 000002cb : SYSCALL(exec) 2cb: b8 07 00 00 00 mov $0x7,%eax 2d0: cd 40 int $0x40 2d2: c3 ret 000002d3 : SYSCALL(fstat) 2d3: b8 08 00 00 00 mov $0x8,%eax 2d8: cd 40 int $0x40 2da: c3 ret 000002db : SYSCALL(chdir) 2db: b8 09 00 00 00 mov $0x9,%eax 2e0: cd 40 int $0x40 2e2: c3 ret 000002e3 : SYSCALL(dup) 2e3: b8 0a 00 00 00 mov $0xa,%eax 2e8: cd 40 int $0x40 2ea: c3 ret 000002eb : SYSCALL(getpid) 2eb: b8 0b 00 00 00 mov $0xb,%eax 2f0: cd 40 int $0x40 2f2: c3 ret 000002f3 : SYSCALL(sbrk) 2f3: b8 0c 00 00 00 mov $0xc,%eax 2f8: cd 40 int $0x40 2fa: c3 ret 000002fb : SYSCALL(sleep) 2fb: b8 0d 00 00 00 mov $0xd,%eax 300: cd 40 int $0x40 302: c3 ret 00000303 : SYSCALL(uptime) 303: b8 0e 00 00 00 mov $0xe,%eax 308: cd 40 int $0x40 30a: c3 ret 0000030b : SYSCALL(open) 30b: b8 0f 00 00 00 mov $0xf,%eax 310: cd 40 int $0x40 312: c3 ret 00000313 : SYSCALL(write) 313: b8 10 00 00 00 mov $0x10,%eax 318: cd 40 int $0x40 31a: c3 ret 0000031b : SYSCALL(mknod) 31b: b8 11 00 00 00 mov $0x11,%eax 320: cd 40 int $0x40 322: c3 ret 00000323 : SYSCALL(unlink) 323: b8 12 00 00 00 mov $0x12,%eax 328: cd 40 int $0x40 32a: c3 ret 0000032b : SYSCALL(link) 32b: b8 13 00 00 00 mov $0x13,%eax 330: cd 40 int $0x40 332: c3 ret 00000333 : SYSCALL(mkdir) 333: b8 14 00 00 00 mov $0x14,%eax 338: cd 40 int $0x40 33a: c3 ret 0000033b : SYSCALL(close) 33b: b8 15 00 00 00 mov $0x15,%eax 340: cd 40 int $0x40 342: c3 ret 00000343 : SYSCALL(getch) 343: b8 16 00 00 00 mov $0x16,%eax 348: cd 40 int $0x40 34a: c3 ret 0000034b : SYSCALL(greeting) 34b: b8 17 00 00 00 mov $0x17,%eax 350: cd 40 int $0x40 352: c3 ret 00000353 : SYSCALL(shutdown) 353: b8 18 00 00 00 mov $0x18,%eax 358: cd 40 int $0x40 35a: c3 ret 35b: 66 90 xchg %ax,%ax 35d: 66 90 xchg %ax,%ax 35f: 90 nop 00000360 : static void putc(int fd, char c) { write(fd, &c, 1); } static void printint(int fd, int xx, int base, int sgn) { 360: 55 push %ebp 361: 89 e5 mov %esp,%ebp 363: 57 push %edi 364: 56 push %esi 365: 53 push %ebx 366: 83 ec 3c sub $0x3c,%esp 369: 89 4d c4 mov %ecx,-0x3c(%ebp) uint x; neg = 0; if (sgn && xx < 0) { neg = 1; x = -xx; 36c: 89 d1 mov %edx,%ecx static void printint(int fd, int xx, int base, int sgn) { 36e: 89 45 b8 mov %eax,-0x48(%ebp) if (sgn && xx < 0) { 371: 85 d2 test %edx,%edx 373: 0f 89 7f 00 00 00 jns 3f8 379: f6 45 08 01 testb $0x1,0x8(%ebp) 37d: 74 79 je 3f8 neg = 1; 37f: c7 45 bc 01 00 00 00 movl $0x1,-0x44(%ebp) x = -xx; 386: f7 d9 neg %ecx } else { x = xx; } i = 0; 388: 31 db xor %ebx,%ebx 38a: 8d 75 d7 lea -0x29(%ebp),%esi 38d: 8d 76 00 lea 0x0(%esi),%esi do { buf[i++] = digits[x % base]; 390: 89 c8 mov %ecx,%eax 392: 31 d2 xor %edx,%edx 394: 89 cf mov %ecx,%edi 396: f7 75 c4 divl -0x3c(%ebp) 399: 0f b6 92 a4 07 00 00 movzbl 0x7a4(%edx),%edx 3a0: 89 45 c0 mov %eax,-0x40(%ebp) 3a3: 89 d8 mov %ebx,%eax 3a5: 8d 5b 01 lea 0x1(%ebx),%ebx } while ((x /= base) != 0); 3a8: 8b 4d c0 mov -0x40(%ebp),%ecx buf[i++] = digits[x % base]; 3ab: 88 14 1e mov %dl,(%esi,%ebx,1) while ((x /= base) != 0); 3ae: 39 7d c4 cmp %edi,-0x3c(%ebp) 3b1: 76 dd jbe 390 if (neg) { 3b3: 8b 4d bc mov -0x44(%ebp),%ecx 3b6: 85 c9 test %ecx,%ecx 3b8: 74 0c je 3c6 buf[i++] = '-'; 3ba: c6 44 1d d8 2d movb $0x2d,-0x28(%ebp,%ebx,1) buf[i++] = digits[x % base]; 3bf: 89 d8 mov %ebx,%eax buf[i++] = '-'; 3c1: ba 2d 00 00 00 mov $0x2d,%edx } while (--i >= 0) { 3c6: 8b 7d b8 mov -0x48(%ebp),%edi 3c9: 8d 5c 05 d7 lea -0x29(%ebp,%eax,1),%ebx 3cd: eb 07 jmp 3d6 3cf: 90 nop putc(fd, buf[i]); 3d0: 0f b6 13 movzbl (%ebx),%edx 3d3: 83 eb 01 sub $0x1,%ebx write(fd, &c, 1); 3d6: 83 ec 04 sub $0x4,%esp 3d9: 88 55 d7 mov %dl,-0x29(%ebp) 3dc: 6a 01 push $0x1 3de: 56 push %esi 3df: 57 push %edi 3e0: e8 2e ff ff ff call 313 while (--i >= 0) { 3e5: 83 c4 10 add $0x10,%esp 3e8: 39 de cmp %ebx,%esi 3ea: 75 e4 jne 3d0 } } 3ec: 8d 65 f4 lea -0xc(%ebp),%esp 3ef: 5b pop %ebx 3f0: 5e pop %esi 3f1: 5f pop %edi 3f2: 5d pop %ebp 3f3: c3 ret 3f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi neg = 0; 3f8: c7 45 bc 00 00 00 00 movl $0x0,-0x44(%ebp) 3ff: eb 87 jmp 388 401: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 408: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 40f: 90 nop 00000410 : // Print to the given fd. Only understands %d, %x, %p, %s. void printf(int fd, const char *fmt, ...) { 410: 55 push %ebp 411: 89 e5 mov %esp,%ebp 413: 57 push %edi 414: 56 push %esi 415: 53 push %ebx 416: 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++) { 419: 8b 5d 0c mov 0xc(%ebp),%ebx void printf(int fd, const char *fmt, ...) { 41c: 8b 75 08 mov 0x8(%ebp),%esi for (i = 0; fmt[i]; i++) { 41f: 0f b6 13 movzbl (%ebx),%edx 422: 84 d2 test %dl,%dl 424: 74 6a je 490 ap = (uint*)(void*)&fmt + 1; 426: 8d 45 10 lea 0x10(%ebp),%eax 429: 83 c3 01 add $0x1,%ebx write(fd, &c, 1); 42c: 8d 7d e7 lea -0x19(%ebp),%edi state = 0; 42f: 31 c9 xor %ecx,%ecx ap = (uint*)(void*)&fmt + 1; 431: 89 45 d0 mov %eax,-0x30(%ebp) 434: eb 36 jmp 46c 436: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 43d: 8d 76 00 lea 0x0(%esi),%esi 440: 89 4d d4 mov %ecx,-0x2c(%ebp) c = fmt[i] & 0xff; if (state == 0) { if (c == '%') { state = '%'; 443: b9 25 00 00 00 mov $0x25,%ecx if (c == '%') { 448: 83 f8 25 cmp $0x25,%eax 44b: 74 15 je 462 write(fd, &c, 1); 44d: 83 ec 04 sub $0x4,%esp 450: 88 55 e7 mov %dl,-0x19(%ebp) 453: 6a 01 push $0x1 455: 57 push %edi 456: 56 push %esi 457: e8 b7 fe ff ff call 313 45c: 8b 4d d4 mov -0x2c(%ebp),%ecx } else { putc(fd, c); 45f: 83 c4 10 add $0x10,%esp for (i = 0; fmt[i]; i++) { 462: 0f b6 13 movzbl (%ebx),%edx 465: 83 c3 01 add $0x1,%ebx 468: 84 d2 test %dl,%dl 46a: 74 24 je 490 c = fmt[i] & 0xff; 46c: 0f b6 c2 movzbl %dl,%eax if (state == 0) { 46f: 85 c9 test %ecx,%ecx 471: 74 cd je 440 } } else if (state == '%') { 473: 83 f9 25 cmp $0x25,%ecx 476: 75 ea jne 462 if (c == 'd') { 478: 83 f8 25 cmp $0x25,%eax 47b: 0f 84 07 01 00 00 je 588 481: 83 e8 63 sub $0x63,%eax 484: 83 f8 15 cmp $0x15,%eax 487: 77 17 ja 4a0 489: ff 24 85 4c 07 00 00 jmp *0x74c(,%eax,4) putc(fd, c); } state = 0; } } } 490: 8d 65 f4 lea -0xc(%ebp),%esp 493: 5b pop %ebx 494: 5e pop %esi 495: 5f pop %edi 496: 5d pop %ebp 497: c3 ret 498: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 49f: 90 nop write(fd, &c, 1); 4a0: 83 ec 04 sub $0x4,%esp 4a3: 88 55 d4 mov %dl,-0x2c(%ebp) 4a6: 6a 01 push $0x1 4a8: 57 push %edi 4a9: 56 push %esi 4aa: c6 45 e7 25 movb $0x25,-0x19(%ebp) 4ae: e8 60 fe ff ff call 313 putc(fd, c); 4b3: 0f b6 55 d4 movzbl -0x2c(%ebp),%edx write(fd, &c, 1); 4b7: 83 c4 0c add $0xc,%esp 4ba: 88 55 e7 mov %dl,-0x19(%ebp) 4bd: 6a 01 push $0x1 4bf: 57 push %edi 4c0: 56 push %esi 4c1: e8 4d fe ff ff call 313 putc(fd, c); 4c6: 83 c4 10 add $0x10,%esp state = 0; 4c9: 31 c9 xor %ecx,%ecx 4cb: eb 95 jmp 462 4cd: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 16, 0); 4d0: 83 ec 0c sub $0xc,%esp 4d3: b9 10 00 00 00 mov $0x10,%ecx 4d8: 6a 00 push $0x0 4da: 8b 45 d0 mov -0x30(%ebp),%eax 4dd: 8b 10 mov (%eax),%edx 4df: 89 f0 mov %esi,%eax 4e1: e8 7a fe ff ff call 360 ap++; 4e6: 83 45 d0 04 addl $0x4,-0x30(%ebp) 4ea: 83 c4 10 add $0x10,%esp state = 0; 4ed: 31 c9 xor %ecx,%ecx 4ef: e9 6e ff ff ff jmp 462 4f4: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi s = (char*)*ap; 4f8: 8b 45 d0 mov -0x30(%ebp),%eax 4fb: 8b 10 mov (%eax),%edx ap++; 4fd: 83 c0 04 add $0x4,%eax 500: 89 45 d0 mov %eax,-0x30(%ebp) if (s == 0) { 503: 85 d2 test %edx,%edx 505: 0f 84 8d 00 00 00 je 598 while (*s != 0) { 50b: 0f b6 02 movzbl (%edx),%eax state = 0; 50e: 31 c9 xor %ecx,%ecx while (*s != 0) { 510: 84 c0 test %al,%al 512: 0f 84 4a ff ff ff je 462 518: 89 5d d4 mov %ebx,-0x2c(%ebp) 51b: 89 d3 mov %edx,%ebx 51d: 8d 76 00 lea 0x0(%esi),%esi write(fd, &c, 1); 520: 83 ec 04 sub $0x4,%esp s++; 523: 83 c3 01 add $0x1,%ebx 526: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 529: 6a 01 push $0x1 52b: 57 push %edi 52c: 56 push %esi 52d: e8 e1 fd ff ff call 313 while (*s != 0) { 532: 0f b6 03 movzbl (%ebx),%eax 535: 83 c4 10 add $0x10,%esp 538: 84 c0 test %al,%al 53a: 75 e4 jne 520 state = 0; 53c: 8b 5d d4 mov -0x2c(%ebp),%ebx 53f: 31 c9 xor %ecx,%ecx 541: e9 1c ff ff ff jmp 462 546: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 54d: 8d 76 00 lea 0x0(%esi),%esi printint(fd, *ap, 10, 1); 550: 83 ec 0c sub $0xc,%esp 553: b9 0a 00 00 00 mov $0xa,%ecx 558: 6a 01 push $0x1 55a: e9 7b ff ff ff jmp 4da 55f: 90 nop putc(fd, *ap); 560: 8b 45 d0 mov -0x30(%ebp),%eax write(fd, &c, 1); 563: 83 ec 04 sub $0x4,%esp putc(fd, *ap); 566: 8b 00 mov (%eax),%eax write(fd, &c, 1); 568: 6a 01 push $0x1 56a: 57 push %edi 56b: 56 push %esi putc(fd, *ap); 56c: 88 45 e7 mov %al,-0x19(%ebp) write(fd, &c, 1); 56f: e8 9f fd ff ff call 313 ap++; 574: 83 45 d0 04 addl $0x4,-0x30(%ebp) 578: 83 c4 10 add $0x10,%esp state = 0; 57b: 31 c9 xor %ecx,%ecx 57d: e9 e0 fe ff ff jmp 462 582: 8d b6 00 00 00 00 lea 0x0(%esi),%esi putc(fd, c); 588: 88 55 e7 mov %dl,-0x19(%ebp) write(fd, &c, 1); 58b: 83 ec 04 sub $0x4,%esp 58e: e9 2a ff ff ff jmp 4bd 593: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi 597: 90 nop s = "(null)"; 598: ba 44 07 00 00 mov $0x744,%edx while (*s != 0) { 59d: 89 5d d4 mov %ebx,-0x2c(%ebp) 5a0: b8 28 00 00 00 mov $0x28,%eax 5a5: 89 d3 mov %edx,%ebx 5a7: e9 74 ff ff ff jmp 520 5ac: 66 90 xchg %ax,%ax 5ae: 66 90 xchg %ax,%ax 000005b0 : typedef union header Header; static Header base; static Header *freep; void free(void *ap) { 5b0: 55 push %ebp Header *bp, *p; bp = (Header*)ap - 1; for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) { 5b1: a1 58 0a 00 00 mov 0xa58,%eax void free(void *ap) { 5b6: 89 e5 mov %esp,%ebp 5b8: 57 push %edi 5b9: 56 push %esi 5ba: 53 push %ebx 5bb: 8b 5d 08 mov 0x8(%ebp),%ebx bp = (Header*)ap - 1; 5be: 8d 4b f8 lea -0x8(%ebx),%ecx for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr) { 5c1: 8d b4 26 00 00 00 00 lea 0x0(%esi,%eiz,1),%esi 5c8: 89 c2 mov %eax,%edx 5ca: 8b 00 mov (%eax),%eax 5cc: 39 ca cmp %ecx,%edx 5ce: 73 30 jae 600 5d0: 39 c1 cmp %eax,%ecx 5d2: 72 04 jb 5d8 if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { 5d4: 39 c2 cmp %eax,%edx 5d6: 72 f0 jb 5c8 break; } } if (bp + bp->s.size == p->s.ptr) { 5d8: 8b 73 fc mov -0x4(%ebx),%esi 5db: 8d 3c f1 lea (%ecx,%esi,8),%edi 5de: 39 f8 cmp %edi,%eax 5e0: 74 30 je 612 bp->s.size += p->s.ptr->s.size; bp->s.ptr = p->s.ptr->s.ptr; 5e2: 89 43 f8 mov %eax,-0x8(%ebx) } else { bp->s.ptr = p->s.ptr; } if (p + p->s.size == bp) { 5e5: 8b 42 04 mov 0x4(%edx),%eax 5e8: 8d 34 c2 lea (%edx,%eax,8),%esi 5eb: 39 f1 cmp %esi,%ecx 5ed: 74 3a je 629 p->s.size += bp->s.size; p->s.ptr = bp->s.ptr; 5ef: 89 0a mov %ecx,(%edx) } else { p->s.ptr = bp; } freep = p; } 5f1: 5b pop %ebx freep = p; 5f2: 89 15 58 0a 00 00 mov %edx,0xa58 } 5f8: 5e pop %esi 5f9: 5f pop %edi 5fa: 5d pop %ebp 5fb: c3 ret 5fc: 8d 74 26 00 lea 0x0(%esi,%eiz,1),%esi if (p >= p->s.ptr && (bp > p || bp < p->s.ptr)) { 600: 39 c2 cmp %eax,%edx 602: 72 c4 jb 5c8 604: 39 c1 cmp %eax,%ecx 606: 73 c0 jae 5c8 if (bp + bp->s.size == p->s.ptr) { 608: 8b 73 fc mov -0x4(%ebx),%esi 60b: 8d 3c f1 lea (%ecx,%esi,8),%edi 60e: 39 f8 cmp %edi,%eax 610: 75 d0 jne 5e2 bp->s.size += p->s.ptr->s.size; 612: 03 70 04 add 0x4(%eax),%esi 615: 89 73 fc mov %esi,-0x4(%ebx) bp->s.ptr = p->s.ptr->s.ptr; 618: 8b 02 mov (%edx),%eax 61a: 8b 00 mov (%eax),%eax 61c: 89 43 f8 mov %eax,-0x8(%ebx) if (p + p->s.size == bp) { 61f: 8b 42 04 mov 0x4(%edx),%eax 622: 8d 34 c2 lea (%edx,%eax,8),%esi 625: 39 f1 cmp %esi,%ecx 627: 75 c6 jne 5ef p->s.size += bp->s.size; 629: 03 43 fc add -0x4(%ebx),%eax freep = p; 62c: 89 15 58 0a 00 00 mov %edx,0xa58 p->s.size += bp->s.size; 632: 89 42 04 mov %eax,0x4(%edx) p->s.ptr = bp->s.ptr; 635: 8b 4b f8 mov -0x8(%ebx),%ecx 638: 89 0a mov %ecx,(%edx) } 63a: 5b pop %ebx 63b: 5e pop %esi 63c: 5f pop %edi 63d: 5d pop %ebp 63e: c3 ret 63f: 90 nop 00000640 : hp->s.size = nu; free((void*)(hp + 1)); return freep; } void* malloc(uint nbytes) { 640: 55 push %ebp 641: 89 e5 mov %esp,%ebp 643: 57 push %edi 644: 56 push %esi 645: 53 push %ebx 646: 83 ec 1c sub $0x1c,%esp Header *p, *prevp; uint nunits; nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 649: 8b 45 08 mov 0x8(%ebp),%eax if ((prevp = freep) == 0) { 64c: 8b 3d 58 0a 00 00 mov 0xa58,%edi nunits = (nbytes + sizeof(Header) - 1) / sizeof(Header) + 1; 652: 8d 70 07 lea 0x7(%eax),%esi 655: c1 ee 03 shr $0x3,%esi 658: 83 c6 01 add $0x1,%esi if ((prevp = freep) == 0) { 65b: 85 ff test %edi,%edi 65d: 0f 84 9d 00 00 00 je 700 base.s.ptr = freep = prevp = &base; base.s.size = 0; } for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 663: 8b 17 mov (%edi),%edx if (p->s.size >= nunits) { 665: 8b 4a 04 mov 0x4(%edx),%ecx 668: 39 f1 cmp %esi,%ecx 66a: 73 6a jae 6d6 66c: bb 00 10 00 00 mov $0x1000,%ebx 671: 39 de cmp %ebx,%esi 673: 0f 43 de cmovae %esi,%ebx p = sbrk(nu * sizeof(Header)); 676: 8d 04 dd 00 00 00 00 lea 0x0(,%ebx,8),%eax 67d: 89 45 e4 mov %eax,-0x1c(%ebp) 680: eb 17 jmp 699 682: 8d b6 00 00 00 00 lea 0x0(%esi),%esi for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 688: 8b 02 mov (%edx),%eax if (p->s.size >= nunits) { 68a: 8b 48 04 mov 0x4(%eax),%ecx 68d: 39 f1 cmp %esi,%ecx 68f: 73 4f jae 6e0 p->s.size = nunits; } freep = prevp; return (void*)(p + 1); } if (p == freep) { 691: 8b 3d 58 0a 00 00 mov 0xa58,%edi 697: 89 c2 mov %eax,%edx 699: 39 d7 cmp %edx,%edi 69b: 75 eb jne 688 p = sbrk(nu * sizeof(Header)); 69d: 83 ec 0c sub $0xc,%esp 6a0: ff 75 e4 push -0x1c(%ebp) 6a3: e8 4b fc ff ff call 2f3 if (p == (char*)-1) { 6a8: 83 c4 10 add $0x10,%esp 6ab: 83 f8 ff cmp $0xffffffff,%eax 6ae: 74 1c je 6cc hp->s.size = nu; 6b0: 89 58 04 mov %ebx,0x4(%eax) free((void*)(hp + 1)); 6b3: 83 ec 0c sub $0xc,%esp 6b6: 83 c0 08 add $0x8,%eax 6b9: 50 push %eax 6ba: e8 f1 fe ff ff call 5b0 return freep; 6bf: 8b 15 58 0a 00 00 mov 0xa58,%edx if ((p = morecore(nunits)) == 0) { 6c5: 83 c4 10 add $0x10,%esp 6c8: 85 d2 test %edx,%edx 6ca: 75 bc jne 688 return 0; } } } } 6cc: 8d 65 f4 lea -0xc(%ebp),%esp return 0; 6cf: 31 c0 xor %eax,%eax } 6d1: 5b pop %ebx 6d2: 5e pop %esi 6d3: 5f pop %edi 6d4: 5d pop %ebp 6d5: c3 ret if (p->s.size >= nunits) { 6d6: 89 d0 mov %edx,%eax 6d8: 89 fa mov %edi,%edx 6da: 8d b6 00 00 00 00 lea 0x0(%esi),%esi if (p->s.size == nunits) { 6e0: 39 ce cmp %ecx,%esi 6e2: 74 4c je 730 p->s.size -= nunits; 6e4: 29 f1 sub %esi,%ecx 6e6: 89 48 04 mov %ecx,0x4(%eax) p += p->s.size; 6e9: 8d 04 c8 lea (%eax,%ecx,8),%eax p->s.size = nunits; 6ec: 89 70 04 mov %esi,0x4(%eax) freep = prevp; 6ef: 89 15 58 0a 00 00 mov %edx,0xa58 } 6f5: 8d 65 f4 lea -0xc(%ebp),%esp return (void*)(p + 1); 6f8: 83 c0 08 add $0x8,%eax } 6fb: 5b pop %ebx 6fc: 5e pop %esi 6fd: 5f pop %edi 6fe: 5d pop %ebp 6ff: c3 ret base.s.ptr = freep = prevp = &base; 700: c7 05 58 0a 00 00 5c movl $0xa5c,0xa58 707: 0a 00 00 base.s.size = 0; 70a: bf 5c 0a 00 00 mov $0xa5c,%edi base.s.ptr = freep = prevp = &base; 70f: c7 05 5c 0a 00 00 5c movl $0xa5c,0xa5c 716: 0a 00 00 for (p = prevp->s.ptr;; prevp = p, p = p->s.ptr) { 719: 89 fa mov %edi,%edx base.s.size = 0; 71b: c7 05 60 0a 00 00 00 movl $0x0,0xa60 722: 00 00 00 if (p->s.size >= nunits) { 725: e9 42 ff ff ff jmp 66c 72a: 8d b6 00 00 00 00 lea 0x0(%esi),%esi prevp->s.ptr = p->s.ptr; 730: 8b 08 mov (%eax),%ecx 732: 89 0a mov %ecx,(%edx) 734: eb b9 jmp 6ef