⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 malloc.c

📁 上课老师给的8086仿真器
💻 C
字号:
/***********************************************************************/
/*  This file is part of the C51 Compiler package                      */
/*  Copyright KEIL ELEKTRONIK GmbH 1993                                */
/***********************************************************************/
/*                                                                     */
/*  MALLOC.C:                                                          */
/*                                                                     */
/*  To translate this file use C51 with the following invocation:      */
/*                                                                     */
/*     C51 MALLOC.C  <memory model>                                    */
/*                                                                     */
/*  To link the modified MALLOC.OBJ file to your application use the   */
/*  following L51 invocation:                                          */
/*                                                                     */
/*     L51 <your object file list>, MALLOC.OBJ <controls>              */
/*                                                                     */
/***********************************************************************/

struct mem  {
  struct mem xdata *next;
  struct mem xdata *prev;
  unsigned int       len;
  unsigned char      mem[1];
};

extern struct mem xdata *__mp__;


void *malloc (unsigned int size)  {
  struct mem xdata *p;
  struct mem xdata *np;

  if (size > 0xfffb)  return ((void *) 0);
  size += (sizeof (struct mem) - 1);
  p = __mp__;

  while (1)  {
    if ((((unsigned int) p->next)-((unsigned int) p) - p->len) >= size) break;
    p = p->next;
    if (!p->next)  return ((void *) 0);
  }
  if (!p->len)  {  p->len = size;  return (p->mem);  }
  np = (void xdata *) p + p->len;
  np->next = p->next;
  np->prev = p;
  p->next  = np;
  if (np->next)  np->next->prev = np;
  np->len  = size;
  return (np->mem);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -