>>> Åͺ¸ CÀÇ ±íÀº °÷ <<< Á¦2ȸ Åͺ¸ CÀÇ °¢Á¾ ¸Þ¸ð¸® ¸ðµ¨°ú ±× ±¸Á¶ ±Û/ÀÓÀ롂 (¼­¿ï´ë ±â°è°øÇаú4) --------------------------------------------------------------------- 1 º»¹®¿¡ ¾Õ¼­ --------------------------------------------------------------------- Áö³­ ´Þ¿¡´Â Åͺ¸ C°¡ Á¦°øÇÏ´Â ¼¼ Á¾·ùÀÇ Æ÷ÀÎÅÍ, Áï ±Ù°Å¸®/¿ø°Å¸®/ °Å´ë Æ÷ÀÎÅÍÀÇ Æ¯Â¡°ú »ç¿ë½Ã ÁÖÀÇ »çÇ׿¡ ´ëÇÏ¿© ¼³¸íÇß´Ù. À̹ø¿¡´Â ±× Æ÷ÀÎÅ͵éÀ» ÀÌÇØÇÏ´Â µ¥¿¡ ÇʼöÀûÀÎ »çÇ×ÀÎ "¸Þ¸ð¸® ¸ðµ¨(memory model)" ÀÇ ±¸Á¶/Ư¡/Â÷ÀÌÁ¡¿¡ °üÇÏ¿© ¼³¸íÇÏ°Ú´Ù. ¹Ì¸® ¸»ÇÏÁö¸¸ À̹ø ±ÛÀº »ó´ç È÷ ±â¼úÀûÀÎ ³»¿ë ÀÏ»öÀÌ¶ó¼­ ¸¼Àº Á¤½ÅÀ¸·Î ÀÓÇؾßÁö¸¸ ³¡±îÁö ¼º°øÀûÀ¸ ·Î ¿Ïµ¶ÇØ ³¾ ¼ö ÀÖÀ» °ÍÀÌ´Ù. °áÄÚ °¡º±°Ô ÈȾ ¸¸ÇÑ ³»¿ëÀº ¾Æ´Ï´Ù. ±×¸®°í ÇÑ ¹ø Àаí ÀÌÇØÇÏ·Á°í ³Ê¹« ¼º±ÞÇÏ°Ô ´ýºñÁöµµ ¸»±â ¹Ù¶õ´Ù. ÃÖ¼Ò ÇÑ ¼­³Ê¹øÀº Àоî¾ß °¨ÀÌ ÀâÈú °ÍÀ¸·Î º»´Ù. --------------------------------------------------------------------- 2 Åͺ¸ CÀÇ ¸Þ¸ð¸® ¸ðµ¨ °³¿ä --------------------------------------------------------------------- Åͺ¸ C´Â µµÇÕ 6 Á¾·ùÀÇ ¸Þ¸ð¸® ¸ðµ¨À» Á¦°øÇÑ´Ù. ÃʼÒÇü(tiny), ¼Ò Çü, ÁßÇü, Áß¼ÒÇü, ´ëÇü, °Å´ë ¸ðµ¨ µîÀÌ ±×°ÍÀÌ´Ù. À̵éÀÇ ±¸ºÐÀº CS, D S, SS, ES µî ³× °³ÀÇ ¼¼±×¸ÕÆ®¸¦ ¾î¶»°Ô °ü¸®ÇÏ´À³Ä¿¡ ´Þ·Á ÀÖ´Ù. ÇÁ·Î±× ·¡¸Ó´Â ÀÚ½ÅÀÇ »óȲ¿¡ ¾Ë¸Â°Ô À̵é Áß¿¡¼­ ¸Þ¸ð¸® ¸ðµ¨À» ¼±ÅÃÇÏ¿© ÇÁ·Î±× ·¥À» ÀÛ¼ºÇÏ°Ô µÈ´Ù. ÀÌµé ¸ðµ¨ÀÇ °³·«ÀûÀÎ ¼³¸íÀ» ÇÏÀÚ¸é ´ÙÀ½°ú °°´Ù. ³ªÁß¿¡ ´Ù½Ã ±ò²û ÇÏ°Ô ºñ±³/Á¤¸®ÇØ ³õÀ» Å×´Ï Áö±ÝÀº ±×³É ±×·Á·Á´Ï ÇÏ°í ´ëÃæ ÈȾ±â¸¸ Çϱ⠹ٶõ´Ù. ¹«½¼ ¸»ÀÎÁö ¾ð¶æ °¡½¿¿¡ ¿Í ´êÁö ¾Ê´õ¶óµµ ¸»ÀÌ´Ù. 2.1 ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨ [1] ÃʼÒÇü ¸ðµ¨(tiny model) ¸» ±×´ë·Î °¡Àå ÀÛÀº ¸Þ¸ð¸® ¸ðµ¨ÀÌ´Ù. ÀÌ ¸ðµ¨¿¡¼­´Â ¸ðµç ¼¼±×¸ÕÆ® ·¹Áö½ºÅÍ°¡ µ¿ÀÏÇÑ ¹øÁö¿¡ À§Ä¡Çϸç ÇÁ·Î±×·¥ ½ÇÇàÀÇ Àü°úÁ¤À» ÅëÅÐ¾î °í Á¤ÀûÀÌ´Ù. Áï "Ç×»ó CS == DS == SS == ES"ÀÌ´Ù. µû¶ó¼­ ÀÌ ¸ðµ¨¿¡¼­´Â ÃÑ 64k¹ÙÀÌÆ®(Ãà¼Ò °¡´É)ÀÇ ¸Þ¸ð¸® °ø°£¸¸ÀÌ ÄÚµå, µ¥ÀÌÅÍ, ½ºÅÃÀ» À§ÇØ ÇÒ´ç µÈ´Ù. ³ª¸ÓÁö 640k¹ÙÀÌÆ® °ø°£Àº Á÷Á¢ÀûÀ¸·Î Á¦¾îÇÒ ¼ö ¾ø´Ù. ±× ¹Û¿¡ "¸ð µç Æ÷ÀÎÅÍ´Â ±Ù°Å¸® Æ÷ÀÎÅÍ·Î ³»Á¤"µÇ´Â Ư¡ÀÌ ÀÖÀ¸¸ç, À¯ÀÏÇÏ°Ô ÀÌ ¸ðµ¨ ¸¸ÀÌ .COM È­ÀÏÀ» »ý¼ºÇØ ³¾ ¼ö ÀÖ´Ù. ±×°ÍÀº exe2bin.exe À¯Æ¿¸®Æ¼¸¦ »ç ¿ëÇϰųª Åͺ¸ ¸µÄ¿¿¡ /t ¿É¼ÇÀ» ÁöÁ¤ÇÔÀ¸·Î½á °¡´ÉÇÏ´Ù. ·¥»óÁÖ ÇÁ·Î±×·¥ À» Á¦ÀÛÇÒ ¶§¿¡´Â ÀÌ ¸ðµ¨À» ¾²´Â °ÍÀÌ ÀϹÝÀûÀÌ´Ù. [2] ¼ÒÇü ¸ðµ¨(small model) ÀÌ ¸ðµ¨¿¡¼­´Â DS == SS == ESÀÌÁö¸¸ CS != DSÀÌ´Ù. Áï ÄÚµå ¼¼±×¸ÕÆ® ¿Í µ¥ÀÌÅÍ ¹× ½ºÅà ¼¼±×¸ÕÆ®°¡ ºÐ¸®µÈ´Ù. µû¶ó¼­ ÃʼÒÇü ¸ðµ¨¿¡¼­¿Í´Â ´Þ ¸® ½ºÅà ¶Ç´Â µ¥ÀÌÅÍ°¡ ÄÚµå ¿µ¿ªÀ» ħ¹üÇÒ ¿°·Á°¡ (Á¤»óÀûÀÎ °æ¿ì) Àý´ë ¾ø´Ù. ÀÌ ¸ðµ¨¿¡¼­´Â ÃÖ´ë 64k¹ÙÀÌÆ®ÀÇ ÄÚµå ¿µ¿ª°ú ÃÑ 64k¹ÙÀÌÆ®(Ãà¼Ò °¡ ´É)ÀÇ µ¥ÀÌÅÍ/½ºÅà ¿µ¿ªÀÌ Á¸ÀçÇϸç, °á°úÀûÀ¸·Î ÃÖ¼Ò 64k(Ãà¼Ò °¡´É), ÃÖ ´ë 128kÀÇ ¸Þ¸ð¸®¸¦ Á÷Á¢ÀûÀ¸·Î »ç¿ëÇÒ ¼ö ÀÖ´Ù. "¸ðµç Æ÷ÀÎÅÍ´Â ±Ù°Å¸® Æ÷ÀÎÅÍ·Î ³»Á¤"µÇ¸ç, ´ëºÎºÐÀÇ ÀÀ¿ë ÇÁ·Î±×·¥¿¡¼­ ÀÌ ¸ðµ¨Àº Àû´çÇÑ Å©±â ¸¦ °¡Áø´Ù. ½ÇÁ¦·Î Åͺ¸ C¿¡¼­´Â º°µµÀÇ ÄÄÆÄÀÏ·¯ ¿É¼ÇÀ» ÁöÁ¤(º¯°æ)ÇÏÁö ¾Ê´Â ÇÑ ¼ÒÇü ¸ðµ¨ÀÌ ³»Á¤µÈ´Ù. [3] ÁßÇü ¸ðµ¨(medium model) ÇÔ¼ö Æ÷ÀÎÅÍ´Â ¿ø°Å¸® Æ÷ÀÎÅÍ·Î ³»Á¤µÈ´Ù. µû¶ó¼­ ÄÚµå´Â 64k¹ÙÀÌÆ®¸¦ °¡»ÓÈ÷ ÃÊ°úÇÒ ¼ö ÀÖ´Ù. ´Ü, ¸ðµâº° ºÐÇÒ ÄÄÆÄÀÏÀ» Çؾ߸¸ ÃÊ°ú°¡ °¡´ÉÇÏ ´Ù´Â ÀüÁ¦°¡ ÀÖ±â´Â ÇÏ´Ù. ÇÏÁö¸¸ µ¥ÀÌÅÍ Æ÷ÀÎÅÍ´Â ±Ù°Å¸® Æ÷ÀÎÅÍ·Î ³»Á¤ µÇ¹Ç·Î µ¥ÀÌÅÍ ¹× ½ºÅÃÀº ÃÑ 64k¹ÙÀÌÆ®(Ãà¼Ò °¡´É)ÀÇ °ø°£À» Â÷ÁöÇÑ´Ù. ÀÌ ¸ðµ¨Àº µ¥ÀÌÅ͸¦ º°·Î ¾²Áö ¾Ê´Â ´ëÇü ÇÁ·Î±×·¥¿¡ Àû´çÇÏ´Ù(½ÇÁ¦·Î´Â º°·Î ¾È ¾²ÀÓ). Âü°í·Î ÇÔ¼ö Æ÷ÀÎÅÍ°¡ ¿ø°Å¸® Æ÷ÀÎÅÍ·Î ³»Á¤µÈ´Ù´Â ¸»Àº ¸ðµç ÇÔ¼ö È£ÃâÀÌ ¿ø°Å¸® È£Ãâ(far call)·Î ³»Á¤µÈ´Ù´Â ¶æµµ Æ÷ÇÔÇÑ´Ù. 2.2 ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨ [4] Áß¼ÒÇü ¸ðµ¨(compact model) ÀÌ ¸ðµ¨Àº ÁßÇü ¸ðµ¨ÀÇ ¹Ý´ëÀÌ´Ù. Áï µ¥ÀÌÅÍ Æ÷ÀÎÅÍ·Î ¿ø°Å¸® Æ÷ÀÎÅÍ °¡ ³»Á¤µÇ°í, ÇÔ¼ö Æ÷ÀÎÅÍ´Â ±Ù°Å¸® Æ÷ÀÎÅÍ·Î ³»Á¤µÈ´Ù. ±×¸®°í ÇÔ¼ö È£Ãâ Àº ¿ø°Å¸® È£Ãâ·Î ³»Á¤µÈ´Ù. µû¶ó¼­ ÄÚµå´Â ÃÖ´ë 64k¹ÙÀÌÆ®¸¦ ÃÊ°úÇÒ ¼ö ¾øÀ¸¸ç, µ¥ÀÌÅÍ Æ÷ÀÎÅÍ·Î 1M¹ÙÀÌÆ® °ø°£(Èü Æ÷ÇÔ)À» Á÷Á¢ÀûÀ¸·Î ÂüÁ¶ÇÒ ¼ö ÀÖ´Ù. ÇÏÁö¸¸ Á¤Àû µ¥ÀÌÅÍ´Â ÃÖ´ë 64k¹ÙÀÌÆ®¸¦ ÃÊ°úÇÒ ¼ö ¾ø´Ù. ÇÑÆí ÄÚ µå, µ¥ÀÌÅÍ, ½ºÅà ¼¼±×¸ÕÆ®´Â °¢°¢ µ¶¸³ÀûÀ¸·Î Á¸ÀçÇÏ¸ç °ãÃÄÁöÁö ¾Ê´Â´Ù. ÀÌ ¸ðµ¨Àº ÄÚµå´Â ÀÛÀº ¹Ý¸é µ¥ÀÌÅÍ°¡ ´ë´ÜÈ÷ ¸¹Àº ÇÁ·Î±×·¥¿¡ À¯¿ëÇÏ´Ù (½ÇÁ¦·Î´Â º°·Î ¾È ¾²ÀÓ). [5] ´ëÇü ¸ðµ¨(large model) ÇÔ¼ö Æ÷ÀÎÅÍ¿Í µ¥ÀÌÅÍ Æ÷ÀÎÅÍ·Î ¿ø°Å¸® Æ÷ÀÎÅÍ°¡ ³»Á¤µÈ´Ù. ±×¸®°í ÇÔ ¼ö È£ÃâÀº ¿ø°Å¸® È£Ãâ·Î ³»Á¤µÈ´Ù. µû¶ó¼­ ÄÚµåÀÇ ºÐ·®Àº ¸ðµâº° ºÐÇÒ ÄÄ ÆÄÀÏÀ» ÅëÇØ (À̷лó) ÃÖ´ë 1M¹ÙÀÌÆ®±îÁö °¡´ÉÇÏ°í, µ¥ÀÌÅÍ Æ÷ÀÎÅ͵µ ¿ª½Ã 1M¹ÙÀÌÆ® °ø°£(Èü Æ÷ÇÔ)À» Á÷Á¢ÀûÀ¸·Î ÂüÁ¶ÇÒ ¼ö ÀÖ´Ù. ÇÏÁö¸¸ Á¤Àû µ¥ÀÌ ÅÍ´Â ÃÖ´ë 64k¹ÙÀÌÆ®¸¦ ÃÊ°úÇÒ ¼ö ¾ø´Ù. ÇÑÆí ÄÚµå, µ¥ÀÌÅÍ, ½ºÅà ¼¼±×¸Õ Æ®´Â °¢°¢ µ¶¸³ÀûÀ¸·Î Á¸ÀçÇϸç°ãÃÄÁöÁö ¾Ê´Â´Ù. ÀÌ ¸ðµ¨Àº ´ë´ÜÈ÷ Å« ÇÁ ·Î±×·¥¿¡ ¾²À̸ç, ½ÇÁ¦·Î ½ÇÇà È­ÀÏÀÇ Å©±â°¡ ´ë·« 64k¹ÙÀÌÆ® ÀÌ»óÀÎ ´ëºÎ ºÐÀÇ C ÀÀ¿ë ÇÁ·Î±×·¥Àº ÀÌ ¸ðµ¨À̶ó°í º¸¸é °ÅÀÇ Æ²¸²¾ø´Ù. [6] °Å´ë ¸ðµ¨(huge model) 64k¹ÙÀÌÆ® ÀÌ»óÀÇ Á¤Àû µ¥ÀÌÅ͸¦ °¡Áú ¼ö ÀÖ´Ù´Â °ÍÀ» Á¦¿ÜÇÏ°í´Â ´ë Çü ¸ðµ¨°ú ¶È°°´Ù. 64k¹ÙÀÌÆ® ÀÌ»óÀÇ Á¤Àû µ¥ÀÌÅ͸¦ °¡Áú ¼ö ÀÖµµ·Ï Çϱâ À§ÇØ ÇÔ¼ö È£ÃâÀº °Å´ë È£Ãâ(huge call)·Î ³»Á¤µÈ´Ù. ÇÏÁö¸¸ ÇÔ¼ö Æ÷ÀÎÅÍ ¿Í µ¥ÀÌÅÍ Æ÷ÀÎÅÍ´Â ½ÇÇà ¼Óµµ¸¦ °í·ÁÇÏ¿© ´ëÇü ¸ðµ¨Ã³·³ ¿ø°Å¸® Æ÷ÀÎÅÍ·Î ³»Á¤µÈ´Ù´Â µ¥ ÁÖÀÇÇØ¾ß ÇÑ´Ù. ÀÌ ¸ðµ¨Àº, ¿¹ÄÁµ¥ ´ë¿ë·®ÀÇ ÀÚÇü(font) µ¥ ÀÌÅ͸¦ ½ÇÇà È­ÀÏ ÀÚü ³»¿¡ Æ÷ÇÔ½ÃÅ°°íÀÚ ÇÒ °æ¿ì µî¿¡³ª ¾²ÀÌ°í º¸ÅëÀÇ °æ¿ì¿¡´Â °ÅÀÇ ¾²ÀÌÁö ¾Ê´Â´Ù. --------------------------------------------------------------------- 3 °¢ ¸ðµ¨µéÀÇ ¸Þ¸ð¸® Áöµµ --------------------------------------------------------------------- ´ÙÀ½ÀÇ <±×¸² 1>~<±×¸² 6>Àº °¢ ¸ðµ¨µéÀÇ ¸Þ¸ð¸® Áöµµ(memory map)ÀÌ ´Ù. ¿©±â¼­ ÁÖÀÇÇؼ­ »ìÆ캼 °ÍÀº ¾Æ·¡¿Í °°´Ù. * CS, DS, SSÀÇ »óµî ¿©ºÎ ¹× °íÁ¤ÀûÀΰ¡ÀÇ ¿©ºÎ * °¢ ¼¼±×¸ÕÆ®ÀÇ ³õÀÎ ¼ø¼­ (Ç×»ó CS <= DS <= SSÀÇ ¼ø¼­ÀÓ) * °¢ ¼¼±×¸ÕÆ® Å©±âÀÇ ÃÖ´ë ÇÑ°è * Á¤Àû µ¥ÀÌÅÍ ¿µ¿ªÀÇ ±¸Á¶ (Ç×»ó ÃʱâÈ­µÈ µ¥ÀÌÅÍ -> ºñÃʱâÈ­µÈ µ¥ÀÌÅÍÀÇ ¼ø¼­) * ½ºÅà ¿µ¿ªÀÇ ±¸Á¶ * ±Ù°Å¸®/¿ø°Å¸® ÈüÀÇ À§Ä¡ * ½ºÅà ¹× ÈüÀÇ ¼ºÀå ¹æÇâ, Áï À§(ÇÏÀ§ ¹øÁö)ÂÊÀÌ³Ä ¾Æ·¡(»óÀ§ ¹øÁö)ÂÊÀ̳Ä. ÇÑÆí, ±×¸²¿¡¼­ À§ÂÊÀº ÇÏÀ§ ¹øÁöÀÌ°í ¾Æ·¡ÂÊÀº »óÀ§ ¹øÁöÀÌ´Ù. ¶ÇÇÑ °ãÀ¸·Î µÈ ¼öÆò¼±Àº µ¶¸³µÈ ¼¼±×¸ÕÆ®ÀÇ °æ°è¸¦ ³ªÅ¸³¿¿¡ ƯÈ÷ ÁÖ¸ñÇÏ¿© º¸ ±â ¹Ù¶õ´Ù. ±× ¿ÜÀÇ ¼öÆò¼±Àº ÇØ´ç¼¼±×¸ÕÆ® ³» °¢ ¿µ¿ªÀÇ °æ°è¸¦ ³ªÅ¸³¾ »ÓÀÌ´Ù. ÀÌ´Â °¢ ¸Þ¸ð¸® ¸ðµ¨ÀÇ ±¸Á¶¸¦ ÀÌÇØÇÏ´Â µ¥ »ó´çÈ÷ Áß¿äÇÑ »çÇ×ÀÌ ¹Ç·Î °¡´ÉÇÑ ÇÑ »ý°¢ÇÏ´Â ÀÚ¼¼·Î ±×¸²À» º¸¾Æ ÁáÀ¸¸é ½Í´Ù. Âü°í·Î Á¤Àû µ¥ÀÌÅÍ(static data)¶õ ¸ðµç Á¾·ùÀÇ ¿ÜºÎº¯¼ö, Á¤Àûº¯¼ö ¹× ¹®ÀÚ¿­ »ó¼ö µîÀ» ÃÑĪÇÏ´Â ¸»ÀÌ´Ù. ÀÌ ¶§ ¿ø½Ã ÄÚµå»ó¿¡¼­ ±× ÃʱâÄ¡ ¸¦ ¸í½ÃÇÑ Á¤Àû µ¥ÀÌÅʹ Ưº°È÷ "ÃʱâÈ­µÈ µ¥ÀÌÅÍ(initialized data)"¶ó ºÎ¸£°í ¸í½ÃÀûÀ¸·Î ÃʱâÈ­µÇÁö ¾ÊÀº µ¥ÀÌÅÍ´Â "ºñÃʱâÈ­µÈ µ¥ÀÌÅÍ(uniniti alized data)"¶ó°í ºÎ¸¥´Ù. µÑ »çÀÌÀÇ Â÷ÀÌÁ¡Àº ÀÌ·¸´Ù. Áï ÃʱâÈ­µÈ µ¥ÀÌÅÍÀÇ °ªÀº ½ÇÇà È­ÀÏ ³» ¿¡ Æ÷ÇԵǴ ¹Ý¸é¿¡, ºñÃʱâÈ­µÈ µ¥ÀÌÅÍÀÇ °ªÀº ½ÇÇà È­ÀÏ ³»¿¡ Æ÷ÇÔµÇÁö ¾ÊÀ¸¸ç ÇÁ·Î±×·¥ÀÌ ½ÇÇàµÊ°ú µ¿½Ã¿¡ ±âµ¿ ÄÚµå(startup code)¿¡ ÀÇÇØ 0À¸ ·Î ÃʱâÈ­µÈ´Ù(´Ü, °Å´ë ¸ðµ¨¿¡¼­´Â ºñÃʱâÈ­µÈ µ¥ÀÌÅÍ ¿µ¿ªÀÌ º°µµ·Î Á¸ ÀçÇÏÁö ¾ÊÀ¸¸ç ¸ðµÎ ÃʱâÈ­µÈ µ¥ÀÌÅÍ·Î °£ÁÖÇÑ´Ù). <±×¸² 1> ÃʼÒÇü ¸ðµ¨(tiny model)ÀÇ ¸Þ¸ð¸® Áöµµ --------------------------------------------------------------------- CS, DS, SS ---> +-------------------+-+ (ES == DS)(1)| | | | ÄÚµå | | | | | +-------------------+ |-+ | ÃʱâÈ­µÈ µ¥ÀÌÅÍ | | | |-------------------| | |(2) | ºñÃʱâÈ­µÈ µ¥ÀÌÅÍ | | | +-------------------+ |-+ | ±Ù°Å¸® Èü(4) | | |-------------------| | Á¤È®È÷ 64k¹ÙÀÌÆ®(3) | | | | ¿©À¯ °ø°£ | | | | | |-------------------| | <--- SP(°¡º¯) | ½ºÅà | | +-------------------+-+ <--- SP ÃʱâÄ¡ (1) ¿ø°Å¸® Æ÷ÀÎÅ͸¦ ÀüÇô ¾²Áö ¾ÊÀ» °æ¿ì¿¡¸¸. (2) µÎ ¿µ¿ªÀ» ÇÕÇØ "Á¤Àû µ¥ÀÌÅÍ ¿µ¿ª"À̶ó ºÎ¸¥´Ù. (3) ¸Þ¸ð¸®°¡ ¸ðÀÚ¶ó¸é ±×¿¡ ¸Â°Ô ÀÚµ¿ÀûÀ¸·Î Ãà¼ÒµÇ¸ç ¿ÜºÎº¯¼ö _stklen, _heaplenÀÇ ÃʱâÄ¡¸¦ º¯°æÇÏ¿© ÀǵµÀûÀ¸·Î 64k¹ÙÀÌÆ® ÀÌÇÏ·Î Ãà¼Ò½Ãų ¼ö ÀÖ´Ù. (·¥»óÁÖ ÇÁ·Î±×·¥ µî¿¡¼­) (4) malloc, calloc/free ÇÔ¼ö¸¦ ½á¼­ ÇÒ´ç/ÇØÁ¦ÇÑ´Ù. * ÃʼÒÇü ¸Þ¸ð¸®¿¡¼­µµ ¿ø°Å¸® ÈüÀÌ ÀÖÀ» ¼ö ÀÖÁö¸¸ ½ÇÁ¦ »çÁ¤»ó °ÅÀÇ ¾²ÀÌÁö ¾ÊÀ¸¹Ç·Î ±×¸²¿¡ ³ªÅ¸³»Áö ¾Ê¾Ò´Ù. --------------------------------------------------------------------- <±×¸² 2> ¼ÒÇü ¸ðµ¨(small model)ÀÇ ¸Þ¸ð¸® Áöµµ --------------------------------------------------------------------- CS ---> +-------------------+-+ | | | | ÄÚµå | | ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö | | | +-------------------+-+-+ (ES == DS) | ÃʱâÈ­µÈ µ¥ÀÌÅÍ | | | (1) |-------------------| | |(2) | ºñÃʱâÈ­µÈ µ¥ÀÌÅÍ | | | +-------------------+ |-+ | ±Ù°Å¸® Èü(4) | | | near heap | | |-------------------| | Á¤È®È÷ 64k¹ÙÀÌÆ®(3) | | | | ¿©À¯ °ø°£ | | | | | |-------------------| | <--- SP(°¡º¯) | ½ºÅà | | +-------------------+-+ <--- SP ÃʱâÄ¡ | ¿ø°Å¸® Èü(5) | | | far heap | | |-------------------| | | | | | ¿©À¯ °ø°£ | | | free space | | ³²´Â ¸Þ¸ð¸® ³¡±îÁö +-------------------+-+ (1)(2)(3)(4) ÃʼÒÇü ¸ðµ¨ Âü°í (5) farmalloc/farfree ÇÔ¼ö ¶Ç´Â allocmem/freemem ÇÔ¼ö¸¦ ½á¼­ ÇÒ´ç/ÇØÁ¦ÇÑ´Ù. --------------------------------------------------------------------- <±×¸² 3> ÁßÇü ¸ðµ¨(medium model)ÀÇ ¸Þ¸ð¸® Áöµµ --------------------------------------------------------------------- +- ÇÔ¼ö È£Ãâ(¿ø°Å¸® È£Ãâ)½Ã¿¡¸¸ | ±× ÇÔ¼ö°¡ Á¸ÀçÇÏ´Â ¸ðµâÀÇ | ¼¼±×¸ÕÆ® ¼±µÎ¸¦ °¡¸®Å°µµ·Ï º¯°æµÇ¸ç | ±× ¿Ü¿¡´Â °íÁ¤ÀûÀÌ´Ù. | CS -+-> +-------------------+-+ | | ¸ðµâ1 | | +-> +-------------------+-+ | | ¸ðµâ2 | | +-> +-------------------+-+ °¢ ¸ðµâ ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö | | ......| | +-> +-------------------+-+ | ¸ðµân | | DS, SS ---> +-------------------+-+-+ (ES == DS) | ÃʱâÈ­µÈ µ¥ÀÌÅÍ | | | (1) |-------------------| | |(2) | ºñÃʱâÈ­µÈ µ¥ÀÌÅÍ | | | +-------------------+ |-+ | ±Ù°Å¸® Èü(4) | | |-------------------| | Á¤È®È÷ 64k¹ÙÀÌÆ®(3) | | | | ¿©À¯ °ø°£ | | | | | |-------------------| | <--- SP(°¡º¯) | ½ºÅà | | +-------------------+-+ <--- SP ÃʱâÄ¡ | ¿ø°Å¸® Èü(5) | | |-------------------| | | | | | ¿©À¯ °ø°£ | | ³²´Â ¸Þ¸ð¸® ³¡±îÁö +-------------------+-+ (1)(2)(3)(4)(5) ÃʼÒÇü ¸ðµ¨ Âü°í * Áöµµ¿¡¼­ º¹¼±Àº µ¶¸³µÈ ¼¼±×¸ÕÆ®ÀÇ °æ°è¸¦ ³ªÅ¸³»¸ç ´Ü¼±, ¶Ç´Â Á¡¼±Àº µ¿ÀÏÇÑ ¼¼±×¸ÕÆ® ³»¿¡¼­ °¢ ¿µ¿ªÀÇ °æ°è¸¦ ³ªÅ¸³½´Ù. (´Ù¸¥ ±×¸²¿¡¼­µµ ¸¶Âù°¡Áö) --------------------------------------------------------------------- <±×¸² 4> Áß¼ÒÇü ¸ðµ¨(compact model)ÀÇ ¸Þ¸ð¸® Áöµµ --------------------------------------------------------------------- CS ---> +-------------------+-+ | | | | ÄÚµå | | ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö | | | DS ---> +-------------------+-+ (ES == ??) | ÃʱâÈ­µÈ µ¥ÀÌÅÍ | | (1) |-------------------| | ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö(2) | ºñÃʱâÈ­µÈ µ¥ÀÌÅÍ | | SS ---> +-------------------+-+ | ¿©À¯ °ø°£ | | 4k¹ÙÀÌÆ®(3) |-------------------| | <--- SP(°¡º¯) | ½ºÅà | | +-------------------+-+ <--- SP ÃʱâÄ¡ | (¿ø°Å¸®) Èü(4) | | |-------------------| | | | | | ¿©À¯ °ø°£ | | ³²´Â ¸Þ¸ð¸® ³¡±îÁö +-------------------+-+ (1) ES´Â ¿ø°Å¸® Æ÷ÀÎÅ͸¦ À§ÇØ ¾²ÀÌ¸ç ±×¶§±×¶§ °ªÀÌ º¯ÇÑ´Ù. (2) µÎ ¿µ¿ªÀ» ÇÕÇØ "Á¤Àû µ¥ÀÌÅÍ ¿µ¿ª"À̶ó ºÎ¸¥´Ù. (3) ¿ÜºÎº¯¼ö _stklenÀ» ÀçÁ¤ÀÇÇÏ¿© º¯°æÇÒ ¼ö ÀÖ´Ù. (4) ±Ù°Å¸® ÈüÀÌ µû·Î Á¸ÀçÇÏÁö ¾ÊÀ¸¹Ç·Î ±×³É ÈüÀ̶ó°í ºÎ¸¥´Ù. malloc,calloc/free ÇÔ¼ö¿¡ ÀÇÇØ ÇØÁ¦/¼³Á¤ÇÑ´Ù. --------------------------------------------------------------------- <±×¸² 5> ´ëÇü ¸ðµ¨(large model)ÀÇ ¸Þ¸ð¸® Áöµµ --------------------------------------------------------------------- +- ÇÔ¼ö È£Ãâ(¿ø°Å¸® È£Ãâ)½Ã¿¡¸¸ | ±× ÇÔ¼ö°¡ Á¸ÀçÇÏ´Â ¸ðµâÀÇ | ¼¼±×¸ÕÆ® ¼±µÎ¸¦ °¡¸®Å°µµ·Ï º¯°æµÇ¸ç | ±× ¿Ü¿¡´Â °íÁ¤ÀûÀÌ´Ù. | CS -+-> +-------------------+-+ | | ¸ðµâ1 | | +-> +-------------------+-+ | | ¸ðµâ2 | | +-> +-------------------+-+ °¢ ¸ðµâ ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö | | ...... | | +-> +-------------------+-+ | ¸ðµân | | DS ---> +-------------------+-+ (ES == ??) | ÃʱâÈ­µÈ µ¥ÀÌÅÍ | | (1) |-------------------| | ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö(2) | ºñÃʱâÈ­µÈ µ¥ÀÌÅÍ | | SS ---> +-------------------+-+ | | | 4k¹ÙÀÌÆ®(3) |-------------------| | <--- SP(°¡º¯) | ½ºÅà | | +-------------------+-+ <--- SP ÃʱâÄ¡ | (¿ø°Å¸®) Èü(4) | | | heap | | |-------------------| | | | | | ¿©À¯ °ø°£ || | free space | | ³²´Â ¸Þ¸ð¸® ³¡±îÁö +-------------------+-+ (1)(2)(3)(4) Áß¼ÒÇü ¸ðµ¨ Âü°í --------------------------------------------------------------------- <±×¸² 6> °Å´ë ¸ðµ¨(huge model)ÀÇ ¸Þ¸ð¸® Áöµµ --------------------------------------------------------------------- +- ´ëÇü ¸ðµ¨ ÂüÁ¶ | CS -+-> +-------------------+-+ | | ¸ðµâ1 | | +-> +-------------------+ | | | ¸ðµâ2 | | +-> +-------------------+ | °¢ ¸ðµâÀÇ ÄÚµå | | ...... | | ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö +-> +-------------------+ | | ¸ðµân | | DS -+-> +-------------------+-+ | | ¸ðµâ1ÀÇ µ¥ÀÌÅÍ | | (ES == ??) +-> +-------------------+ | (1) | | ¸ðµâ2ÀÇ µ¥ÀÌÅÍ | | +-> +-------------------+ | °¢ ¸ðµâÀÇ µ¥ÀÌÅÍ | | ...... | | ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö +-> +-------------------+ | (2) | ¸ðµânÀÇ µ¥ÀÌÅÍ | | SS ---> +-------------------+-+ | | | 4k¹ÙÀÌÆ®(3) |-------------------| | <--- SP(°¡º¯) | ½ºÅà | | +-------------------+-+ <--- SP ÃʱâÄ¡ | (¿ø°Å¸®) Èü(4) | | |-------------------| | | | | | ¿©À¯ °ø°£ | | ³²´Â ¸Þ¸ð¸® ³¡±îÁö +-------------------+-+ (1)(3)(4) Áß¼ÒÇü ¸ðµ¨ Âü°í (2) ÃʱâÈ­µÈ µ¥ÀÌÅ͸¸À» ÀǹÌÇÑ´Ù. ºñÃʱâÈ­µÈ µ¥ÀÌÅÍ ¿µ¿ªÀº º°µµ·Î Á¸ÀçÇÏÁö ¾Ê´Â´Ù. --------------------------------------------------------------------- --------------------------------------------------------------------- 4 ¸Þ¸ð¸® ¸ðµ¨ÀÇ ºÐ·ù --------------------------------------------------------------------- <Ç¥ 1> ¸Þ¸ð¸® ¸ðµ¨ÀÇ ºÐ·ù -------------+--------------------------------------------------- | ÄÚµå Å©±â(code size) µ¥ÀÌÅÍ Å©±â +---------------------+----------------------------- (data size) | 64k ÀÌÇÏ | 1M ÀÌÇÏ -------------+---------------------+----------------------------- | ÃʼÒÇü | 64k ÀÌÇÏ | (ÄÚµå, µ¥ÀÌÅÍ Áßø) | | ¼ÒÇü | ÁßÇü | (ÄÚµå, µ¥ÀÌÅͺи®) | -------------+---------------------+----------------------------- | Áß¼ÒÇü | ´ëÇü 1M ÀÌÇÏ | | (Á¤Àû µ¥ÀÌÅÍ 64k ÀÌÇÏ) | | °Å´ë | | (Á¤Àû µ¥ÀÌÅÍ 64k ÃÊ°ú °¡´É) -------------+---------------------+----------------------------- <Ç¥ 1>¿¡ °¢Á¾ ¸Þ¸ð¸® ¸ðµ¨À» ±× ´ëÇ¥ÀûÀΠƯ¡¿¡ µû¶ó ºÐ·ùÇØ ³õ¾Ò ´Ù. ÀÌ¿Í °°ÀÌ Äڵ峪 µ¥ÀÌÅÍ Å©±âÀÇ ÇÑ°è¿¡ µû¶ó¼­ ¸Þ¸ð¸® ¸ðµ¨À» ºÐ·ùÇÏ ´Â °ÍÀÌ °¡Àå ÀϹÝÀûÀÌ´Ù. ±×·±µ¥ »ì´Ù º¸¸é Äڵ峪 µ¥ÀÌÅÍ Å©±â¿¡ µû¶ó À̵éÀ» ÃÑĪÇÏ´Â ¿ë¾î°¡ ÀÚÁÖ ÇÊ¿äÇØÁö´Âµ¥, ÀÌ¿¡ µû¶ó ±×·¯ÇÑ ¿ë¾îµéÀ» ¾Æ·¡¿Í °°ÀÌ Á¤ÀÇÇؼ­ ¾²°í ÀÖ´Ù. * µ¥ÀÌÅÍ Å©±â¿¡ µû¸¥ ºÐ·ù - ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨: ÃʼÒÇü, ¼ÒÇü, ÁßÇü - ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨: Áß¼ÒÇü, ´ëÇü, °Å´ë * ÄÚµå Å©±â¿¡ µû¸¥ ºÐ·ù - ¼ÒÇü ÄÚµå ¸ðµ¨: ÃʼÒÇü, ¼ÒÇü, Áß¼ÒÇü - ´ëÇü ÄÚµå ¸ðµ¨: ÁßÇü, ´ëÇü, °Å´ë --------------------------------------------------------------------- 5 °¢ ¸Þ¸ð¸® ¸ðµ¨ÀÇ Æ¯Â¡ --------------------------------------------------------------------- ¾Õ ÀýÀÇ ¿ë¾î¸¦ ½á¼­ °¢Á¾ ¸Þ¸ð¸® ¸ðµ¨ÀÇ Æ¯Â¡À» »ç¾Èº°·Î ºñ±³/¼³¸í ÇÏ¸é ´ÙÀ½°ú °°´Ù. <±×¸² 1>~<±×¸² 6>À» Âü°íÇϸ鼭 ¼¼½ÉÇÏ°Ô µûÁ® º¸±â ¹Ù¶õ´Ù. --------------------------------------------------------------------- * ³»Á¤µÈ Æ÷ÀÎÅÍ - ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨: ±Ù°Å¸® Æ÷ÀÎÅÍ(near pointer) - ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨: ¿ø°Å¸® Æ÷ÀÎÅÍ(far pointer) (°Å´ë ¸ðµ¨¿¡¼­µµ ¿ø°Å¸® Æ÷ÀÎÅÍ°¡ ³»Á¤µÊ¿¡ ÁÖÀÇ!) * ³»Á¤µÈ Æ÷ÀÎÅÍÀÇ ¹ÙÀÌÆ® Å©±â - ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨: 2¹ÙÀÌÆ® - ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨: 4¹ÙÀÌÆ® * ³»Á¤µÈ ÇÔ¼ö È£Ãâ ¹æ½Ä - ¼ÒÇü ÄÚµå ¸ðµ¨: ±Ù°Å¸® È£Ãâ(near call) - ÁßÇü/´ëÇü ¸ðµ¨: ¿ø°Å¸® È£Ãâ(far call) - °Å´ë ¸ðµ¨: °Å´ë È£Ãâ(huge call) (°Å´ë È£ÃâÀº ÇÔ¼ö È£Ãâ Á÷Àü¿¡ ±× ÇÔ¼ö°¡ Á¸ÀçÇÏ´Â ¸ðµâ¿¡ µþ¸° µ¶¸³ÀûÀÎ µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ ¼±µÎ¸¦ DS°¡ °¡¸®Å°µµ·Ï ±× °ªÀ» º¯°æÇÔÀ» ¶æÇÑ´Ù. <±×¸² 6> Âü°í) --------------------------------------------------------------------- * µ¥ÀÌÅÍ(Èü Æ÷ÇÔ)ÀÇ ÃÑ Å©±â - ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨: ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö(±Ù°Å¸® Èü Æ÷ÇÔ) - ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨: (À̷лó) ÃÖ´ë 1M¹ÙÀÌÆ®±îÁö(Èü Æ÷ÇÔ) * Á¤Àû µ¥ÀÌÅÍ ¿µ¿ª(¿ÜºÎº¯¼ö/Á¤Àûº¯¼ö/¹®ÀÚ¿­ »ó¼ö)ÀÇ Å©±â - ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨: ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö - ÁßÇü/´ëÇü ¸ðµ¨: ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö(¿äÁÖÀÇ!!!) - °Å´ë ¸ðµ¨: (À̷лó) ÃÖ´ë 1M¹ÙÀÌÆ®±îÁö (´Ü, °¢ ¸ðµâÀÇ Á¤Àû µ¥ÀÌÅÍ Å©±â´Â 64k¹ÙÀÌÆ®¸¦ ÃÊ°úÇÒ ¼ö ¾ø´Ù!!) * ÄÚµåÀÇ ÃÑ Å©±â - ¼ÒÇü ÄÚµå ¸ðµ¨: ÃÖ´ë 64k¹ÙÀÌÆ®±îÁö -´ëÇü ÄÚµå ¸ðµ¨: (À̷лó) ÃÖ´ë 1M¹ÙÀÌÆ®±îÁö (´Ü, °¢ ¸ðµâÀÇ ÄÚµå Å©±â´Â 64k¹ÙÀÌÆ®¸¦ ÃÊ°úÇÒ ¼ö ¾ø´Ù!!) --------------------------------------------------------------------- * °¢ ¼¼±×¸ÕÆ®ÀÇ ¹èÄ¡ - ÃʼÒÇü ¸ðµ¨: CS == DS == SS == ES - ¼ÒÇü ¸ðµ¨: CS < DS == SS == ES - ÁßÇü ¸ðµ¨: CS < DS == SS == ES - Áß¼ÒÇü ¸ðµ¨: CS < DS < SS ES == ?? - ´ëÇü ¸ðµ¨: CS < DS < SS ES == ?? - °Å´ë ¸ðµ¨: CS < DS < SS ES == ?? * ÄÚµå/µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ Áßø(overlap) ¿©ºÎ - ÃʼÒÇü ¸ðµ¨¸¸ °ãÄ¡°í(CS == DS) ³ª¸ÓÁö´Â ¸ðµÎ µ¶¸³ÀûÀ¸·Î ºÐ¸®µÊ(CS < DS) * µ¥ÀÌÅÍ/½ºÅà ¼¼±×¸ÕÆ®ÀÇ Áßø ¿©ºÎ - ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨: DS == SS - ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨: DS < SS, Áï µ¶¸³ÀûÀ¸·Î ºÐ¸®µÊ * CS °ªÀÇ °¡º¯ ¿©ºÎ - ¼ÒÇü ÄÚµå ¸ðµ¨: CS == ÄÚµå ¼¼±×¸ÕÆ®ÀÇ ¼±µÎ == °íÁ¤ ºÒº¯ - ´ëÇü ÄÚµå ¸ðµ¨: CS´Â ¼­·Î ´Ù¸¥ ¸ðµâ¿¡ ÀÖ´Â ÇÔ¼ö¸¦ (¿ø°Å¸®) È£ÃâÇÒ ¶§¸¶´Ù ÇØ´ç ¸ðµâÀÇ ¼¼±×¸ÕÆ® ¼±µÎ¸¦ °¡¸®Å°µµ·Ï º¯°æµÈ´Ù. ±× ¿Ü¿¡´Â °íÁ¤Àû. * DS °ªÀÇ °¡º¯ ¿©ºÎ - °Å´ë ¸ðµ¨: ¼­·Î ´Ù¸¥ ¸ðµâ¿¡ ÀÖ´Â ÇÔ¼ö¸¦ (¿ø°Å¸®) È£ÃâÇÒ ¶§¸¶´Ù ÇØ´ç ¸ðµâ¿¡ ¼ÓÇÏ´Â Á¤Àû µ¥ÀÌÅÍ ¿µ¿ªÀÇ ¼¼±×¸ÕÆ® ¼±µÎ¸¦ °¡¸®Å°µµ·Ï º¯°æµÈ´Ù(-> °Å´ë È£Ãâ). ±× ¿Ü¿¡´Â °íÁ¤Àû. - ±× ¿ÜÀÇ ¸ðµ¨: DS == Á¤Àû µ¥ÀÌÅÍ ¿µ¿ªÀÇ ¼¼±×¸ÕÆ® ¼±µÎ == °íÁ¤ ºÒº¯ * ES °ªÀÇ °¡º¯ ¿©ºÎ - ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨: ES == DS == °íÁ¤ ºÒº¯ (´Ü, ¿ø°Å¸® Æ÷ÀÎÅ͸¦ »ç¿ëÇÏÁö ¾Ê¾ÒÀ» °æ¿ì) - ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨: ES == ?? == °¡º¯ (¿ø°Å¸® Æ÷ÀÎÅ͸¦ À§ÇØ ¾²ÀδÙ) --------------------------------------------------------------------- * ±Ù°Å¸® Èü(near heap)ÀÇ Å©±â - ÃʼÒÇü ¸ðµ¨: (µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ Å©±â) - (ÄÚµå Å©±â) - (Á¤Àû µ¥ÀÌÅÍ ¿µ¿ª) - (»ç¿ëµÈ ½ºÅà ũ±â) - ¼ÒÇü/ÁßÇü ¸ðµ¨: (µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ Å©±â) - (Á¤Àû µ¥ÀÌÅÍ ¿µ¿ª) - (»ç¿ëµÈ ½ºÅà ũ±â) (µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ Å©±â´Â ¿ÜºÎº¯¼ö _heaplenÀÌ 0(³»Á¤Ä¡)ÀÏ °æ¿ì Á¤È®È÷ 64k(65536)¹ÙÀÌÆ®ÀÌ°í, ¸¸¾à ¿ÜºÎº¯¼ö _stklen°ú _heaplenÀÇ ÃʱâÄ¡¸¦ ÇÁ·Î±×·¥¿¡¼­ ÁöÁ¤ÇÑ °æ¿ì 64k¹ÙÀÌÆ® ÀÌÇÏ·Î ÁÙÀÏ ¼ö ÀÖ´Ù. ´õºÒ¾î ¸Þ¸ð¸®°¡ ºÎÁ·ÇÒ ¶§¿¡µµ µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ Å©±â°¡ ±×¿¡ ¾Ë¸Â°Ô ÁÙ¾îµç´Ù. Turbo C Reference Guide ¸Å´º¾ó ÂüÁ¶) - ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨: ±Ù°Å¸® ÈüÀÌ Á¸ÀçÇÏÁö ¾Ê´Â´Ù. --------------------------------------------------------------------- * Ưº°È÷ ÄÄÆÄÀÏ·¯ ¿É¼ÇÀ» º¯°æÇÏÁö ¾Ê¾ÒÀ» ¶§ ³»Á¤µÇ´Â ¸Þ¸ð¸® ¸ðµ¨ - ¼ÒÇü ¸ðµ¨ÀÌ ³»Á¤µÈ´Ù. µû¶ó¼­ ÀϹÝÀûÀÎ °æ¿ì ±Ù°Å¸® Æ÷ÀÎÅÍ/±Ù°Å¸® È£ÃâÀÌ ³»Á¤µÇ¸ç ÄÚµå¿Í µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®´Â ºÐ¸®µÈ´Ù. --------------------------------------------------------------------- #49 ÀÓÀ롂 (turbo28 ) [°­ÁÂ] C±íÀº°÷2-2: ¸Þ¸ð¸® ¸ðµ¨°ú ±× ±¸Á¶ 05/06 00:09 288 line --------------------------------------------------------------------- 6 ¹øÁöÁöÁ¤ ¼ö½ÄÀÚ(addressing modifier) --------------------------------------------------------------------- Åͺ¸ C´Â ANSI C »ç¾ç¿¡ ±âÃÊÇÏÁö ¾ÊÀº 7°³ÀÇ ¼ö½ÄÀÚ(modifier)¸¦ Ãß °¡·Î Á¦°øÇÑ´Ù. near, far, huge, _cs, _ds, _es, _ss ¿©±â¼­ µÚÀÇ 4°³´Â ´Ù¸¥ ¾ð¾î(ƯÈ÷ ÆĽºÄ®)°úÀÇ ¸µÅ©¿¡¼­³ª ÇÊ¿äÇÑ °Í À̹ǷΠ¼³¸íÀ» »ý·«ÇÏ°í, ´ë½Å ¾ÕÀÇ 3°³¿¡ °üÇؼ­ ÁßÁ¡ÀûÀ¸·Î ¼³¸íÇÏ°Ú´Ù. Åͺ¸ C¿¡¼­´Â Æ÷ÀÎÅͳª ÇÔ¼ö È£ÃâÀÇ ³»Á¤µÈ ¹æ½ÄÀ» ÇÁ·Î±×·¡¸Ó°¡ ÀÓÀÇ·Î º¯°æÇÒ ¼ö ÀÖ´Ù. ¿¹ÄÁµ¥ ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨¿¡¼­´Â ±Ù°Å¸® Æ÷ÀÎÅÍ°¡ ³»Á¤µÇ Áö¸¸ ÇÁ·Î±×·¡¸Ó´Â ¿ø°Å¸® Æ÷ÀÎÅ͸¦ ¾²±â À§ÇØ Æ÷ÀÎÅÍÀÇ µ¥ÀÌÅÍÇüÀ» º¯°æ ÇÒ ¼ö ÀÖ´Ù. ÀÌó·³ ³»Á¤µÈ Æ÷ÀÎÅÍÇüÀ̳ª ÇÔ¼ö È£Ãâ ¹æ½ÄÀ» º¯°æ½ÃÅ°°íÀÚ ÇÒ ¶§ (ÁÖ·Î) near, far, huge ¼ö½ÄÀÚ°¡ ¾²ÀδÙ. ¿©±â¼­ near, far µîµîÀ» ¼ö½ÄÀÚ¶ó ºÎ¸£´Â ÀÌÀ¯´Â Æ÷ÀÎÅÍÇüÀÓÀ» ³ªÅ¸³»´Â ±¸µÎÁ¡ *¸¦ ¹®¹ýÀûÀ¸·Î ¼ö ½ÄÇÏ´Â ¿ªÇÒÀ» Çϱ⠶§¹®ÀÌ´Ù. --------------------------------------------------------------------- 7 ±Ù°Å¸®/¿ø°Å¸®/°Å´ë Æ÷ÀÎÅÍÀÇ Á¤ÀÇ --------------------------------------------------------------------- ¿¹¸¦ µé¾î¼­, (char *)Çü Æ÷ÀÎÅÍ(¹®ÀÚ¿­ Æ÷ÀÎÅÍ) strÀÌ ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨¿¡¼­ ¾Æ·¡¿Í °°ÀÌ Á¤ÀǵǾî ÀÖ´Ù°í Ä¡ÀÚ. ±×·¯¸é strÀº ±Ù°Å¸® Æ÷ÀÎÅÍ ·Î ³»Á¤µÈ´Ù. char *str; ÀÌ ¶§ strÀ» ¿ø°Å¸® Æ÷ÀÎÅÍ·Î ¹Ù²Ù·Á¸é "*"¸¦ "far *"·Î ġȯÇÏ¸é µÈ ´Ù. Áï ¼ö½ÄÀÚ far¸¦ ±¸µÎÁ¡ * ¾Õ¿¡ ³õÀ¸¸é µÈ´Ù. char far *str; ¸¸¾à ´ëÇü µ¥ÀÌÅÍ ¸ðµ¨¿¡¼­ strÀ» ±Ù°Å¸® Æ÷ÀÎÅÍ·Î Á¤ÀÇÇÏ°í ½Í´Ù¸é, char near *str; À̶ó°í ±â¼úÇÏ¸é µÈ´Ù. °Å´ë Æ÷ÀÎÅ͸¦ ¿øÇÑ´Ù¸é near ´ë½Å¿¡ huge¸¦ ¾²´Â °ÍÀ¸·Î Á·ÇÏ´Ù. ÀϹÝÀûÀ¸·Î ¾î¶² µ¥ÀÌÅÍÇü T°¡ ÀÖ°í TÇü µ¥ÀÌÅ͸¦ °¡¸®Å°´Â Æ÷ÀÎÅÍ pt rÀÌ ¾Æ·¡¿Í °°ÀÌ Á¤ÀǵǾî ÀÖÀ» ¶§(ptrÀº ²À º¯¼ö¸íÀÏ ÇÊ¿ä°¡ ¾ø´Ù), T *ptr; ptrÀÇ ³»Á¤µÈ Æ÷ÀÎÅÍÇüÀ» º¯°æ½ÃÅ°°íÀÚ Çϸé "*ptr"À» "near *ptr", "far *ptr", "huge *ptr"·Î ±×´ë·Î ġȯÇϱ⸸ ÇÏ¸é µÈ´Ù. ÀÌ ¶§ (ptrÀÌ º¯¼ö¸í ÀÌ ¾Æ´Ò ¶§) ÇÊ¿äÇÏ¸é ¾Æ·¡¿Í °°ÀÌ ptr¿¡ °ýÈ£¸¦ µÎ¸§À¸·Î½á *³ª [ ], ( ) µîÀÇ ±¸µÎÁ¡ÀÇ ¿ì¼± ¼øÀ§¿¡ º¯µ¿ÀÌ »ý±â±â ¾Êµµ·Ï ÇØ¾ß ÇÑ´Ù. ±× ¿ÜÀÇ ´Ù ¸¥ ºÎºÐÀº °Çµå¸®¸é ¾È µÈ´Ù. T near *ptr; T far *ptr; T huge *ptr; T near *(ptr); T far *(ptr); T huge *(ptr); ¿¹¸¦ µé¾î ¼ÒÇü ¸ðµ¨¿¡¼­ ÀÌÂ÷¿ø ¹è¿­ Æ÷ÀÎÅÍ py°¡ ¾Æ·¡¿Í °°ÀÌ Á¤ÀÇ µÇ¾î ÀÖÀ» ¶§, int ss[3][10]; int (*py)[10]; py = ss; py¸¦ ¿ø°Å¸® Æ÷ÀÎÅÍ·Î µ¥ÀÌÅÍÇüÀ» º¯°æÇÏ·Á¸é ¾Æ·¡¿Í °°ÀÌ ÇÑ´Ù. int (far *py)[10]; ´ÙÀ½Àº Æ÷ÀÎÅÍÀÇ Æ÷ÀÎÅÍ(Æ÷ÀÎÅ͸¦ °¡¸®Å°´Â Æ÷ÀÎÅÍ)¸¦ Á¤ÀÇÇÑ ¿¹ÀÌ´Ù. char **pps; ppx¸¦ ¿ø°Å¸® Æ÷ÀÎÅ͸¦ °¡¸®Å°´Â ¿ø°Å¸® Æ÷ÀÎÅÍ·Î ¹Ù²Ù¸é ¾Æ·¡¿Í °° ´Ù. char far *(far *pps); ¶Ç´Â °ýÈ£¸¦ Á¦°ÅÇÏ¿© char far *far *pps; ¸¸¾à À§ÀÇ Á¤ÀǸ¦ "char far **ppx"¶ó°í ÇÏ¸é ¼ÒÇü µ¥ÀÌÅÍ ¸ðµ¨¿¡¼­´Â "char far *near *ptr"ÀÌ µÇ¾î °á°úÀûÀ¸·Î "¿ø°Å¸® Æ÷ÀÎÅ͸¦ °¡¸®Å°´Â ±Ù °Å¸® Æ÷ÀÎÅÍ"°¡ µÇ¹Ç·Î ÁÖÀÇÇϱ⠹ٶõ´Ù. ´ÙÀ½Àº °¢Á¾ ¿ø°Å¸®/°Å´ë Æ÷ÀÎÅ͸¦ Á¤ÀÇÇÑ ¿¹ÀÌ´Ù. Æ÷ÀÎÅÍ º¯¼öÀÇ ¿ø ·¡ µ¥ÀÌÅÍÇüÀº "far *"À̳ª "huge *"¸¦ "*"·Î ÀçġȯÇÏ¸é ½±°Ô ÆľÇÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù. int far *px; ¡ç ÀÏÂ÷¿ø ¹è¿­ Æ÷ÀÎÅÍ(¿ø°Å¸®) char huge *px; ¡ç ¹®ÀÚ¿­ ¹è¿­ Æ÷ÀÎÅÍ(°Å´ë) int (far *fp)(double x); ¡ç ÇÔ¼ö Æ÷ÀÎÅÍ(¿ø°Å¸®) double (far *py)[100]; ¡ç ÀÌÂ÷¿ø ¹è¿­ Æ÷ÀÎÅÍ(¿ø°Å¸®) void far *ptr; ¡ç voidÇü ¿ø°Å¸® Æ÷ÀÎÅÍ --------------------------------------------------------------------- 8 ³¡À¸·Î --------------------------------------------------------------------- À̹ø ´ÞÀÇ ±ÛÀº µ¶Àڵ鿡°Ô Áö·çÇÔ ³»Áö ´çȤÇÑ °¨ÀÌ ¾øÁö ¾Ê¾ÒÀ» ÁÙ ·Î ¾È´Ù. ¾ÆÁ÷±îÁöµµ ¾ê±â°¡ ½ÇÁúÀûÀÎ ºÎºÐ¿¡ Á¢¾îµéÁö ¸øÇ߱⠶§¹®¿¡, ¿¹ Á¦µµ ¾øÀÌ ¼³¸íÀ» °­ÇàÇØ ³ª°¥ ¼ö¹Û¿¡ ¾ø¾ú´Ù. °Ô´Ù°¡ ±ÛÀÌ ¿ö³« ±â¼úÀûÀÌ ¶ó¼­ Çѹø¿¡ ¸¹Àº ºÐ·®ÀÇ ±ÛÀ» °ÔÀçÇϱ⵵ ¹¹ÇÑ Å¿µµ ÀÖ¾ú´Ù. ´ÙÀ½ ´Þ¿¡´Â ±Ù°Å¸®/¿ø°Å¸®/°Å´ë È£Ãâ ¹æ½ÄÀÇ Æ¯Â¡ ¹× Â÷ÀÌÁ¡¿¡ ´ëÇØ ¾Ë¾Æº¸°í, ´õºÒ¾î ¼ÒÇü ¸ðµ¨°ú ´ëÇü ¸ðµ¨¿¡ ±¹ÇÑÇÏ¿© ½ºÅà ¿µ¿ªÀ» 64k¹ÙÀÌ Æ® ÀÌÇÏ·Î Ãà¼Ò½ÃÅ°´Â ¹æ¹ý°ú ¼¼±×¸ÕÆ® °¢ ºÎºÐÀÇ À§Ä¡(°¡·É µ¥ÀÌÅÍ ¼¼±× ¸ÕÆ®ÀÇ Å©±â, ÈüÀÇ ¼±µÎ ¹øÁö µîµî)¸¦ ¾Ë¾Æ³»´Â ºñ¹ýÀ» ¼Ò°³ÇÏ°Ú´Ù. ¹°·Ð ´ÙÀ½ ´ÞºÎÅÍ´Â Á¶±ÝÀº ½ÇÁúÀûÀÎ ¼³¸í°ú ¿¹Á¦°¡ À̾îÁú °ÍÀ̹ǷΠÁö·çÇÏÁö ¾Ê°Ô ´«À¸·Î È®ÀÎÇϸ鼭 Åͺ¸ CÀÇ ±íÀº °÷À» ÆÄÇìÃÄ ³ª°¥ ¼ö ÀÖÀ» °ÍÀÌ´Ù. --------------------------------------------------------------------- 9 ´ýÀ¸·Î --------------------------------------------------------------------- ¾Æ¹«·± ¿¹Á¦µµ ¾øÀÌ ±×³É ±ÛÀ» ¸¶Ä¡·Á´Ï±î ¾Æ¹«·¡µµ ¶³¶°¸§Çؼ­ ´ýÀ¸ ·Î ÃÖ°í±Þ ³­À̵µÀÇ ¿¹Á¦¸¦ Çϳª ¼Ò°³ÇÑ´Ù. ´ÙÀ½ÀÇ ¿¹Á¦ memmodel.c´Â ¼Ò Çü ¸ðµ¨¿¡¼­ÀÇ ½ÇÁ¦ÀûÀÎ ¸Þ¸ð¸® Áöµµ¸¦ º¸¿© ÁØ´Ù. Åͺ¸ CÀÇ ±íÀº °÷À» ´« À¸·Î Á÷Á¢ È®ÀÎÇÒ ¼ö ÀÖ´Â ÁÁÀº ±âȸ°¡ ¾Æ´Ò±î »ý°¢ÇÑ´Ù. ¸Þ¸ð¸® Áöµµ¸¦ ¾ò±â À§Çؼ­´Â ¸Þ¸ð¸® °¢ ¿µ¿ªÀÇ ½ÃÀÛ°ú ³¡ ¹øÁö(¶Ç´Â ¼¼±×¸ÕÆ® °æ°è)¸¦ ¾Ë¾Æ¾ß Çϴµ¥ ÀÌ ¿¹Á¦¿¡¼­´Â ½ÃÀÛ°ú ³¡ ¹øÁö¸¦ ±¸Çϱâ À§ÇÏ¿© ÇÑ °¡Áö ÀÌ»óÀÇ ¹æ¹ýÀ» »ç¿ëÇÏ°í ÀÖ´Ù. ½ÇÇà °á°ú¸¦ º¸¸é ¿©·¯ °¡ Áö ¹æ¹ý¿¡ ÀÇÇØ ±¸ÇÑ ¹øÁö°ªµéÀÌ ¼­·Î ¿ÏÀüÇÏ°Ô Àß ÀÏÄ¡ÇÏ°í ÀÖÀ½À» º¼ ¼ö ÀÖÀ» °ÍÀÌ´Ù. ÀÌ ¿¹Á¦´Â ¹Ýµå½Ã Åͺ¸ C 2.0¿¡¼­ ¼ÒÇü ¸ðµ¨(³»Á¤Ä¡ ±×´ë·Î)·Î ÄÄÆÄÀÏ /¸µÅ©ÇØ¾ß ÇÑ´Ù. ´ÙÀ½ÀÇ ½ÇÇà °á°ú´Â Åͺ¸ C 2.0 ÅëÇÕ °³¹ß ȯ°æÇÏ¿¡¼­ ÄÄ ÆÄÀÏ·¯ ¿É¼ÇÀ» ÀüÇô º¯°æÇÏÁö ¾ÊÀº ä(µð¹ö±ë ¸ðµå »óÅÂ)·Î ±× °á°ú¸¦ Ãâ ·ÂÇÑ °ÍÀÌ´Ù. Âü°í·Î ÀÌ ¿¹Á¦´Â µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ Å©±â¸¦ ³»Á¤Ä¡ÀÎ 64k¹ÙÀÌÆ®º¸´Ù Ãà¼Ò½ÃÅ°±â À§ÇÏ¿©, ½ºÅÃÀÇ Å©±â¸¦ ¼³Á¤ÇÏ´Â ¿ÜºÎº¯¼ö _stklenÀÇ ÃʱâÄ¡¸¦ 0x0250À¸·Î, ±Ù°Å¸® ÈüÀÇ Å©±â¸¦ ¼³Á¤ÇÏ´Â ¿ÜºÎº¯¼ö _heaplenÀÇ ÃʱâÄ¡¸¦ 0x0001·Î Àâ¾Æ, ±âµ¿ ÄÚµå(startup code)·Î ÇÏ¿©±Ý µ¥ÀÌÅÍ ¼¼±×¸ÕÆ®ÀÇ Å© ±â¸¦ ´ëÆø Ãà¼Ò½ÃÅ°µµ·Ï Çß´Ù. ÀÚ¼¼ÇÑ »çÇ×Àº Turbo C 2.0 Reference Guid e ¸Å´º¾ó 28ÂÊ, 30ÂÊÀ» Âü°íÇϱ⠹ٶõ´Ù. Áö¸é »çÁ¤»ó, ½Ã°£ °ü°è»ó ÀÌ ¿¹Á¦ÀÇ ºÐ¼®Àº ´ÙÀ½ ´Þ·Î ¹Ì·ê ¼ö¹Û¿¡ ¾øÀ» °Í °°´Ù. ±×·¯³ª ¼­Åõ¸¥ ¿µ¾îÁö¸¸ ÁÖ¼®À» ÃæºÐÈ÷ ´Þ¾Æ µÎ¾úÀ¸¹Ç·Î ÀÇ ¿å¸¸ ÀÖ´Ù¸é ¿¹Á¦¸¦ ºÐ¼®ÇÏ´Â °Ô ¾î·ÆÁö¸¸µµ ¾ÊÀ» °ÍÀÌ´Ù. ´Ù¸¸ go_up_sta ck ÇÔ¼ö´Â ½ºÅÃÀ» ²¨²Ù·Î °Å½½·¯ ¿Ã¶ó°¡¼­ SPÀÇ ÃʱâÄ¡(½ºÅÃÀÇ ÃÖ»óÀ§ ¹ø Áö°ª)¸¦ ±¸ÇØ ÁÖ´Â ÇÔ¼ö·Î¼­, ÀÌ ÇÔ¼ö´Â Åͺ¸ C ÆÐÅ°Áö¿¡ µþ·Á ÀÖ´Â ±âµ¿ ÄÚµå c0.asmÀÇ ¾î¼Àºí¸® ¿ø½Ã È­ÀÏÀ» ºÐ¼®ÇÏÁö ¾Ê°í´Â ÀüÇô ÀÌÇØÇÒ ¼ö°¡ ¾ø±â ¶§¹®¿¡, Áö±ÝÀº ±×³É ±×·Á·Á´Ï Çϱ⠹ٶõ´Ù. ±× ¿ÜÀÇ ³ª¸ÓÁö ºÎºÐÀº µ¶ÀÚ ½º½º·Î ºÐ¼®ÇØ ³¾ ¼ö ÀÖÀ¸¸®¶ó ¹Ï´Â´Ù. ¹ßµîÀÌ ÂïÈúÁö´Â ¸ð¸£°ÚÁö ¸¸... <¿¹Á¦ MEMMODEL.C> ¼ÒÇü ¸ðµ¨¿¡¼­ÀÇ ½ÇÁ¦ÀûÀÎ ¸Þ¸ð¸® Áöµµ --------------------------------------------------------------------- /* File MEMMODEL.C */ #include #include #include #pragma warn -par /* off warning */ unsigned _heaplen = 0x0001; /* minimum value */ /* if _heaplen == 0 or _heaplen is too large, this program will output wrong results */ unsigned _stklen = 0x0250; /* minimum value is 0x0200 when the software emulation for the floating point operation */ extern unsigned _psp; /* program segment prefix */ /* declared in dos.h */ extern void *__heapbase; /* a pointer to the near heap base */ extern void *__heaptop; extern void far *_heapbase; /* a pointer to the far heap base */ extern void far *_heaptop; void *go_up_stack(unsigned BP, int argc, char *argv[]) { int i; BP += 2; /* for "push bp" in the main function */ BP += 2; /* for return address when quit the main function (small code model) */ BP += 6; /* for argc, argv, envp(6 byte) */ BP += argc * 2; /* for argv[0], ..., argv[argc - 1] */ BP += 2; /* for argv[argc](== NULL) */ for (i = 0; i < argc; i++) /* for strings pointed by argv[i]s */ BP += strlen(argv[i]) + 1; if ((BP & 0x0001) != 0) BP++; /* for word alignment(dummy 0x00 byte)*/ BP += 2; /* for dummy return address(== 0x00fb) */ return (void *)BP; /* BP is the initial value of SP */ /* sometimes BP == StartingSP - 2 because of the additional dummy return address(2 byte) */ } void main(int argc, char *argv[], char *env[]) { unsigned CSsize; /*code segment size in paragraph(small model) */ unsigned DSsize; /* data segment size in paragraph */ unsigned StartingSP; /* initial value of SP */ unsigned farheap; /* segment of the far heap base pointer */ unsigned keepsize; /* calculated keep size in paragraph, i.e. total program size */ void *ptr; void far *topofmem; /* far pointer to the top of the memory */ CSsize = _DS - _CS; /* when small model */ ptr = (char *)__heapbase + _stklen + _heaplen; DSsize = ((unsigned)ptr >> 4) + 1; StartingSP = DSsize << 4; farheap = FP_SEG(_heapbase); /* get segment of the _heapbase */ keepsize = farheap - _psp; /* print the structure of the small memory model */ printf("Porgram segment prefix == %#06x\n", _psp); printf("Code segment == %#06x\n", _CS); printf("Data segment == %#06x\n", _DS); printf("Stack segment == %#06x\n", _SS); printf("Extra segment == %#06x\n", _ES); printf("Offset of static data area to DS == 0x0000\n"); printf("Offset of near heap base to DS == %#06x\n", __heapbase); printf("Offset of near heap top to DS == %#06x\n", __heaptop); printf("Current stack pointer == %#06x\n", _SP); /* print the initial value of SP calculated by three different methods */ printf("Initial value of SP == %#06x\n", StartingSP); printf(" == %#06x(other method)\n", (farheap - _DS) << 4); printf(" == %#06x(other method)\n", go_up_stack(_BP, argc, argv)); /* print the map of the far heap */ topofmem = MK_FP(*(unsigned far *)MK_FP(_psp, 0x0002), 0x0000); printf("Far heap base == %Fp\n", _heapbase); printf("Far heap top == %Fp\n", _heaptop); printf("Top of memory == %Fp\n\n", topofmem); /* print sizes */ printf("CS size == %#06x paragraph\n", CSsize); printf("DS size == %#06x paragraph(including stack)\n", DSsize); printf("Keep size == %#06x paragraph\n", keepsize); printf(" == %#06x(other method)\n", 0x10 + CSsize + DSsize); printf("Free space in near heap == %#06x byte(including stack area)\n", _SP - (unsigned)__heaptop + 1); printf("Free space in far heap == %ld byte\n", (unsigned long)(FP_SEG(_heaptop) - FP_SEG(_heapbase)) << 4); printf(" == %ld byte(other method)\n", (unsigned long)(FP_SEG(topofmem) - FP_SEG(_heapbase)) << 4); /* for a TSR program "keep(0, keepsize);" is required before quit program */ } --------------------------------------------------------------------- ½ÇÇà °á°ú (Åͺ¸ C 2.0 ÅëÇÕ °³¹ß ȯ°æÇÏ¿¡¼­ ¼ÒÇü ¸ðµ¨·Î ÄÄÆÄÀÏ/¸µÅ©/½ÇÇà. PSPÀÇ ¼¼±×¸ÕÆ®°ª µîÀ̳ª ¿ø°Å¸® ÈüÀÇ Å©±â µîÀº ½Ã½ºÅÛ »óȲ¿¡ µû¶ó °¡º¯ÀûÀÌ´Ù. ±×·¯³ª »ó´ëÀûÀÎ °ªÀº ½Ã½ºÅÛ¿¡ »ó°ü¾øÀÌ ÀÏÁ¤Çϸ®¶ó º»´Ù.) Porgram segment prefix == 0x847e Code segment == 0x848e Data segment == 0x85e6 Stack segment == 0x85e6 Extra segment == 0x85e6 Offset of static data area to DS == 0x0000 Offset of near heap base to DS == 0x079a Offset of near heap top to DS == 0x079a Current stack pointer == 0x09ba Initial value of SP == 0x09f0 == 0x09f0(other method) == 0x09f0(other method) Far heap base == 8685:0000 Far heap top == A000:0000 Top of memory == A000:0000 CS size == 0x0158 paragraph DS size == 0x009f paragraph(including stack) Keep size == 0x0207 paragraph == 0x0207(other method) Free space in near heap == 0x0221 byte(including stack area) Free space in far heap == 104368 byte == 104368 byte(other method) ---------------------------------------------------------------------