Ê×ÏÈ£¬ÎÒÃÇÏÈ¿´Ò»¸ö¼òµ¥µÄ»ã±à³ÌÐò£º
area ff,code,readonly £»ÉùÃ÷´úÂë¶Î
code32 £»ÉùÃ÷Ϊ32λARMÖ¸Áî
entry £»ÉùÃ÷³ÌÐòÈë¿Ú
start
;bÖ¸Áî
;1.b Ìøת·¶Î§+_ 32M b + ±êºÅ
;b start
;b stop
;2.bl ×Óº¯Êýµ÷ÓÃ
;»á°ÑԤȡָÁîµÄµØÖ·±£´æÔÚlr£¨r14£©
;3.bx ×Óº¯Êý·µ»Ø
mov r0,#9
mov r1,#15
mov r5,#9
bl func
;int func(int a,int b)
stop
b stop
func
mov r5,#1
loop
cmp r0,r1
beq stop1
subgt r0,r0,r1
sublt r1,r1,r0
b loop
stop1
bx lr
end
¿ÉÒÔ¿´³ö£¬ARM»ã±à³ÌÐòÓá°£»¡±ºÅ½øÐÐ×¢ÊÍ¡£
Ò»¡¢»ã±àÓïÑÔ³ÌÐò¸ñʽ
Ò»¸öÍêÕûµÄARM»ã±àÓÉÁ½²¿·Ö×é³É£ºÉùÃ÷£¬Êµ¼Ê´úÂë¶ÎÁ½²¿·Ö×é³É¡£
1¡¢ÉùÃ÷
ÔÚÒ»¸ö³ÌÐò֮ǰÏÈÒª½øÐÐÉùÃ÷£º
1£©ÉùÃ÷´úÂë¶Î£º
ÓÃAREAÖ¸ÁÒåÒ»¸ö¶Î£¬ËµÃ÷Ëù¶¨Òå¶ÎµÄÏà¹ØÊôÐÔ¡£(˵Ã÷¶ÎµÄÃû×Ö£¬¶ÎµÄÊôÐÔ)
2£© ÉùÃ÷ARMÖ¸Á
ÓÃCODE32»òCODE16À´ÉùÃ÷³ÌÐòΪ32λARMÖ¸Áî»òÊÇ16λThumbÖ¸Áî¡£
3£© ÉùÃ÷³ÌÐòÈë¿Ú£º
ÓÃENTRYÖ¸Áî±êʶ³ÌÐòµÄÈë¿Úµã¡£
×¢£º
Õâ3¸öÉùÃ÷ȱһ²»¿É¡£
ÔÚ³ÌÐòÍê³ÉºóÒªÓÃEND Ö¸ÁîÉùÃ÷³ÌÐò½áÊø¡£Ã¿Ò»¸ö»ã±à³ÌÐò¶Î¶¼±ØÐëÓÐÒ»ÌõENDÖ¸Áָʾ´úÂë¶ÎµÄ½áÊø¡£
2¡¢¶Î
1£©ÔÚARM»ã±àÓïÑÔ³ÌÐòÖУ¬ÒÔ³ÌÐò¶ÎΪµ¥Î»×éÖ¯´úÂë¡£¶ÎÊÇÏà¶Ô¶ÀÁ¢µÄÖ¸Áî»òÊý¾ÝÐòÁÐ,¾ßÓÐÌض¨µÄÃû³Æ¡£
2£©¶ÎµÄ·ÖÀà
´úÂë¶Î:´úÂë¶ÎµÄÄÚÈÝΪִÐдúÂë
Êý¾Ý¶Î:Êý¾Ý¶Î´æ·Å´úÂëÔËÐÐʱÐèÒªÓõ½µÄÊý¾Ý¡£
×¢£ºÒ»¸ö»ã±à³ÌÐòÖÁÉÙÓÐÒ»¸ö´úÂë¶Î¡£Èç¹û³ÌÐò½Ï³¤Ê±£¬¿ÉÒÔ·Ö¸îΪ¶à¸ö´úÂë¶ÎºÍÊý¾Ý¶Î¡£¶à¸ö¶ÎÔÚ³ÌÐò±àÒëÁ¬½Óʱ×îÖÕÐγÉÒ»¸ö¿ÉÖ´ÐеÄÓ³ÏñÎļþ¡£
3£©¶Î¾ßÓÐÒÔϵÄÊôÐÔ
Ø READONLY
Ø READWRITE
¶þ¡¢»ã±àÓïÑÔµÄÓï¾ä¸ñʽ
[LABEL] OPERATION [OPERAND] [£»COMMENT]
±êºÅÓò ²Ù×÷Öú¼Ç·ûÓò ²Ù×÷ÊýÓò ×¢ÊÍÓò
1. ±êºÅÓò£¨LABLE£©
1>±êºÅÓòÓÃÀ´±íʾָÁîµÄµØÖ·¡¢±äÁ¿¡¢¹ý³ÌÃû¡¢Êý¾ÝµÄµØÖ·ºÍ³£Á¿¡£
2>±êºÅÊÇ¿ÉÒÔ×Ô¼ºÆðÃûµÄ±êʶ·û£¬Óï¾ä±êºÅ¿ÉÒÔÊÇ´óСд×Öĸ»ìºÏ£¬Í¨³£ÒÔ×Öĸ¿ªÍ·£¬ÓÉ×Öĸ¡¢Êý×Ö¡¢Ï»®ÏßµÈ×é³É¡£
3> Óï¾ä±êºÅ²»ÄÜÓë¼Ä´æÆ÷Ãû¡¢Ö¸ÁîÖú¼Ç·û¡¢Î±Ö¸Áî(²Ù×÷)Öú¼Ç·û¡¢±äÁ¿ÃûͬÃû¡£
4> Óï¾ä±êºÅ±ØÐëÔÚÒ»ÐеĿªÍ·Êéд£¬²»ÄÜÁô¿Õ¸ñ¡£
2. ²Ù×÷Öú¼Ç·ûÓò(OPERATION)
1>²Ù×÷Öú¼Ç·ûÓò¿ÉÒÔΪָÁα²Ù×÷¡¢ºêÖ¸Áî»òαָÁîµÄÖú¼Ç·û¡£
2> ARM»ã±àÆ÷¶Ô´óСдÃô¸Ð£¬ÔÚ»ã±àÓïÑÔ³ÌÐòÉè¼ÆÖУ¬Ã¿Ò»ÌõÖ¸ÁîµÄÖú¼Ç·û¿ÉÒÔÈ«²¿Óôóд¡¢»òÈ«²¿ÓÃСд£¬µ«²»ÔÊÐíÔÚÒ»ÌõÖ¸ÁîÖдó¡¢Ð¡Ð´»ìÓá£
3> ËùÓеÄÖ¸Á²»ÄÜÔÚÐеĿªÍ·Êéд£¬±ØÐëÔÚÖ¸ÁîµÄÇ°ÃæÓпոñ£¬È»ºóÔÙÊéдָÁî¡£
4> Ö¸ÁîÖú¼Ç·ûºÍºóÃæµÄ²Ù×÷Êý»ò²Ù×÷¼Ä´æÆ÷Ö®¼ä±ØÐëÓпոñ£¬²»¿ÉÒÔÔÚÕâÖ®¼äʹÓöººÅ¡£
3. ²Ù×÷ÊýÓò(OPERAND)
²Ù×÷ÊýÓò±íʾ²Ù×÷µÄ¶ÔÏ󣬲Ù×÷Êý¿ÉÒÔÊdz£Á¿¡¢±äÁ¿¡¢±êºÅ¡¢¼Ä´æÆ÷Ãû»ò±í´ïʽ£¬²»Í¬¶ÔÏóÖ®¼ä±ØÐëÓöººÅ¡°£¬¡±·Ö¿ª¡£
Èý¡¢ARMÖ¸Á¸ñʽ
opcode {<cond>}{S} <Rd>,<Rn> {,<operand2>}
1¡¢ÆäÖÐ<>ÖеÄÏîÊDZØÐëµÄ£¬£û£ýÖеÄÏîÊÇ¿ÉÑ¡µÄ¡£
2¡¢opcode ±íʾָÁîÖú¼Ç·û¡£
cond:±íʾִÐÐÌõ¼þ¡£
S:±íʾÊÇ·ñÓ°ÏìCPSR¼Ä´æÆ÷µÄÖµ¡£
Rd:±íʾĿ±ê¼Ä´æÆ÷¡£
Rn:±íʾµÚÒ»¸ö²Ù×÷ÊýµÄ¼Ä´æÆ÷¡£
operand2:±íʾµÚ2¸ö²Ù×÷Êý¡£
3¡¢¡°operand2¡±¾ßÓÐÈçϵÄÐÎʽ£º
1>#immed_8r:³£Êý±í´ïʽ
eg: MOV R0,#1
ADD R0,R1,#0X0F
2>Rm:¼Ä´æÆ÷ÐÎʽ¡£
¼´ÔڼĴæÆ÷·½Ê½Ï£¬²Ù×÷Êý¼´Îª¼Ä´æÆ÷µÄÊýÖµ¡£
eg: MOV PC,R0
ADD R1,R1,R2
3>Rm,shift:¼Ä´æÆ÷ÒÆλ·½Ê½¡£
½«¼Ä´æÆ÷µÄÒÆλ½á¹û×÷Ϊ²Ù×÷Êý£¬µ±RmÖµ±£³Ö²»±ä¡£
Ø ASR #n:±íʾËãÊõÓÒÒÆnλ¡£
Ø LSR #n:±íʾÂß¼ÓÒÒÆnλ¡£
Ø ROR #n:±íʾѻ·ÓÒÒÆnλ¡£
Ø RRX #n:´øÀ©Õ¹µÄÑ»·ÓÒÒÆnλ¡£
Ø LSL #n:Âß¼×óÒÆnλ¡£
4¡¢ ʹÓÃÌõ¼þÂë¡°cond¡±¿ÉÒÔʵÏÖ¸ßЧµÄÂß¼²Ù×÷£¬Ìá¸ß´úÂëµÄЧÂÊ¡£
Ø ËùÓеÄARMÖ¸Á¿ÉÒÔÌõ¼þÖ´ÐС£
Ø ThumbÖ¸ÁîÖ»ÓÐB(Ìøת)Ö¸Áî¾ßÓÐÌõ¼þÖ´Ðй¦ÄÜ¡£
×¢£ºÈç¹ûÖ´ÐÐÖв»±íÃ÷Ìõ¼þÂ룬ĬÈÏΪÎÞÌõ¼þ(AL)Ö´ÐС£
ËÄ¡¢»ã±à³ÌÐòÖг£ÓõķûºÅ
ÔÚ»ã±àÓïÑÔ³ÌÐòÉè¼ÆÖУ¬¾³£Ê¹Óø÷ÖÖ·ûºÅ±íʾ±äÁ¿¡¢³£Á¿ºÍµØÖ·
Ø ·ûºÅÓÉ´óСд×Öĸ¡¢Êý×ÖÒÔ¼°Ï»®Ïß×é³É¡£
Ø ·ûºÅÇø·Ö´óСд£¬Í¬ÃûµÄ´ó¡¢Ð¡Ð´·ûºÅ»á±»±àÒëÆ÷ÈÏΪÊÇÁ½¸ö²»Í¬µÄ·ûºÅ¡£
Ø ·ûºÅÔÚÆä×÷Ó÷¶Î§ÄÚ±ØÐëΨһ£¬¼´ÔÚÆä×÷Ó÷¶Î§ÄÚ²»¿ÉÓÐͬÃûµÄ·ûºÅ¡£
Ø ×Ô¶¨ÒåµÄ·ûºÅÃû²»ÄÜÓëϵͳµÄ±£Áô×ÖÏàͬ¡£
·ûºÅÃû²»Ó¦ÓëÖ¸Áî»òαָÁîͬÃû¡£
1. ³ÌÐòÖеıäÁ¿:
1>ARM»ã±à³ÌÐòËùÖ§³ÖµÄ±äÁ¿ÓÐÊý×Ö±äÁ¿£¬Âß¼±äÁ¿ºÍ×Ö·û´®±äÁ¿
2>ÔÚARM»ã±à³ÌÐòÉè¼ÆÖУ¬¿ÉʹÓÃGBLA,GBLL,GBLSᶨÒåÉùÃ÷È«¾Ö±äÁ¿£¬Ê¹ÓÃLCLA,LCLL,LCLSÉùÃ÷¾Ö²¿±äÁ¿£¬²¢¿ÉʹÓÃSETA,SETLºÍSETS¶ÔÆä¾Ðгõʼ»¯¡£
2. ³ÌÐòÖеij£Á¿
1>ARM»ã±à³ÌÐòËùÖ§³Ö³£Á¿ÓÐÊý×Ö³£Á¿£¬Âß¼³£Á¿ºÍ×Ö·û´®³£Á¿¡£
3. ³ÌÐòÖеıäÁ¿´ú»»
1>³ÌÐòÖеıäÁ¿¿Éͨ¹ý´ú»»²Ù×÷È¡µÄÒ»¸ö³£Á¿¡£´ú»»²Ù×÷·ûΪ¡±$¡±
2>ʹÓÃʾÀý£º
LCLS S1
LCLS S2 ;¶¨Òå¾Ö²¿×Ö·û´®±äÁ¿S1ºÍS2
S1 SETS ¡°Test!¡±
S2 SETS ¡°This is a $ S1¡±;S2µÄֵΪ¡°This is a Test