×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library

Integer DIV routine

Submitted by Steve Fewell

Routine: iDIV
Name: Integer DIV routine
Starting Address: &9FFD
Entry criteria: Either IWA or FWA contain the dividend. A contains the variable type (Floating-Point/Integer). The Basic Text Pointer 2 points to an expression (the divisor) [e.g. " A%"]
Exit: The IWA.= Quotient (Result, IWA = IWA / Divisor-expression).

Description:
Call the Integer Division routine to evaluate the Divisor-expression and perform the actual division.

Multiply the Result by the base (Base 2 - Binary) and add on any value needing to be added to the result. This is not done by the Integer Division routine due to time constraints, as the MOD routine does not need to perform these tasks in order to obtain its required remainder.

Push the sign-bit of the result to the 6502 stack, load X with &39 (to specify where the result is located), and call the end of the Integer multiplication routine to put the Result into the IWA, convert it to the correct sign, and to check the next operator to see if any further multiplication/division processing is required.

 

Disassembly for the Integer DIV routine

9FFD   032 249 128 20 F9 80 JSR &80F9    Integer Division
A000 &9 038 057 26 39 ROL &39
A002 &: 038 058 26 3A ROL &3A
A004 &; 038 059 26 3B ROL &3B
A006 &< 038 060 26 3C ROL &3C
A008 $7 036 055 24 37 BIT &37
A00A   008 08 PHP
A00B 9 162 057 A2 39 LDX#&39
A00D   128 165 80 A5 BRA -91 --> &9FB4    Get Result from Zero Page & check next operator in expression

 


 Back to 8BS
Or