例行程序输入R0(G1个),R1(b1个),R2(G2)和R3(b2)的输入,并在第二队获胜时设置符号标志,否则将其清除。
275 PSHR R5 ; push return address
110 SUBR R2, R0 ; R0 -= R2
082 MOVR R0, R2 ; R2 = R0
04C SLL R0, 2 ; R0 <<= 2
0D0 ADDR R2, R0 ; R0 += R2
0D0 ADDR R2, R0 ; R0 += R2
0C8 ADDR R1, R0 ; R0 += R1
118 SUBR R3, R0 ; R0 -= R3
2B7 PULR R7 ; return
CP-1610没有乘法指令,一次只能移位1或2个位置,因此我们改为计算以下表达式:
((R0 - R2) << 2) + (R0 - R2) + (R0 - R2) + R1 - R3
完整的测试代码
ROMW 10 ; use 10-bit ROM width
ORG $4800 ; map this program at $4800
;; ------------------------------------------------------------- ;;
;; test code ;;
;; ------------------------------------------------------------- ;;
main PROC
SDBD ; set up an interrupt service routine
MVII #isr, R0 ; to do some minimal STIC initialization
MVO R0, $100
SWAP R0
MVO R0, $101
EIS ; enable interrupts
SDBD ; R4 = pointer to test cases
MVII #@@data, R4
MVII #$200, R5 ; R5 = backtab pointer
@@loop PSHR R5 ; save R5 on the stack
MVI@ R4, R0 ; load the next test case
MVI@ R4, R1 ; into R0 .. R3
MVI@ R4, R2
MVI@ R4, R3
CALL score ; invoke our routine
BMI @@true
MVII #$80, R0 ; set output to '0'
B @@output
@@true MVII #$88, R0 ; set output to '1'
@@output PULR R5 ; restore R5
MVO@ R0, R5 ; draw the output
SDBD ; was it the last test case?
CMPI #@@end, R4
BLT @@loop ; if not, jump to @@loop
DECR R7 ; loop forever
@@data DECLE 1, 0, 0, 1 ; test cases
DECLE 2, 0, 0, 11
DECLE 10, 8, 11, 1
DECLE 0, 0, 1, 0
DECLE 100, 100, 117, 0
DECLE 7, 7, 5, 12
DECLE 2, 0, 0, 13
@@end ENDP
;; ------------------------------------------------------------- ;;
;; ISR ;;
;; ------------------------------------------------------------- ;;
isr PROC
MVO R0, $0020 ; enable display
CLRR R0
MVO R0, $0030 ; no horizontal delay
MVO R0, $0031 ; no vertical delay
MVO R0, $0032 ; no border extension
MVII #$D, R0
MVO R0, $0028 ; light-blue background
MVO R0, $002C ; light-blue border
JR R5 ; return from ISR
ENDP
;; ------------------------------------------------------------- ;;
;; routine ;;
;; ------------------------------------------------------------- ;;
score PROC
PSHR R5 ; push the return address
SUBR R2, R0 ; R0 -= R2
MOVR R0, R2 ; R2 = R0
SLL R0, 2 ; R0 <<= 2
ADDR R2, R0 ; R0 += R2
ADDR R2, R0 ; R0 += R2
ADDR R1, R0 ; R0 += R1
SUBR R3, R0 ; R0 -= R3
PULR R7 ; return
ENDP
输出量
jzIntv的屏幕截图
1. CP-1610操作码使用10位值(称为“ DECLE”)进行编码。该例程的长度为9 DECLE。