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