LIST P = 16F877 #INCLUDE <P16F877.INC> Num1 EQU 0x20 ; Memory location for Num1 Num2 EQU 0x21 ; Memory location for Num2 Num3 EQU 0x22 ; Memory location for Num3 Largest EQU 0x23 ; Memory location for Largest Smallest EQU 0x24 ; Memory location for Smallest Second_Largest EQU 0x25 ; Memory location for Second Largest ORG 0x00 ; Origin - starting address of the program ; Initialize values for the numbers MOVLW 0x01 ; Load WREG with the first number (1) MOVWF Num1 ; Store it in Num1 MOVLW 0x03 ; Load WREG with the second number (3) MOVWF Num2 ; Store it in Num2 MOVLW 0x05 ; Load WREG with the third number (5) MOVWF Num3 ; Store it in Num3 ; Initialize Largest and Smallest MOVF Num1, WREG ; Load WREG with Num1 MOVWF Largest ; Assume Num1 is Largest initially MOVWF Smallest ; Assume Num1 is Smallest initially ; Initialize Second Largest to 0 MOVLW 0x00 MOVWF Second_Largest ; Initialize Second Largest to 0 ; Compare Num2 MOVF Num2, WREG ; Move Num2 into WREG ; Check if Num2 is greater than Largest GOTO UpdateLargestNum2 ; Check if Num2 is less than Smallest GOTO UpdateSmallestNum2 ; Check if Num2 is the second largest MOVF Num2, WREG ; Move Num2 into WREG CPFSLT Second_Largest ; If Num2 < Second_Largest, skip GOTO UpdateSecondLargestNum2 GOTO NextNumber UpdateLargestNum2: MOVF Num2, WREG ; Move Num2 into WREG MOVWF Largest ; Update Largest GOTO NextNumber UpdateSmallestNum2: MOVF Num2, WREG ; Move Num2 into WREG MOVWF Smallest ; Update Smallest GOTO NextNumber UpdateSecondLargestNum2: MOVF Num2, WREG ; Move Num2 into WREG MOVWF Second_Largest ; Update Second Largest GOTO NextNumber NextNumber: ; Compare with Num3 MOVF Num3, WREG ; Move Num3 into WREG ; Check if Num3 is greater than Largest GOTO UpdateLargestNum3 ; Check if Num3 is less than Smallest GOTO UpdateSmallestNum3 ; Check if Num3 is the second largest MOVF Num3, WREG CPFSLT Second_Largest ; If Num3 < Second_Largest, skip GOTO UpdateSecondLargestNum3 GOTO Final ; Go to final processing UpdateLargestNum3: MOVF Num3, WREG ; Move Num3 into WREG MOVWF Largest ; Update Largest GOTO NextNumber UpdateSmallestNum3: MOVF Num3, WREG ; Move Num3 into WREG MOVWF Smallest ; Update Smallest GOTO NextNumber UpdateSecondLargestNum3: MOVF Num3, WREG MOVWF Second_Largest ; Update Second Largest GOTO NextNumber Final: ; Final processing: At this point, Largest, Smallest, and Second_Largest hold the results ; Here you can include code to store results, output to display, etc. End: ; End of program
Standard input is empty
LIST P = 16F877
#INCLUDE <P16F877.INC>
; Define memory locations for the numbers
Num1 EQU 0x20 ; Memory location for Num1
Num2 EQU 0x21 ; Memory location for Num2
Num3 EQU 0x22 ; Memory location for Num3
Largest EQU 0x23 ; Memory location for Largest
Smallest EQU 0x24 ; Memory location for Smallest
Second_Largest EQU 0x25 ; Memory location for Second Largest
ORG 0x00 ; Origin - starting address of the program
; Initialize values for the numbers
MOVLW 0x01 ; Load WREG with the first number (1)
MOVWF Num1 ; Store it in Num1
MOVLW 0x03 ; Load WREG with the second number (3)
MOVWF Num2 ; Store it in Num2
MOVLW 0x05 ; Load WREG with the third number (5)
MOVWF Num3 ; Store it in Num3
; Initialize Largest and Smallest
MOVF Num1, WREG ; Load WREG with Num1
MOVWF Largest ; Assume Num1 is Largest initially
MOVWF Smallest ; Assume Num1 is Smallest initially
; Initialize Second Largest to 0
MOVLW 0x00
MOVWF Second_Largest ; Initialize Second Largest to 0
; Compare Num2
MOVF Num2, WREG ; Move Num2 into WREG
; Check if Num2 is greater than Largest
CPFSLT Largest ; If Num2 > Largest, skip next line
GOTO UpdateLargestNum2
; Check if Num2 is less than Smallest
CPFSGT Smallest ; If Num2 < Smallest, skip next line
GOTO UpdateSmallestNum2
; Check if Num2 is the second largest
MOVF Num2, WREG ; Move Num2 into WREG
CPFSLT Second_Largest ; If Num2 < Second_Largest, skip
GOTO UpdateSecondLargestNum2
GOTO NextNumber
UpdateLargestNum2:
MOVF Num2, WREG ; Move Num2 into WREG
MOVWF Largest ; Update Largest
GOTO NextNumber
UpdateSmallestNum2:
MOVF Num2, WREG ; Move Num2 into WREG
MOVWF Smallest ; Update Smallest
GOTO NextNumber
UpdateSecondLargestNum2:
MOVF Num2, WREG ; Move Num2 into WREG
MOVWF Second_Largest ; Update Second Largest
GOTO NextNumber
NextNumber:
; Compare with Num3
MOVF Num3, WREG ; Move Num3 into WREG
; Check if Num3 is greater than Largest
CPFSLT Largest ; If Num3 > Largest, skip next line
GOTO UpdateLargestNum3
; Check if Num3 is less than Smallest
CPFSGT Smallest ; If Num3 < Smallest, skip next line
GOTO UpdateSmallestNum3
; Check if Num3 is the second largest
MOVF Num3, WREG
CPFSLT Second_Largest ; If Num3 < Second_Largest, skip
GOTO UpdateSecondLargestNum3
GOTO Final ; Go to final processing
UpdateLargestNum3:
MOVF Num3, WREG ; Move Num3 into WREG
MOVWF Largest ; Update Largest
GOTO NextNumber
UpdateSmallestNum3:
MOVF Num3, WREG ; Move Num3 into WREG
MOVWF Smallest ; Update Smallest
GOTO NextNumber
UpdateSecondLargestNum3:
MOVF Num3, WREG
MOVWF Second_Largest ; Update Second Largest
GOTO NextNumber
Final:
; Final processing: At this point, Largest, Smallest, and Second_Largest hold the results
; Here you can include code to store results, output to display, etc.
End:
; End of program
END