The program that I am in the process of writing takes input in the form of a single digit number followed by a space followed by a two digit number. The program will take the two numbers and add them together, reduce number by 7s until less than 7, and associate that number with a day of the week. Here is what I have:
start: initIO * Initialize (required for I/O)
setEVT * Error handling routines
* initF * For floating point macros only
linein buffer *reads in values
cvta2 buffer,#1 *provided macro to convert ascii to num, read first digit only
move.b D0,D1 *Store value in D1
cvta2 buffer+2,#2 *read the next two digits after space
move.b D0,D2 *store
add.b D1,D2 *add them together (I can probably use just one register here)
here is the trouble:
for: cmp.w week, D2 *<<<<< This is saying invalid syntax, I want to see if the number provided is greater than 7, if not branch out to the next section
/trouble
ble done
subq.w #7,D2 *If num>7, sub 7
done:
lineout dmsg
break * Terminate execution
*
*----------------------------------------------------------------------
* Storage declarations
buffer: dc.b 80
dmsg: dc.b 'Done',0
week: dc.b $7 *If combined value is greater than this, sub 7
*These are the values to check against to get correct reply
sun: dc.b $1
mon: dc.b $2
tues: dc.b $3
weds: dc.b $4
thurs: dc.b $5
fri: dc.b $6
sat: dc.b $7
*These are the responses for the output
sunr: dc.b 'Sunday',0
monr: dc.b 'Monday',0
tuesr: dc.b 'Tueday',0
wedsr: dc.b 'Wednesday',0
thursr: dc.b 'Thursday',0
frir: dc.b 'Friday',0
satr: dc.b 'Saturday',0
end
There will be more code when I figure out how to make the comparison above, but it will be the same sort of comparison just using the result against the days of the week values in order to provide the correct response.
I have tried using the various forms of cmp (cmpa, cmpi.w/l, etc), but I cannot seem to find a method that allows me to compare the two values. Would I have to load the value I labeled "week" into a register before trying to compare it or something like that?
Examples of I/O:
Input:
1 10
Output:
"Wednesday"
Any insight is appreciated. Thanks for your time.
You are trying to perform a comparison with an unsupported addressing mode (in your example the 'week' operand is not an immediate value, but a memory address).
To compare D2 with 7 you can use cmpi (compare immediate):
cmpi.b #7,d2
In case you need the operand to be a variable, you must load it into a register first:
lea week,a0
...
cmp.b (a0),d2
Also make sure the operand size in the cmp instruction matches the size of your data