fork download
  1. LIST P = 16F877
  2. #INCLUDE <P16F877.INC>
  3.  
  4. ; Define memory locations for the numbers
  5. Num1 EQU 0x20 ; Memory location for Num1
  6. Num2 EQU 0x21 ; Memory location for Num2
  7. Num3 EQU 0x22 ; Memory location for Num3
  8. Largest EQU 0x23 ; Memory location for Largest
  9. Smallest EQU 0x24 ; Memory location for Smallest
  10. Second_Largest EQU 0x25 ; Memory location for Second Largest
  11.  
  12. ORG 0x00 ; Origin - starting address of the program
  13.  
  14. ; Initialize values for the numbers
  15. MOVLW 0x01 ; Load WREG with the first number (1)
  16. MOVWF Num1 ; Store it in Num1
  17.  
  18. MOVLW 0x03 ; Load WREG with the second number (3)
  19. MOVWF Num2 ; Store it in Num2
  20.  
  21. MOVLW 0x05 ; Load WREG with the third number (5)
  22. MOVWF Num3 ; Store it in Num3
  23.  
  24. ; Initialize Largest and Smallest
  25. MOVF Num1, WREG ; Load WREG with Num1
  26. MOVWF Largest ; Assume Num1 is Largest initially
  27. MOVWF Smallest ; Assume Num1 is Smallest initially
  28.  
  29. ; Initialize Second Largest to 0
  30. MOVLW 0x00
  31. MOVWF Second_Largest ; Initialize Second Largest to 0
  32.  
  33. ; Compare Num2
  34. MOVF Num2, WREG ; Move Num2 into WREG
  35.  
  36. ; Check if Num2 is greater than Largest
  37. CPFSLT Largest ; If Num2 > Largest, skip next line
  38. GOTO UpdateLargestNum2
  39.  
  40. ; Check if Num2 is less than Smallest
  41. CPFSGT Smallest ; If Num2 < Smallest, skip next line
  42. GOTO UpdateSmallestNum2
  43.  
  44. ; Check if Num2 is the second largest
  45. MOVF Num2, WREG ; Move Num2 into WREG
  46. CPFSLT Second_Largest ; If Num2 < Second_Largest, skip
  47. GOTO UpdateSecondLargestNum2
  48. GOTO NextNumber
  49.  
  50. UpdateLargestNum2:
  51. MOVF Num2, WREG ; Move Num2 into WREG
  52. MOVWF Largest ; Update Largest
  53. GOTO NextNumber
  54.  
  55. UpdateSmallestNum2:
  56. MOVF Num2, WREG ; Move Num2 into WREG
  57. MOVWF Smallest ; Update Smallest
  58. GOTO NextNumber
  59.  
  60. UpdateSecondLargestNum2:
  61. MOVF Num2, WREG ; Move Num2 into WREG
  62. MOVWF Second_Largest ; Update Second Largest
  63. GOTO NextNumber
  64.  
  65. NextNumber:
  66. ; Compare with Num3
  67. MOVF Num3, WREG ; Move Num3 into WREG
  68.  
  69. ; Check if Num3 is greater than Largest
  70. CPFSLT Largest ; If Num3 > Largest, skip next line
  71. GOTO UpdateLargestNum3
  72.  
  73. ; Check if Num3 is less than Smallest
  74. CPFSGT Smallest ; If Num3 < Smallest, skip next line
  75. GOTO UpdateSmallestNum3
  76.  
  77. ; Check if Num3 is the second largest
  78. MOVF Num3, WREG
  79. CPFSLT Second_Largest ; If Num3 < Second_Largest, skip
  80. GOTO UpdateSecondLargestNum3
  81.  
  82. GOTO Final ; Go to final processing
  83.  
  84. UpdateLargestNum3:
  85. MOVF Num3, WREG ; Move Num3 into WREG
  86. MOVWF Largest ; Update Largest
  87. GOTO NextNumber
  88.  
  89. UpdateSmallestNum3:
  90. MOVF Num3, WREG ; Move Num3 into WREG
  91. MOVWF Smallest ; Update Smallest
  92. GOTO NextNumber
  93.  
  94. UpdateSecondLargestNum3:
  95. MOVF Num3, WREG
  96. MOVWF Second_Largest ; Update Second Largest
  97. GOTO NextNumber
  98.  
  99. Final:
  100. ; Final processing: At this point, Largest, Smallest, and Second_Largest hold the results
  101. ; Here you can include code to store results, output to display, etc.
  102.  
  103. ; End of program
  104.  
Success #stdin #stdout 0.02s 25528KB
stdin
Standard input is empty
stdout
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