3.15 设累加器A的各位ACC。0~ACC. 7分别记为X0~X7,编制程序用软件实现
:
解:
X0 BIT ACC.0 ANL C,X1 ANL C,01H X1 BIT ACC.1 ANL C,X2 ANL C,X3 X2 BIT ACC.2 MOV 00H,C ORL C,/00H
X3 BIT ACC.3 MOV C,X0 MOV 00H,C X4 BIT ACC.4 ANL C,/X1 MOV C,X7 X5 BIT ACC.5 MOV 01H,C ANL C,/X6 X6 BIT ACC.6 ANL C,/X2 ANL C,X5 X7 BIT ACC.7 ORL C,00H ANL C,/X4 ORG 0000H MOV 00H,C ORL C,00H MOV C,X0 MOV C,X2 SJMP $
3.16用程序实现c=a2+b2,设a,b均小于10。a存放在31H单元,b存放在32H单元,把c存入34H和33H单元(要求BCD码) 解:主程序: ORG 0000H MOV A,32H MOV A,#0 MOV SP,#3FH LCALL SQR ADDC A,#0 MOV A,31H ADD A,R1 MOV 34H,A LCALL SQR DA A SJMP $ MOV R1,A MOV 33H,A 子程序:
ORG 0030H SQR: INC A
MOVC A,@A+PC RET
TAB: DB 00H,01H,04H,09H,16H,25H,36H,49H,64H,81H END
例3.17求两个无符号数据块中的最大值的乘积。数据块的首地址分别为60H和70H,每个数据块的第一个字节都存放数据块长度,结果存入5FH和5EH单元中。 解:主程序:
ORG 0000H ACALL QMAX
MOV R1 , # 60H MUL AB ACALL QMAX MOV 5EH , A MOV B , A MOV 5FH , B MOV R1 , # 70H SJMP $ 子程序:
ORG 0000H CLR C LP3: ADD A , @R1
QMAX: MOV A @R1 SUBB A , @R1 LP4: DJNZ R2 , LP1 MOV R2 , A JNC LP3 RET CLR A END MOV A , @R1 LP1: INC R1 SJMP LP4