一个小作业。
找出最大值和最小值,然后相乘。
我使用if-else语句实现。
Min EQU 50H
Max EQU 51H
ORG 0H
START:
MOV 40H, #24 ; 16 numbers from address 40H
MOV 41H, #2
MOV 42H, #63
MOV 43H, #11
MOV 44H, #28
MOV 45H, #8
MOV 46H, #9
MOV 47H, #14
MOV 48H, #16
MOV 49H, #35
MOV 4AH, #54
MOV 4BH, #13
MOV 4CH, #6
MOV 4DH, #17
MOV 4EH, #32
MOV 4FH, #25
MOV R0, #41H ; the pointer to travel in the array
MOV Max, 40H ; begin from the first number
MOV Min, 40H
MOV R2, #15 ; the number to control loop, 15 times
LP1:
MOV A, @R0
CJNE A, Max, NEXT1 ; compare A with Max
NEXT1:
JC NEXT2 ; if A < Max, then go to NEXT2
MOV Max, A ; if A >= Max, then MAX = A
INC R0 ; Move to the last number by one step
SJMP LP2 ; end one loop
NEXT2:
CJNE A, Min, NEXT3 ; compare A with Min
NEXT3:
JNC LP2 ; if A >= Min, then back to the loop
MOV Min, A ; if A < Min, them Min = A
INC R0
SJMP LP2
LP2:
DJNZ R2, LP1 ; control loop times, 15 times totally
MULTI:
MOV A, Min
MOV B, Max
MUL AB
MOV 52H, A
MOV 53H, B
END ; Min is 2, Max is 63, Min*Max is 126, after run this project, register A is 0x7e = 126, because it save
; Low 8 bits, and register B is 0x00, beacause it save High 8 bits.