Doc Bot

Download | Tutorials | Instruction Set | Hardware Reference
Introduction | About Doc Bot | Site Map | Search | Use License | Contact Us
Download
Screenshots
Table Of Contents | Addressing Modes | Memory Model | External Ports | Instruction Set | Hardware Reference | Turn Cycles | File format
Table Of Contents | Introduction | Types Of Memory | Special Function Registers | Basic Registers | Addressing Modes | Program Flow | Timers | External Ports | Interrupts | Power Control Modes | Hardware Components
Table Of Contents | Calculate Square Roots | Safe Division

Code Library

small logo

Calculate Square Roots

Find out the square root of the 16-bit number.

; +-----------------------------------------------------------------+
; | Purpose: Find out the square root of the 16-bit number |
; | 8-Bit version by Joao Dartagnan Antunes Oliveira (04/20/1993) |
; | 16-Bit modification by Bruno Marcio Diogo Venancio (08/10/2007) |
; | Email: bruno.marcio@bol.com.br |
; | Brazil v1.1 |
; | Input: B (MSB) and A (LSB) (binary) |
; | Output: A |
; | Destroy : R02,R03,R04,R05,R06,R07 |
; | THIS CODE CAN BE FREELY DISTRIBUTED WITHOUT CHANGES |
; +-----------------------------------------------------------------+
;
COUNT_L:
EQU
R02
COUNT_H:
EQU
R03
ACC_L:
EQU
R04
ACC_H:
EQU
R05
X_L:
EQU
R06
X_H:
EQU
R07
ORG
#0x0000
;
; Test Routine
;
LOOP:
MOV
A
#0x4000
MOV
B
#0x4000
CALL
SQRTBI
; SQRT(40000)=200
SJMP
$LOOP
;
; METHOD:
;
; Add in one accumulator an odd number counter until it cotains a value great or
; equal than X , at this moment, the counter value divided for 2 will be SQRT(X)
;
SQRTBI:
MOV
X_L
A
MOV
X_H
B
MOV
COUNT_L
#0x0001
; COUNTER <- 1
MOV
COUNT_H
#0x0000
MOV
ACC_L
#0x0000
; ACUMULATOR <- 0
MOV
ACC_H
#0x0000
RET
Introduction | About Doc Bot | Site Map | Search | Use License | Contact Us
©2009 Daniel Julivert