;利用MOVCA,@A+PC指令编写一查平方表程序,
;将片内30H~31H内的数查平方后送入40H~49H单元,
;30H~39H预先存入数据为1,3,5,7,9,2,4,6,8,10.
org 0000h
mov 30h, #1
mov 31h, #2
mov 32h, #3
mov 33h, #4
mov 34h, #5
mov 35h, #6
mov 36h, #7
mov 37h, #8
mov 38h, #9
mov 39h, #10
call SQRT
sjmp $
;查表法求平方的程序如下。
SQRT:
MOV R0, #30H
MOV R1, #40H
MOV R2, #10
LOOP:
MOV A, @R0 ;1 byte
ADD A, #S_TAB - ($ + 4) ;2byte
MOVC A, @A + PC ;1byte
MOV @R1, A ;1byte
INC R0 ;1byte
INC R1 ;1byte
DJNZ R2, LOOP ;2byte
RET ;1byte
S_TAB:
DB 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
end