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

Safe Division

Divides the value at register R0 by the value at register R1. The quotient is stored in R0 and the remainder in R1. The value of the B register remains unchanged.

; +-----------------------------------------------------------------+
; | subroutine: SAFE_DIV |
; | 8-Bit / 8-Bit to 8-Bit Quotient & Remainder Unsigned Divide |
; | |
; | input: R00 = Dividend X |
; | R01 = Divisor Y |
; | |
; | output: R00 = quotient Q of division ( Q = X / Y ) |
; | R01 = remainder R of division ( R = X % Y ) |
; | |
; | alters: Carry Flag (C) |
; | |
; | notes: If division by zero is attempted nothing happens |
; | and the Overflow Flag (OV) is not altered. |
; +-----------------------------------------------------------------+
SAFE_DIV:
JZ
R01
SADI_END
; Avoid division by zero
PUSH
B
; Save contents of B register
DIV
R00
R01
MOV
R01
B
POP
B
; Restore B register to previous value
SADI_END:
RET
Introduction | About Doc Bot | Site Map | Search | Use License | Contact Us
©2009 Daniel Julivert