4

我试图以十进制显示 D0,但是当我运行程序时,什么都没有显示。我没有收到任何错误,当我查看寄存器 D0 时,我看到了十六进制的预期数字,但没有显示十进制等效数字。我正在尝试使用 TRAP 来做到这一点,我们在课堂上展示了这一点。我究竟做错了什么?有问题的代码行是代码开始处的第 17 行。它说“TRAP #15 以十进制显示 D0”。谢谢你的帮助。

*-----------------------------------------------------------
* Program Number: 0
* Written by    : Bryan Kriss
* Date Created  : 10/06/2013
* Description   : This program performs If-then-else statement.
*
*-----------------------------------------------------------
START   ORG $1000   Program starts at loc $1000
IF  CMP     #12,P   Is P > 12? 
    BLE     ENDIF   If P < 12, go to ENDIF
    ASL     P       Shift left
    ASL     P       Shift left
    ASL     P       Shift left
    ADD     #4,P    P + 4
    MOVE    P,D0    Move P into D0
    EXT.L   D0
    TRAP    #15     Display D0 in decimal
    STOP    #$2700   Stop execution

ENDIF   MOVE    Q,D1     Move the value of Q into D1
        SUB     D1,D0    P - D1 (P-Q)
        MOVE    D0,D1    Move P into D1

        STOP    #$2700    Stop execution
* Data section
    ORG $2000   Data starts at loc 2000
P   DC.W    15  int P = 15;
Q   DC.W    7   int Q = 7;
    END START
4

1 回答 1

3

根据文档,您需要将选择器放在 D0 中,将实际值放在 D1 中。

改变:

MOVE    P,D0    Move P into D0
EXT.L   D0
TRAP    #15     Display D0 in decimal

至:

MOVE    P,D1    Move P into D1
EXT.L   D1
MOVE.B  #3,D0   Put required TRAP #15 selector (3) in D0
TRAP    #15     Display D0 in decimal

进一步澄清:TRAP #15是执行easy68k环境支持的各种任务的通用机制。为了指定要执行的任务,您传递D0 中的任务选择器。然后,根据您使用的选择器,还需要将其他参数加载到正确的寄存器中,通常是D1A1

easy68k 网站上有一个完整的选择器列表- 前几个选择器是:

TRAP #15 is used for I/O.  Put the task number in D0.

 Task
  0  Display string at (A1), D1.W bytes long (max 255) with carriage return and line feed (CR, LF). (see task 13)
  1  Display string at (A1), D1.W bytes long (max 255) without CR, LF. (see task 14)
  2  Read string from keyboard and store at (A1), NULL terminated, length retuned in D1.W (max 80)
  3  Display signed number in D1.L in decimal in smallest field. (see task 15 & 20)
  ...
于 2013-10-08T22:10:56.303 回答