某场歌手赛,共有10个评委,试编写一程序,输入10个评分,去掉最高分和最低分,求平均分(均为BCD码)。
正确答案:
O.RG 0H
N.EQU #5
B.LOCK EQU #30H
I.SELSORT: MOV R7,N
D.EC R7
M.OV R1,BLOCK
I.SST1: MOV R0,BLOCK
M.OV A,R7
M.OV R6,A
M.OV A,@R0
M.OV B,A
I.SST2: INC R1
M.OV A,@R1
C.LR C
S.UBB A,B
J.C ISST3
M.OV A,@R1
M.OV R2,A
M.OV B,@R1
I.SST3: DJNZ R6,ISST2
M.OV A,B
X.CH A,@R1
M.OV B,R2
M.OV @R1,B MOV @R1,A
D.JNZ R7,ISST1
M.OV R0,BLOCK
M.OV @R0,#0 ;去掉最低分
M.OV A,BLOCK
ADD A,#9
MOV R0,A
MOV @R0,#0 ;去掉最高分
AD: MOV R0,BLOCK
INC RO
MOV R1,#8
CLR A
CLR C
MOV B,#0
ADL: ADD A,@R0
DA A
MOV R2,A
ADDC A,#0
MOV B,A
MOV A,R2
DJNZ R1,ADL
MOV R5,0
MOV R4,B
MOV R3,A
MOV R2,#0
MOV R1,#8
R5R4R3/R2R1 = R4R3
MOV R1,#00H
MOV R2,#0FH
MOV R3,#04H
MOV R4,#05H
MOV R5,#06H
LCALL _DIV
AJMP $
_DIV: ;{
CLR C
MOV 30H,#0
MOV 31H,#0
MOV 32H,#0
_DIV_LOOP: CLR C
MOV A,R3
SUBB A,R1
MOV R3,A
MOV A,R4
SUBB A,R2
MOV R4,A
MOV A,R5
SUBB A,#0
MOV R5,A
JC _DIV_END
_INC_SHANG: CLR C
MOV A,30H
ADDC A,#1
MOV 30H,A
MOV A,31H
ADDC A,#0
MOV 31H,A
MOV A,32H
ADDC A,#0
MOV 32H,A
LJMP _DIV_LOOP
_DIV_END: CLR C
MOV A,R1
ADDC A,R3
MOV A,R2
ADDC A,R4
MOV R3,30H
MOV R4,31H
END
N.EQU #5
B.LOCK EQU #30H
I.SELSORT: MOV R7,N
D.EC R7
M.OV R1,BLOCK
I.SST1: MOV R0,BLOCK
M.OV A,R7
M.OV R6,A
M.OV A,@R0
M.OV B,A
I.SST2: INC R1
M.OV A,@R1
C.LR C
S.UBB A,B
J.C ISST3
M.OV A,@R1
M.OV R2,A
M.OV B,@R1
I.SST3: DJNZ R6,ISST2
M.OV A,B
X.CH A,@R1
M.OV B,R2
M.OV @R1,B MOV @R1,A
D.JNZ R7,ISST1
M.OV R0,BLOCK
M.OV @R0,#0 ;去掉最低分
M.OV A,BLOCK
ADD A,#9
MOV R0,A
MOV @R0,#0 ;去掉最高分
AD: MOV R0,BLOCK
INC RO
MOV R1,#8
CLR A
CLR C
MOV B,#0
ADL: ADD A,@R0
DA A
MOV R2,A
ADDC A,#0
MOV B,A
MOV A,R2
DJNZ R1,ADL
MOV R5,0
MOV R4,B
MOV R3,A
MOV R2,#0
MOV R1,#8
R5R4R3/R2R1 = R4R3
MOV R1,#00H
MOV R2,#0FH
MOV R3,#04H
MOV R4,#05H
MOV R5,#06H
LCALL _DIV
AJMP $
_DIV: ;{
CLR C
MOV 30H,#0
MOV 31H,#0
MOV 32H,#0
_DIV_LOOP: CLR C
MOV A,R3
SUBB A,R1
MOV R3,A
MOV A,R4
SUBB A,R2
MOV R4,A
MOV A,R5
SUBB A,#0
MOV R5,A
JC _DIV_END
_INC_SHANG: CLR C
MOV A,30H
ADDC A,#1
MOV 30H,A
MOV A,31H
ADDC A,#0
MOV 31H,A
MOV A,32H
ADDC A,#0
MOV 32H,A
LJMP _DIV_LOOP
_DIV_END: CLR C
MOV A,R1
ADDC A,R3
MOV A,R2
ADDC A,R4
MOV R3,30H
MOV R4,31H
END
答案解析:有
微信扫一扫手机做题