Ä¿Ç°ÕýÔÚѧϰLinux»ã±à£¬Ð´Ð´ÎÄÕ¹²ÏíÒ»ÏÂÐĵÃ
»ã±àÓïÑÔ×÷ΪһÖÖ¸ßЧµÄ£¬¶øÇÒ½ôÃܽáºÏÓ²¼þƽ̨µÄ±à³ÌÓïÑÔ£¬ÔÚ²Ù×÷ϵͳ£¬Ç¶Èëʽ¿ª·¢µÈÁìÓò¶¼ÓÐ×ÅÊ®·ÖÖØÒªµÄ×÷Óá£ÕýÒòΪ»ã±àÒÀÀµÓÚÓ²¼þ½á¹¹£¨CPUÖ¸ÁîÂ룩£¬Òò´Ë²»Í¬Ìåϵ½á¹¹ÉϵĻã±àÓïÑÔÒ²´óÏྶͥ¡£Ä¿Ç°¹úÄÚ´óѧµÄ»ã±àÓïÑԿγ̴ó¶àÒÔIntelƽ̨µÄÓï·¨¸ñʽÀ´½²Êö£¬¶øÊÐÃæÉϽ²ÊöÆäËûÌåϵ½á¹¹»ã±àÓïÑÔµÄÊé¼®Ò²ÊÇÁÈÁÈÎÞ¼¸£¬Õâ¾Í¸øϵͳ³ÌÐòÔ±Ñо¿ÆäËûƽ̨»ã±à´úÂë´øÀ´Á˺ܴóµÄÀ§ÄÑ¡£±¾Îļòµ¥½éÉÜÁËLinuxϵÄAT&TÓï·¨£¬ÒÔ¼°ÔÚLinuxÏ»ã±àµÄ»ù±¾·½·¨¡£
AT&TÓï·¨ÆðÔ´ÓÚAT&T±´¶ûʵÑéÊÒ£¬ÊÇÔÚµ±Ê±ÓÃÓÚʵÏÖUnixϵͳµÄ´¦ÀíÆ÷²Ù×÷ÂëÓï·¨Ö®É϶øÐγɵģ¬AT&TÓï·¨ºÍIntelÓï·¨Ö÷ÒªÇø±ðÈçÏ£º
AT&TʹÓÃ$±íʾÁ¢¼´Êý£¬Intel²»Óã¬Òò´Ë±íʾʮ½øÖÆ2ʱ£¬AT&TΪ$2£¬¶øIntel¾ÍÊÇ2
AT&TÔڼĴæÆ÷Ç°¼Ó%£¬±ÈÈçeax¼Ä´æÆ÷±íʾΪ%eax
AT&T ´¦Àí²Ù×÷ÊýµÄ˳ÐòºÍIntelÏà·´£¬±ÈÈ磬movl %eax, %ebxÊǽ«eaxÖеÄÖµ´«µÝ¸øebx£¬¶øIntelÊÇÕâÑùµÄmov ebx, eax
AT&TÔÚÖú¼Ç·ûµÄºóÃæ¼ÓÉÏÒ»¸öµ¥¶À×Ö·û±íʾ²Ù×÷ÖÐÊý¾ÝµÄ³¤¶È£¬±ÈÈçmovl $foo, %eaxµÈͬÓÚIntelµÄmov eax, word ptr foo
³¤ÌøתºÍµ÷Óõĸñʽ²»Í¬£¬AT&TΪljmp $section, $offset£¬¶øIntelΪjmp section:offset
Ö÷ÒªµÄÇø±ð¾ÍÊÇÕâЩ£¬ÆäËûµÄϸ½Ú»¹Óкܶ࣬ÏÂÃæ¸ø³öÒ»¸ö¾ßÌåµÄÀý×ÓÀ´ËµÃ÷
[code]#cpuid.s Sample program
.section .data
output:
.ascii "The processor Vendor ID is 'xxxxxxxxxxxx'\n"
.section .text
.globl _start
_start:
movl $0, %eax
cpuid
movl $output, %edi
movl %ebx, 28(%edi)
movl %edx, 32(%edi)
movl %ecx, 36(%edi)
movl $4, %eax
movl $1, %ebx
movl $output, %ecx
movl $42, %edx
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80[/code]
Õâ¸ö³ÌÐòµÄ×÷ÓÃÊDzéѯCPUµÄ³§ÉÌID£¬ÆäÖУº
,ascii¶¨Òå×Ö·û´®£¨ºÍIntel¸ñʽÍêÈ«²»Í¬£©.sectionÊÇÉùÃ÷¶ÎµÄÓï¾ä£¬.dataºÍ.textÊǶÎÃû£¬·Ö±ðΪÊý¾Ý¶ÎºÍ´úÂë¶Î£¬_startÊÇgas£¨GNU»ã±àÆ÷£©µÄĬÈÏÈë¿Ú±êÇ©£¬±íʾ³ÌÐò´ÓÕâÀ↑ʼִÐС£.globl½«_startÉùÃ÷³ÉÁËÍⲿ³ÌÐò·ÃÎʵıêÇ©¡£cpuidΪָÁîÇëÇóCPUµÄÖ¸¶¨ÐÅÏ¢£¬¸ÃÖ¸ÁîÓÃeax×÷ΪÊäÈ룬ebx,edx,ecx×÷ΪÊä³ö£¬ÕâÀォ0×÷ΪcpuidµÄÊäÈëÖ¸ÁÇëÇó·µ»ØCPUµÄ³§ÉÌID×Ö·û´®¡£·µ»ØµÄ½á¹û£¬Ò»¸ö12×Ö½ÚµÄ×Ö·û´®£¬·Ö±ð´æ´¢ÔÚÈý¸ö¼Ä´æÆ÷ÖУ¬ÆäÖÐebx´æ·ÅµÍ4룬edxÖмä4룬ecx¸ß4λ£¨×¢Òâ˳Ðò£¡£©¡£½ÓÏÂÀ´¶¨ÒåÒ»¸öÖ¸Õëedi£¬ediÖ¸ÏòoutputµÄ¿ªÊ¼µØÖ·£¬È»ºó½Ó×ŵÄ3ÌõÓï¾ä½«outputÀïµÄxÌ滻Ϊ³§ÉÌÐÅÏ¢¡£28£¨%edi£©ÖеÄ28±íʾƫÒÆÁ¿£¬¼´Õû¸öµØַΪ%ediÀïµÄµØÖ·¼ÓÉÏ28¸ö×Ö½Ú£¬Õâ¸öµØÖ·ÕýºÃÊÇoutputÀïµÚÒ»¸öxµÄµØÖ·¡£ÔÙ½ÓÏÂÀ´¾ÍÊÇ´òÓ¡½á¹ûÁË£¬ÕâÀïÓõ½ÁËLinuxµÄÒ»¸öϵͳµ÷Óã¨int 0x80£©£¬¸Ãϵͳµ÷ÓõIJÎÊý·Ö±ðΪ£ºeax ϵͳµ÷Óúţ¬ebx ҪдÈëµÄÎļþÃèÊö·û£¬ecx ×Ö·û´®Ê×µØÖ·£¬edx ×Ö·û´®³¤¶È£¬³ÌÐòÀïÕâЩ¸ö²ÎÊýµÄÖµ·Ö±ðΪ4£¬1£¨±ê×¼Êä³ö£©£¬outputµÄµØÖ·ºÍ42¡£×îºóÔٴε÷ÓÃ1ºÅϵͳµ÷ÓÃ-Í˳öº¯Êý£¬·µ»Øshell£¬Õâ´ÎebxÖеÄÖµÊÇ·µ»Ø¸øshellµÄÍ˳ö´úÂ룬0±íʾÎÞÒì³£
È»ºó»ã±àÁ¬½ÓÔËÐгÌÐò£º
[code]$as -o cpuid.o cpuid.s
$ld -o cpuid cpuid.o
$./cpuid
The processor Vendor ID is 'GenuineIntel'
$[/code]
±¾È˵ĵçÄÔÊÇPentium MµÄCPUËùÒÔ·µ»ØµÄ½á¹ûÊÇGenuineIntel¡£
¼¸µã˵Ã÷£º
1£©LinuxµÄ±ê×¼»ã±à»·¾³Îªas£¬ld£¬gdb,gprof,objdumpµÈGNU¿ª·¢µ÷ÊÔ¹¤¾ß£¬³ýÁËgdbÍ⣬ÆäËûÈ«²¿Ëæbinutils°ü·¢²¼¡£ÆäÖÐasʹÓõÄÊÇAT&TÓï·¨¡£ÔÚLinuxÏÂÒ²¿ÉÒÔʹÓÃNasmÀ´½øÐÐIntel¸ñʽµÄ»ã±à³ÌÐò±àд£¬¾ßÌåNasmµÄʹÓ÷½·¨¼û±¾ÈËblogµÄ¡¶NasmʹÓÃÊֲᡷ
2£©LinuxÏ»ã±àµÄϵͳµ÷ÓÃΪint 0x80£¬ºÍDOSϵÄint 21h´óͬСÒ죬ֻ²»¹ý´«µÝ²ÎÊý²»Í¬
3£©¶ÎÉùÃ÷Óï¾ä.section²»ÐèÒªÏñIntel¸ñʽÄÇÑùÔڶνáβµÄʱºò¼ÓÉ϶νáÊø±êÖ¾£¨SEGMENT/ENDS£©£¬ÏÂÒ»¸ö¶ÎµÄ¿ªÊ¼×Ô¶¯±êÖ¾×ÅÉϸö¶ÎµÄ½áÊø
4£©¼òµ¥³ÌÐòµÄÈë¿Ú±êÇ©²»ÊDZØÐëÒª¶¨ÒåµÄ£¬ld»á×Ô¼ºÅжÏÈë¿Ú£¬µ«ÊÇ»á¸ø³ö¾¯¸æ
5£©±¾ÎIJ¿·ÖÄÚÈÝÀ´Ô´ÓÚRichard BlumµÄ¡¶Professional Assembly Language¡·Ò»Êé
ÃÞ°À¼Ó¶Ì¿ã ÓÚ 2010-09-25 20:42:15·¢±í:
[quote][/quote]
glxin1982 ÓÚ 2010-05-13 21:05:42·¢±í:
:0wpoi2
Ò¹µÄÆßÏÒ ÓÚ 2010-05-13 02:19:37·¢±í:
ÄÇÔõôÊä³öÒ»¸öÕûÊýÄØ
Îä´óСǿ ÓÚ 2010-03-23 07:26:26·¢±í:
ÊÕÁË£¬Ð»Ð»·ÖÏí
xuruiyi ÓÚ 2010-03-21 23:48:02·¢±í:
½²µÄºÜÒ»°ã°¡£¡Ñ§Ï°ÁË£¬Ð»Ð»
221.217.209.* ÓÚ 2007-02-27 17:28:48·¢±í:
h hhhhhhhhhhhhhh
snaildr ÓÚ 2006-10-02 20:38:50·¢±í:
dddddddddddddddddd
snaildr ÓÚ 2006-10-02 20:33:36·¢±í:
ddddddddddd
snaildr ÓÚ 2006-10-02 20:28:48·¢±í:
dddddddddd