mov 30h, #1
mov 31h, #3
mov 32h, #5
mov 33h, #7
mov 34h, #9
mov 35h, #2
mov 36h, #4
mov 37h, #6
mov 38h, #8
mov 39h, #10
call SQRT
sjmp $
查表法求平方的程序如下。
SQRT:
MOV R0, #30H
MOV R1, #40H
MOV R2, #10
LOOP:
MOV A, @R0
ADD A, #S_TAB - ($ + 4)
MOVC A, @A + PC
MOV @R1, A
INC R0
INC R1
DJNZ R2, LOOP
RET
S_TAB:
DB 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
完
ORG 1000HMOV DPTR,#2100H
LP0: MOVX A,@DPTR
CJNE A,#41H,LP1
MOV R0,DPL
MOV R1,DPH
MOV DPTR,#21A0H
MOV A,R0
MOVX @DPTR,A
INC DPTR
MOV A,R1
MOVX @DPTR,A
SJMP LP3
LP1: CJNE A,#0FFH,LP2
MOV DPTR,#21A0H
MOV A,#0FFH
MOVX @DPTR,A
INC DPTR
MOVX @DPTR,A
INC DPTR
SJMP LP3
LP2: INC DPTR
SJMP LP0
LP3: SJMP $
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)