; square and cube operations
; input at 9000H
; result at locations 9001H, 9002H, 9003H
ORG 0H
SJMP 30H
ORG 30H
MOV DPTR,#9000H
MOVX A,@DPTR ;get number-x
MOV R0,A ;store in r0
MOV B,A
MUL AB ;square it-x^2
CLR C ;for storing result
JB 01,LAST ;if bit 01 is set then end, else do cube
PUSH B ;store upper part of square
MOV B,A ;b-lower part of x^2
MOV A,R0 ;a-x
MUL AB ;x*lower x^2
INC DPTR
MOVX @DPTR,A ;store partial result
MOV A,B
MOV R2,A ;upper part of x*lower x^2 in r2
POP B ;get back upper part of square
MOV A,R0 ;a-x
MUL AB ;x*upper x^2
ADD A,R2 ;add to partial result
LAST: INC DPTR
MOVX @DPTR,A
MOV A,B
ADDC A,#00 ;add carry to b(for square result, c=0)
INC DPTR
MOVX @DPTR,A
HERE: SJMP HERE
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 root of a given number 8bit | 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