摩托罗拉 68000 组装比较数字
Motorola 68000 assembly comparing numbers
我正在编写的程序以一位数字的形式输入,然后是 space,然后是两位数字。该程序会将这两个数字相加,将数字减 7 直到小于 7,并将该数字与星期几相关联。这是我拥有的:
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)
麻烦来了:
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
/麻烦
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 *If combined value is greater than this, sub 7
*These are the values to check against to get correct reply
sun: dc.b
mon: dc.b
tues: dc.b
weds: dc.b
thurs: dc.b
fri: dc.b
sat: dc.b
*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
当我弄清楚如何进行上面的比较时,会有更多代码,但它是同一种比较,只是使用结果与星期几的值进行比较,以提供正确的响应。
我尝试过使用各种形式的 cmp(cmpa、cmpi。w/l 等),但我似乎找不到一种方法可以比较这两个值。在尝试比较它或类似的东西之前,我是否必须将我标记为 "week" 的值加载到寄存器中?
I/O的例子:
输入:
1 10
输出:
"Wednesday"
如有任何见解,我们将不胜感激。谢谢你的时间。
您正在尝试与不受支持的寻址模式进行比较(在您的示例中,'week' 操作数不是立即值,而是内存地址)。
要将 D2 与 7 进行比较,您可以使用 cmpi(立即比较):
cmpi.b #7,d2
如果您需要操作数是一个变量,您必须先将其加载到一个寄存器中:
lea week,a0
...
cmp.b (a0),d2
还要确保 cmp 指令中的操作数大小与您的数据大小相匹配
编辑(问题的工作代码,但未优化):
start: initIO * Initialize (required for I/O)
setEVT * Error handling routines
* initF * For floating point macros only
linein buffer
cvta2 buffer,#1
move.l D0,D1
cvta2 buffer+2,#2
move.l D0,D2
add.l D1,D2
divu.w #[=10=]07,D2
lsr.l #,D2 *Shift remainder
lsr.l #,D2
move.w sun,A2
cmp.w A2,D2
BNE monday
lineout sunr
BEQ end
monday:
move.w mon,A2
cmp.w A2,D2
BNE tuesda
lineout monr
BEQ end
tuesda:
move.w tues,A2
cmp.w A2,D2
BNE wednes
lineout tuesr
BEQ end
wednes:
move.w weds,A2
cmp.w A2,D2
BNE thursd
lineout wedsr
BEQ end
thursd:
move.w thurs,A2
cmp.w A2,D2
BNE friday
lineout thursr
BEQ end
friday:
move.w fri,A2
cmp.w A2,D2
BNE saturd
lineout frir
BEQ end
saturd:
lineout satr
BEQ end
end:
break * Terminate execution
*
*----------------------------------------------------------------------
* Storage declarations
buffer: dc.b 80
wkmsg: dc.w 'The day of the week is '
week: equ
sun: dc.w
mon: dc.w
tues: dc.w
weds: dc.w
thurs: dc.w
fri: dc.w
sat: dc.w
sunr: dc.w 'Sunday',0
monr: dc.w 'Monday',0
tuesr: dc.w 'Tueday',0
wedsr: dc.w 'Wednesday',0
thursr: dc.w 'Thursday',0
frir: dc.w 'Friday',0
satr: dc.w 'Saturday',0
end
我正在编写的程序以一位数字的形式输入,然后是 space,然后是两位数字。该程序会将这两个数字相加,将数字减 7 直到小于 7,并将该数字与星期几相关联。这是我拥有的:
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)
麻烦来了:
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
/麻烦
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 *If combined value is greater than this, sub 7
*These are the values to check against to get correct reply
sun: dc.b
mon: dc.b
tues: dc.b
weds: dc.b
thurs: dc.b
fri: dc.b
sat: dc.b
*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
当我弄清楚如何进行上面的比较时,会有更多代码,但它是同一种比较,只是使用结果与星期几的值进行比较,以提供正确的响应。
我尝试过使用各种形式的 cmp(cmpa、cmpi。w/l 等),但我似乎找不到一种方法可以比较这两个值。在尝试比较它或类似的东西之前,我是否必须将我标记为 "week" 的值加载到寄存器中?
I/O的例子:
输入:
1 10
输出:
"Wednesday"
如有任何见解,我们将不胜感激。谢谢你的时间。
您正在尝试与不受支持的寻址模式进行比较(在您的示例中,'week' 操作数不是立即值,而是内存地址)。
要将 D2 与 7 进行比较,您可以使用 cmpi(立即比较):
cmpi.b #7,d2
如果您需要操作数是一个变量,您必须先将其加载到一个寄存器中:
lea week,a0
...
cmp.b (a0),d2
还要确保 cmp 指令中的操作数大小与您的数据大小相匹配
编辑(问题的工作代码,但未优化):
start: initIO * Initialize (required for I/O)
setEVT * Error handling routines
* initF * For floating point macros only
linein buffer
cvta2 buffer,#1
move.l D0,D1
cvta2 buffer+2,#2
move.l D0,D2
add.l D1,D2
divu.w #[=10=]07,D2
lsr.l #,D2 *Shift remainder
lsr.l #,D2
move.w sun,A2
cmp.w A2,D2
BNE monday
lineout sunr
BEQ end
monday:
move.w mon,A2
cmp.w A2,D2
BNE tuesda
lineout monr
BEQ end
tuesda:
move.w tues,A2
cmp.w A2,D2
BNE wednes
lineout tuesr
BEQ end
wednes:
move.w weds,A2
cmp.w A2,D2
BNE thursd
lineout wedsr
BEQ end
thursd:
move.w thurs,A2
cmp.w A2,D2
BNE friday
lineout thursr
BEQ end
friday:
move.w fri,A2
cmp.w A2,D2
BNE saturd
lineout frir
BEQ end
saturd:
lineout satr
BEQ end
end:
break * Terminate execution
*
*----------------------------------------------------------------------
* Storage declarations
buffer: dc.b 80
wkmsg: dc.w 'The day of the week is '
week: equ
sun: dc.w
mon: dc.w
tues: dc.w
weds: dc.w
thurs: dc.w
fri: dc.w
sat: dc.w
sunr: dc.w 'Sunday',0
monr: dc.w 'Monday',0
tuesr: dc.w 'Tueday',0
wedsr: dc.w 'Wednesday',0
thursr: dc.w 'Thursday',0
frir: dc.w 'Friday',0
satr: dc.w 'Saturday',0
end