[英]Motorola 68000 assembly comparing numbers
我正在編寫的程序以一位數字后跟一個空格后跟一個兩位數字的形式進行輸入。 該程序將把這兩個數字相加,將數字減少 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 $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
當我弄清楚如何進行上述比較時,將會有更多代碼,但只是使用結果與星期幾值進行比較以提供正確的響應,這將是相同類型的比較。
我曾嘗試使用各種形式的 cmp(cmpa、cmpi.w/l 等),但似乎找不到一種方法可以讓我比較這兩個值。 在嘗試比較它或類似的東西之前,我是否必須將標記為“周”的值加載到寄存器中?
輸入/輸出示例:
輸入:
1 10
輸出:
“周三”
任何見解表示贊賞。 謝謝你的時間。
您正在嘗試與不受支持的尋址模式進行比較(在您的示例中,“周”操作數不是立即數,而是內存地址)。
要將 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 #$0007,D2
lsr.l #$08,D2 *Shift remainder
lsr.l #$08,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 $7
sun: dc.w $1
mon: dc.w $2
tues: dc.w $3
weds: dc.w $4
thurs: dc.w $5
fri: dc.w $6
sat: dc.w $7
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.