共2条
1/1 1 跳转至页
LDR,PC,PC,R2 弱弱地问一下,LDR PC,[PC,R2]的执行结果是什么?
问
如果执行LDR PC,[PC,R2]之前,PC的值为0x0000800c,R2的值为0,
那么执行LDR PC,[PC,R2]之后,PC的值应该为0x0000800c中的数据
即PC = (PC + 0) = 0xe79ff002的,
可是,为什么实际上却是0x00008014中的数据,
即PC = (PC + 8) = (0x00008014) = 0x0x00008024
????
-----------------------------------------------------
源代码如下:
MAIN LDR R0,= NumCon
LDRB R2,[R0] ; 取得跳转控制变量值
MOV R2,R2,LSL #2 ; 功能号乘上4,以便查表
LDR PC,[PC,R2] ; 查表取得对应功能子程序地址,并跳转
NOP
FUN_TAB DCD FUN_SUB0 ; 跳转表
DCD FUN_SUB1
DCD FUN_SUB2
DCD FUN_SUB3
FUN_SUB0 B MAIN
FUN_SUB1 B MAIN
FUN_SUB2 B MAIN
FUN_SUB3 B MAIN
---------------------------------------------------
反汇编:
MAIN [0xe59f002c] ldr r0,0x00008034 ; = #0x40003001
00008004 [0xe5d02000] ldrb r2,[r0,#0]
00008008 [0xe1a02102] mov r2,r2,lsl #2
0000800c [0xe79ff002] ldr pc,[pc,r2]
00008010 [0xe1a00000] nop
FUN_TAB [0x00008024] dcd 0x00008024 $...
00008018 [0x00008028] dcd 0x00008028 (...
0000801c [0x0000802c] dcd 0x0000802c ,...
00008020 [0x00008030] dcd 0x00008030 0...
FUN_SUB0 [0xeafffff5] b MAIN
FUN_SUB1 [0xeafffff4] b MAIN
FUN_SUB2 [0xeafffff3] b MAIN
FUN_SUB3 [0xeafffff2] b MAIN
答 1: 流水线取指比执行超前了2个指令 答 2: 是真的吗?好佩服你,我没想到!
那么执行LDR PC,[PC,R2]之后,PC的值应该为0x0000800c中的数据
即PC = (PC + 0) = 0xe79ff002的,
可是,为什么实际上却是0x00008014中的数据,
即PC = (PC + 8) = (0x00008014) = 0x0x00008024
????
-----------------------------------------------------
源代码如下:
MAIN LDR R0,= NumCon
LDRB R2,[R0] ; 取得跳转控制变量值
MOV R2,R2,LSL #2 ; 功能号乘上4,以便查表
LDR PC,[PC,R2] ; 查表取得对应功能子程序地址,并跳转
NOP
FUN_TAB DCD FUN_SUB0 ; 跳转表
DCD FUN_SUB1
DCD FUN_SUB2
DCD FUN_SUB3
FUN_SUB0 B MAIN
FUN_SUB1 B MAIN
FUN_SUB2 B MAIN
FUN_SUB3 B MAIN
---------------------------------------------------
反汇编:
MAIN [0xe59f002c] ldr r0,0x00008034 ; = #0x40003001
00008004 [0xe5d02000] ldrb r2,[r0,#0]
00008008 [0xe1a02102] mov r2,r2,lsl #2
0000800c [0xe79ff002] ldr pc,[pc,r2]
00008010 [0xe1a00000] nop
FUN_TAB [0x00008024] dcd 0x00008024 $...
00008018 [0x00008028] dcd 0x00008028 (...
0000801c [0x0000802c] dcd 0x0000802c ,...
00008020 [0x00008030] dcd 0x00008030 0...
FUN_SUB0 [0xeafffff5] b MAIN
FUN_SUB1 [0xeafffff4] b MAIN
FUN_SUB2 [0xeafffff3] b MAIN
FUN_SUB3 [0xeafffff2] b MAIN
答 1: 流水线取指比执行超前了2个指令 答 2: 是真的吗?好佩服你,我没想到!
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |