PIC16F877 program to find the square root of a given number
Write an assembly level program for PIC16F877 to find the square root of a given number.
Method: successive subtraction of odd numbers. ROOT increments while NUM ≥ (2·ROOT+1). ROOT holds ⌊√NUM⌋.
; Integer Square Root for 8‑bit NUM on PIC16F877
LIST P=16F877
INCLUDE <P16F877.INC>
__CONFIG _HS_OSC & _WDT_OFF & _PWRTE_ON & _LVP_OFF
CBLOCK 0x20
NUM ; input
ROOT ; result
TEMP
ENDC
ORG 0x0000
GOTO START
START:
MOVLW .100
MOVWF NUM
CLRF ROOT
LOOP_SQRT:
MOVF ROOT, W ; W=ROOT
ADDWF ROOT, W ; W=2*ROOT
ADDLW 1 ; W=2*ROOT+1
MOVWF TEMP
MOVF NUM, W
SUBWF TEMP, W ; if NUM < TEMP -> done
BTFSS STATUS, C
GOTO DONE
MOVF TEMP, W
SUBWF NUM, F ; NUM -= TEMP
INCF ROOT, F
GOTO LOOP_SQRT
DONE:
; ROOT = floor(sqrt(NUM))
END
Join EEE Made Easy Telegram channel
Join EEE Made Easy Whatsapp Channel
Download & Install EEE Made Easy App
Books for Microcontroller 8051
- KSEB Sub Engineer and AE Books
- The 8051 Micro controller 3rd Edition,by Kenneth Ayala
- The 8051 Microcontrollers & Embedded Systems, by Mazidi
- 8051 MICROCONTROLLER AND APPLICATIONS FOR BSC
- Microcontroller & Embedded Systems for BE
More on Microcontrollers
- Features of AVR|AVR Microcontrollers
- 8051 ARCHITECTURE|8051 Microcontroller Architecture
- 8051 Microcontroller Architecture|RISC and CISC CPU Architectures|HARVARD & VON- NEUMANN CPU Architecture
- Microprocessor VS Microcontroller| Comparison of Microprocessor and Microcontroller|Difference between Microprocessor and Microcontroller
- Addressing modes of 8051 Microcontroller|8051 Addressing Modes
- 8051 Microcontroller Instruction Set|KSEB Sub Engineer Notes
- 8051 Microcontroller MCQ|8051 Questions and Answers
- Microcontroller|Types of microcontroller
- 8051 Microcontroller Notes pdf|8051 microcontroller pdf
- Interrupts in 8051|Interrupts in 8051 Microcontroller
8051 microcontroller trainer kit
8051 microcontroller trainer kit
Latest Posts in EEE Made Easy
- Energy Efficient Lamps|CFL, LED lampsEnergy Efficient Lamps: CFL (Compact Fluorescent lamp ) and LED (light emitting diodes) lamp are Energy Efficient Lamps. Energy Efficient … Read more
- [New] AE KWA Kerala PSC 2026AE KWA Kerala PSC 2026: DETAILED SYLLABUS FOR SELECTION TO THE POST OF ASSISTANT ENGINEER IN KERALA WATER AUTHOERITY AE … Read more
- [New] Electricity Worker KSEB Syllabus 2026|021/2026 Syllabus Kerala PSCElectricity Worker KSEB Syllabus 2026- 021/2026 Syllabus Kerala PSC: DETAILED SYLLABUS FOR THE POST OF ELECTRICITY WORKER IN KERALASTATE ELECTRICITY … Read more
- [Latest]KWA Operator Syllabus 2026|734,735/2025 Kerala PSC syllabusKWA Operator Syllabus 2026 – 734,735/2025 Kerala PSC syllabus: KERALA PUBLIC SERVICE COMMISSIONDETAILED SYLLABUS FOR THE POST OF OPERATOR (DIRECT) … Read more
- [New]Inspector of Legal Metrology Syllabus|613/2025 Kerala PSC SyllabusInspector of Legal Metrology Syllabus– 613/2025 Kerala PSC Syllabus: DETAILED SYLLABUS FOR THE POST OF INSPECTOR OF LEGAL METROLOGY IN … Read more
- [PDF]IE Rules|Indian Electricity Rules 1956IE Rules:The Indian Electricity Rules 1956 was made under section 37 of the Indian Electricity Act, 1910 and redefined after … Read more
- [Latest]Syllabus Sub Engineer LSGD Electricity Wing Thrissur Corporation| 770/2025 Syllabus Kerala PSCSyllabus Sub Engineer LSGD Electricity Wing Thrissur Corporation: DETAILED SYLLABUS FOR THE POST OF SUB ENGINEER IN LSGD(ELECTRICITY WING OF … Read more

