Saturday, April 30, 2016

8051 Program – square of a given number 8bit

; square of a given number 8bit
; input: 4000H
; output: 4001H-4002H
ORG 0H
DATA_ADDR EQU 4000H
MAIN:
MOV DPTR,#DATA_ADDR ; fill memory
MOV A,#25
MOVX @DPTR,A
LCALL SQUARE
SJMP MAIN
SQUARE:
MOV DPTR,#DATA_ADDR ;load dptr with:DATA_ADDR
MOVX A,@DPTR ;move data from external memory location to a
MOV B,A ;move data from a to b
MUL AB ;multiply and b
INC DPTR ;increment dptr
MOV R0,A ;move data from a to r0
MOV A,B ;move data from b to a
MOVX @DPTR,A ;move data from a to external memory location
INC DPTR ;increment dptr
MOV A,R0 ;move data from r0 to a
MOVX @DPTR,A ;move data from a to external memory location
return:
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 root 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