汇编语言ccr学习汇编遇到麻烦

发布于 2024-10-17 13:23:31 字数 492 浏览 7 评论 0原文

他提出了这些问题 一个。 13显然是样本集中最大的一条数据。将 13 存储到 D0 后,当另一个数字与它进行比较时,CCR 的状态是什么(只需给出 5 位并指示哪些位被触发)。 b.最后一块数据(0)移入 D1 寄存器后,CCR 的状态如何。

*    

ORG $400  
MOVEA.L #DATA,A0  
CLR.B   D0  
NEXT    MOVE.B (A0),D1  
BEQ EXIT  
CMP.B   D0,D1  
BLE EndTest  
MOVE.B  D1,D0  
EndTest ADDA.L  #1,A0  
BRA NEXT    
EXIT    STOP    #$2700  
*         
ORG $1000  
Data    DC.B    12,13,5,6,4,8,4,10,0      
END $400      

我编译了它,但在 easy68k 中没有看到 5 位。我知道 ccr 是由标志位组成的,但我不知道该怎么做。

He gave these questions
a. 13 is obviously the largest piece of data in the sample set. After 13 was stored in D0, what was the state of the CCR when another number was compared against it (just give the 5 bits and indicate which bits were triggered).
b. What was the state of the CCR after the final piece of data (0) was moved into the D1 register.

*    

ORG $400  
MOVEA.L #DATA,A0  
CLR.B   D0  
NEXT    MOVE.B (A0),D1  
BEQ EXIT  
CMP.B   D0,D1  
BLE EndTest  
MOVE.B  D1,D0  
EndTest ADDA.L  #1,A0  
BRA NEXT    
EXIT    STOP    #$2700  
*         
ORG $1000  
Data    DC.B    12,13,5,6,4,8,4,10,0      
END $400      

I compiled it, but I don't see 5 bits in easy68k. I know ccr is made of flag bits but i'm not sure what to do.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只怪假的太真实 2024-10-24 13:23:31

此循环等效于以下 C 代码:

char *byte = data;
char cur, max = 0;

while ((cur = *byte++))
    if (cur > max) max = cur;

即循环将始终迭代所有值,并在找到末尾的零时终止。这意味着当您点击 EXIT 时,您已经完成了 BEQ EXIT 检查,该检查测试了先前加载的结果并发现它为零。 CCR 将为 0x??04,即仅设置 Z、零标志,因为这是 BEQ 检查的内容。

BLE 测试而言,这是对标志的复杂检查;根据摩托罗拉68k参考手册表3.19,测试Z || (N && !V) || (!N && V),即 N / V 或零(即等于 部分),因此标志的几种组合可能会导致采用该分支。对于您的具体数据,我假设,鉴于先前的值为 12,您最终将设置 N,即 CCR 值为 0x??08 (大多数 CPU 上的 CMP 会执行减法并丢弃,并且 12-13 为负数)。

关于 m68k 汇编,本 wikibook 是一个很好的介绍。它描述了条件分支/CCR 标志测试,但省略了上面的棘手部分......

This loop is equivalent to the following C code:

char *byte = data;
char cur, max = 0;

while ((cur = *byte++))
    if (cur > max) max = cur;

I.e. the loop will always iterate over all values and terminate when it finds the zero at the end. That means by the time you hit EXIT, you've gone through the BEQ EXIT check that tested the result of the previous load and found it to be zero. The CCR will be 0x??04, i.e. only the Z, zero flag set, as that's what BEQ checks for.

As far as the BLE test goes, this is a complex check on the flags; According to Motorola's 68k reference manual, table 3.19, it tests for Z || (N && !V) || (!N && V), i.e. for mutual exclusivity of N / V or zero (that'd be the equal part), so several combinations of the flags may result in that branch being taken. For your specific data, I would assume that, given the previous value was 12, you'll end up with N set, i.e. a CCR value of 0x??08 (CMP on most CPUs does a subtract-with-discard, and 12-13 is negative).

Regarding m68k assembly, this wikibook is a good intro. It describes conditional branches / CCR flag tests but leaves out the tricky bits above ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文