如何用68K语言制作IF-ELSE控制结构



我正在为ASM中的68K处理器编写一个程序。

我需要做类似的事情

if (D0 > D1) {
   do_some_stuff();
   do_some_stuff();
   do_some_stuff();
   do_some_stuff();
} else {
   do_some_stuff();
   do_some_stuff();
   do_some_stuff();
   do_some_stuff();
}

,但问题在于它只允许我分支到某个指针或继续执行。

喜欢:

CMP.L   D0,D1       ; compare
BNE AGAIN       ; move to a pointer

制作上述结构的最简单方法是什么?

您可以尝试这样的事情:

if (D0>D1) {
    //do_some_stuff
} else {
    //do_some_other_stuff
}

应该是:

CMP.L   D0,D1       ; compare
BGT AGAIN  
//do_some_other_stuff
BR DONE
AGAIN:
//do_some_stuff
DONE:

阅读有关条件分支的更多信息

最适合这种情况的控制结构是BGT

BGT在大于上的分支)将分支在第二个操作数大于第一操作数时。当您查看幕后发生的事情时,这是有道理的。

CMP.W D1,D0 ;Performs D0-D1, sets the CCR, discards the result 

它设置了CCR(条件代码寄存器),因为仅在(n = 1和V = 1和Z = 0)时进行分支0和z = 0)

现在转换:

if (D0 > D1) {
    //do_some_stuff
} else {
    //do_some_other_stuff
}

进入68K组装语言:

     CMP.W   D1,D0       ;compare the contents of D0 and D1
     BGT     IF 
     // do_some_other_stuff
     BRA     EXIT
IF
     // do_some_stuff
EXIT ...

最新更新