0

What I am trying to achieve in this program is to take a single line of input, a single digit number followed by a space followed by a 2 digit number, add them together, divide by 9, and compare the result to cases for the different outputs.

Something like this could be accomplished by using strtok, using the space as a delimiter, then adding the values together, but I am unaware of how to do this for the M68k.

I am using EASy68k to compile and test the following code in assembly for the motorola 68000:

Here are some examples of expected input/output:

Enter [1-9] and the number to add [01-20]:

User input: "1 01"

"Hello Venus" (Would start at response 1, then increment by 1)

User input: "1 02"

"Hello Earth" (Would start again at 1, then increment 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
Jeremy H.
  • 69
  • 1
  • 11
  • Assembler is the worst option for this case. Compile C file and then see what have you done wrong – 0___________ Oct 13 '17 at 00:08
  • I'm not sure if I'm getting you. At this moment the code takes as input single number. (?) And you want to take as input `"# ##"` ... There are many ways how to change your code, depends what you want to do with those numbers further. Probably the easiest way to verify user did enter "\d\ \d{2}" (regexp notation) is to read 4 times single character and test whether first, third and fourth were digits, and second was space, as that's very small formatting string, and it looks like you don't need to parse the values themselves. BTW you have lot of code for something that single table can do. – Ped7g Oct 13 '17 at 00:28
  • Oh, now I get it probably, so user inputs *a* and *b*, and you print result by 1+((a+b)%9) value (i.e. 1+20 = 21, 21%9 = 3, so `DISPFOU` text should be displayed (1+3). But I also don't have idea, what you mean by "compile and test C". The common sense would to take C as C programming language, but you have assembly here. – Ped7g Oct 13 '17 at 00:35
  • I tried to clarify the post some more. I am working with assembly as opposed to C. PeterJ had mentioned C and I thought I had incorrectly stated my issue. I am working with motorola 68000 assembly through a program called EASy68k. – Jeremy H. Oct 13 '17 at 02:02
  • So change that *"Code for input"* part to read either whole string, or char by char, and parse the results... not sure what answer you expect here, SO is not code writing service. It works like that sometimes, but you may get more lucky if you at least try something and then describe what particular problem you have. At the moment this is "too broad", as you can implement such thing in million of ways, so hard to tell which one to pursuit, which one is close to your way of thinking and coding. BTW, what happens if you read number like now, then one char (expecting space), then again number? – Ped7g Oct 13 '17 at 08:29
  • Well currently one issue that that with the code is the space that acts as a terminator and it will only read the first integer. The other problem is that there is not nearly the same amount of documentation on this as there is for any higher level language. – Jeremy H. Oct 13 '17 at 16:42
  • If I were writing this in C, I would strtok the input, using the space as a delimiter, storing the information in two separate places which would allow me to add them together and divide by 9 if necessary. The only thing that I don't know how to do is the equivalent of strtok in assembly. I have been looking through documentation and examples and I have not yet found a way to do that. If you are aware of how to do that, a simple "look up _____" as I am not looking for a code writing service, but I am looking for a nudge in the right direction. – Jeremy H. Oct 13 '17 at 16:50

0 Answers0