Motorola 68k输入比较/添加

时间:2017-10-13 00:03:30

标签: assembly motorola 68000

我想要实现的目标在这个程序中,只需要一行输入,一个数字后跟一个空格,后跟一个2位数字,将它们加在一起,除以9 ,并将结果与​​不同输出的案例进行比较。

这样的事情可以通过使用strtok,使用空格作为分隔符,然后将值一起添加来实现,但我不知道如何为M68k执行此操作。

我正在使用EASy68k在motorola 68000的程序集中编译和测试以下代码:

以下是预期输入/输出的一些示例:

  

输入[1-9]和要添加[01-20]的数字:

用户输入:" 1 01"

  

"你好维纳斯" (从响应1开始,然后递增1)

用户输入:" 1 02"

  

" Hello Earth" (将从1开始,然后再增加2)

CR      EQU     $0D
LF      EQU     $0A

START   ORG    $1000

* Put program code here
        LEA     HEADER,A1   Loads header message into A1
        MOVE.B  #14,D0      Loads '14' into D0
        TRAP    #15         Trap task 14 is output

*------------Code for output----------------
LOOP    LEA     PROMPT,A1
        MOVE.B  #14,D0
        TRAP    #15


*------------Code for input----------------
        MOVE.B  #4,D0           Trap task 4 does the following:
        TRAP    #15             Read a number from the keyboard into D1.L
        CMP.L   #0,D1           Compares D1 to the number 0
        BEQ     DONE            Branch to DONE if they are equal

*--figure out what the number actually is--
        CMP.B   #1,D1           Compares D1 and 1
        BNE     TWO             BEQ branches if D1 and 1 are not equal
        LEA     DISPONE,A1      
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP    

TWO     CMP.B   #2,D1           Compares D1 and 2
        BNE     THREE           BEQ branches if D1 and 2 are not equal
        LEA     DISPTWO,A1      
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP

THREE   CMP.B   #3,D1           Compares D1 and 3
        BNE     FOUR            BEQ branches if D1 and 3 are not equal
        LEA     DISPTHR,A1      
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP

FOUR    CMP.B   #4,D1           Compares D1 and 4
        BNE     FIVE
        LEA     DISPFOU,A1      
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP

FIVE    CMP.B   #5,D1           Compares D1 and 2
        BNE     SIX             BEQ branches if D1 and 2 are not equal
        LEA     DISPFIV,A1      
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP

SIX     CMP.B   #6,D1           Compares D1 and 3
        BNE     SEVEN           BEQ branches if D1 and 3 are not equal
        LEA     DISPSIX,A1      
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP

SEVEN   CMP.B   #7,D1           Compares D1 and 4
        BNE     EIGHT
        LEA     DISPSEV,A1      
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP

EIGHT   CMP.B   #8,D1           Compares D1 and 2
        BNE     NINE            BEQ branches if D1 and 2 are not equal
        LEA     DISPEIG,A1      
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP

NINE    LEA     DISPNIN,A1      
        MOVE.B  #14,D0  
        TRAP    #15

        BRA     LOOP            Branch to LOOP

INVALID LEA     INV,A1
        MOVE.B  #14,D0  
        TRAP    #15
        BRA     LOOP

DONE    MOVE.B  #9,D0
       TRAP    #15             Halt Simulator

CR      EQU     $0D         
LF      EQU     $0A 

HEADER   DC.B    'This is my header',CR,LF,0
PROMPT   DC.B    'Enter [1-9] and the number to add [01-20]:',0
DISPONE  DC.B    'HELLO MERCURY',CR,LF,0
DISPTWO  DC.B    'HELLO VENUS',CR,LF,0
DISPTHR  DC.B    'HELLO EARTH',CR,LF,0
DISPFOU  DC.B    'HELLO MARS',CR,LF,0
DISPFIV  DC.B    'HELLO JUPITER',CR,LF,0
DISPSIX  DC.B    'HELLO SATURN',CR,LF,0
DISPSEV  DC.B    'HELLO URANUS',CR,LF,0
DISPEIG  DC.B    'HELLO NEPTUNE',CR,LF,0
DISPNIN  DC.B    'HELLO PLUTO',CR,LF,0


        END     START

0 个答案:

没有答案