; square root of a given number 8bit
; input: 4000H
; output: 4001H
ORG 0H
IN_ADDR EQU 4000H
OUT_ADDR EQU 4001H
MAIN:
MOV DPTR,#IN_ADDR ; fill memory
MOV A,#09
MOVX @DPTR,A
LCALL SQUAREROOT
SJMP MAIN
SQUAREROOT:
MOV DPTR,#IN_ADDR
MOVX A,@DPTR
MOV R1,A
MOV R2,#01
loop: MOV A,R1
MOV B,R2
DIV AB
MOV R3,A
MOV R4,B
SUBB A,R2
JZ result
INC R2
SJMP loop
result: MOV DPTR,#OUT_ADDR
MOV A,R3
MOVX @DPTR,A
RET
END
Related topics:
8051 Program - search an element in an array | 8051 Program - search a byte in array and count match | 8051 Program - square of a given number 8bit | 8051 Program - square and cube operation | 8051 Program - count number of ones in a byte | 8051 Program - count 0 and 1 in a byte | 8051 Program - memory subroutines | 8051 Program - math subroutines | 8051 Program - conversion subroutines
List of topics: 8051
No comments:
Post a Comment