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
完
0-9循环显示,经验证完全无误。。谢谢采纳。
ORG 0000H
MOV DPTR,#TAB DPTR此时指向0C0H,以后由于A值的不停加1会不停的往后指,在循环
MAIN:MOV R5,#0 给初值
MOV A,R5A=0
LP: MOVC A,@A+DPTR 查表
MOV P1,A显示
MOV A,R5
INC A 加1
MOV R5,A
LCALL DELAY 延时
CJNE A,#10,LP 是否 到9.
SJMP MAIN
DELAY:MOV R3,#255
DEL1: MOV R4,#255
DEL2: NOP
DJNZ R4,DEL2
DJNZ R3,DEL1
RET
TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H共阳字符。0-9。
END 如有疑问,可以HI我。。
用数组来解决最简单方便,自己参考一下吧#include <stdio.h>
int main()
{
char ch
int i,j,BQ
char * k1[3][4]={
{"0","0.1","0.2-0.3" ,"0.4-0.6"} ,
{"0.1" ,"0.2-0.3","0.4-0.6","0.7-0.9"} ,
{"0.2","0.4-0.6","0.7-0.9","1.0"} ,
}
printf("0-潮湿或点滴状出水\n" )
printf("1-淋雨状或涌流状出水,水压<=0.1MPa或单位出水量<=10L/min\n")
printf("2-淋雨状或涌流状出水,水压>0.1MPa或单位出水量>10L/min\n")
printf("请选择地下水状态[0-2]:")
do {
scanf("%c",&ch )getchar()
} while ( ch >'2' || ch<'0' )
i=ch-'0'
printf("请输入BQ值:")
scanf("%d" , &BQ )
if ( BQ >450 ) j=0 //题目中写的有问题,应该是>450,不是451
else if ( BQ >350 ) j=1
else if ( BQ >250 ) j=2
else j=3
printf("K1=%s\n" , k1[i][j] )
system("pause")
return 0
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)