home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
SIMTEL
/
CPMUG
/
CPMUG018.ARK
/
FPCONV.ASM
< prev
next >
Wrap
Assembly Source File
|
1984-04-29
|
18KB
|
599 lines
;
; 8008 BINARY FLOATING POINT SYSTEM
;
; FORMAT CONVERSION PACKAGE
;
;
; THE FORMAT CONVERSION PACKAGE OF THE 8008 BINARY FLOATING
; POINT SYSTEM CONTAINS SUBROUTINES FOR THE CONVERSION OF
; DATA BETWEEN THE FLOATING POINT SYSTEM NOTATION AND TWO OTHER
; FORMATS. THE NON-FLOATING-POINT FORMATS ARE: FOUR WORD FIXED
; POINT FORMAT AND VARIABLE LENGTH CHARACTER STRING FORMAT.
;
; THE FORMAT CONVERSION PACKAGE IS CONTAINED IN 512 CONSECUTIVE
; WORDS OF MEMORY (2 BANKS OF ROM) AND REQUIRES FOR ITS
; EXECUTION THAT THE ARITHMETIC AND UTILITY PACKAGE BE
; AVAILABLE IN MEMORY. THE COMBINATION OF THIS PACKAGE AND THE
; ARITHMETIC AND UTILITY PACKAGE USES THE FIRST 64 WORDS
; OF A BANK OF RAM AS SCRATCHPAD MEMORY.
;
;
; THE FIXED POINT FORMAT DATA PROCESSED BY THIS PACKAGE
; CONSIST OF 32 BIT BINARY NUMBERS OCCUPYING FOUR WORDS.
; 2'S COMPLEMENT NOTATION IS USED TO REPRESENT NEGATIVE
; VALUES.
; THE POSITION OF THE BINARY POINT RELATIVE TO THE
; BITS REPRESENTING THE VALUE IS DENOTED BY A BINARY
; SCALING FACTOR. THE BINARY SCALING FACTOR IS NOT NORMALLY
; RECORDED IN THE COMPUTER, BUT WHEN A FORMAT CONVERSION
; SUBROUTINE IS CALLED, THE BINARY SCALING FACTOR MUST BE
; SPECIFIED (IN THE E REGISTER). A BINARY SCALING FACTOR OF
; ZERO INDICATES THAT THE BINARY POINT IS IMMEDIATELY TO THE
; LEFT OF THE MOST SIGNIFICANT OF THE 32 BITS REPRESENTING THE
; VALUE. A BINARY SCALING FACTOR OF 32 INDICATES THAT THE BINARY
; POINT IS IMMEDIATELY TO THE RIGHT OF THE LEAST SIGNIFICANT
; BIT. THE PERMISSIBLE RANGE OF THE BINARY SCALING FACTOR IS
; -128 (200 OCTAL) TO +127 (177 OCTAL).
;
;
; THE CHARACTER STRING FORMAT DATA PROCESSED BY THIS PACKAGE
; CONSIST OF BINARY REPRESENTATIONS OF CHARACTERS OCCUPYING
; CONSECUTIVE WORDS OF MEMORY. A CHARACTER STRING MAY NOT
; CROSS A MEMORY BANK BOUNDARY. THE CHARACTERS WHICH MAY BE
; INCLUDED IN A CHARACTER STRING, AND THE CORRESPONDING
; OCTAL REPRESENTATIONS ARE LISTED BELOW.
;
; DECIMAL DIGITS 000B-011B BCD DIGITS
; SPACE 360B
; + 373B PLUS
; - 375B MINUS
; . 376B DECIMAL POINT
; E 25QB EXPONENTIAL SIGN
; (THESE OCTAL REPRESENTATIONS CAN BE CONVERTED TO THE
; CORRESPONDING ASCII CHARACTERS BY ADDING 60 OCTAL TO EACH
;
; THE OUT SUBROUTINE GENERATES CHARACTER STRINGS IN TWO
; FORMATS, EACH CONSISTING OF 13 CHARACTERS. THE FORMAT
; USED IN A SPECIFIC CASE IS DEPENDENT ON THE MAGNITUDE
; OF THE VALUE REPRESENTED.
; ZERO AND MAGNITUDES BETWEEN .1000000 AND 9999999. ARE
; REPRESENTED BY A SPACE OR MINUS SIGN, SEVEN DECIMAL DIGITS,
; AN APPROPRIATELY POSITIONED DECIMAL POINT, AND FOUR SPACES.
;
; MAGNITUDES OUTSIDE THE ABOVE RANGE ARE REPRESENTED BY A
; SPACE OR MINUS SIGN, A VALUE BETWEEN 1.00000Q AND 9.999999,
; AN EXPONENTIAL SIGN, AND A SIGNED TWO DIGIT POWER OF TEN.
;
;
; THE INP SUBROUTINE CONVERTS CHARACTER STRINGS IN EITHER
; OF THE ABOVE FORMATS, OR A MODIFIED VERSION OF THEM. THE
; LEADING SIGN CHARACTER MAY BE INCLUDED OR OMITTED. UP TO
; 37 DIGITS MAY BE USED TO INDICATE THE VALUE, WITH OR WITHOUT
; AN INCLUDED DECIMAL POINT. IF A POWER-OF-TEN MULTIPLIER
; IS INDICATED IT MAY BE SIGNED OR UNSIGNED AND MAY CONTAIN
; ONE OR TWO DIGITS. AN INPUT CHARACTER STRING IS TERMINATED
; BY THE FIRST CHARACTER WHICH DEPARTS FROM THE SPECIFIED FORMAT.
;
; THE FOLLOWING ARE EXAMPLES OF INPUT AND CORRESPONDING
; OUTPUT CHARACTER STRINGS.
;
; 3. 141593 3.141593
; -.000000000001Q -1.00000QE-13
; +1.6E5 160000.0
; 12345678 1.234568E+08
; 54321E-10 5.432100E-6Q
; -2718281828 -2.718282E+09
;
;
; THE INDIVIDUAL SUBROUTINES INCLUDED IN THE FORMAT CONVERSION
; PACKAGE OF THE FLOATING POINT SYSTEM ARE DESCRIBED IN DETAIL
; BELOW.
;
; CHARACTER STRING INPUT SUBROUTINE
;
; THE CHARACTER STRING INPUT SUBROUTINE CONVERTS THE VALUE
; REPRESENTED BY A CHARACTER STRING STORED IN MEMORY TO
; FLOATING POINT FORMAT AND STORES THE RESULT IN THE FLOATING
; POINT ACCUMULATOR.
;
; ENTRY POINT
; INP
;
; ENTRY CONDITIONS
; H REGISTER = MS 6 BITS OF THE ADDRESS OF THE STRING
; L REGISTER = LS 8 BITS OF THE ADDRESS OF THE STRING
;
; EXIT CONDITIONS
; CONTROL BITS SET AS DEFINED FOR THE SYSTEM
; IF OVERFLOW
; LOCATION <OVER> SET NON-ZERO
; IF NO OVERFLOW
; A REGISTER = ACCUM EXP
; B REGISTER = ACCUM SIGN AND 1ST FRACTION
; C REGISTER = ACCUM 2ND FRACTION
; D REGISTER = ACCUM 3RD FRACTION
;
; REGISTERS ALTERED
; ALL
;
; MAXIMUM SUBROUTINE LEVELS USED
; 3
;
;
; CHARACTER STRING OUTPUT ROUTINE
;
; THE CHARACTER STRING OUTPUT SUBROUTINE CONVERTS THE VALUE
; IN THE FLOATING POINT ACCUMULATOR TO A CHARACTER STRING
; FORMAT CONSISTING OF 13 CHARACTERS AND STORES THE STRING
; IN MEMORY.
;
; ENTRY POINT
; OUT
;
; ENTRY CONDITIONS
; H REGISTER = MS 6 BITS OF THE ADDRESS OF THE STRING
; L REGISTER = LS 8 BITS OF THE ADDRESS OF THE STRING
;
; EXIT CONDITIONS
; CONTROL BITS SET AS DEFINED FOR THE SYSTEM
; A REGISTER = ACCUM EXP
; B REGISTER = ACCUM SIGN AND 1ST FRACTION
; C REGISTER = ACCUM 2ND FRACTION
; D REGISTER = ACCUM 3RD FRACTION
;
; REGISTERS ALTERED
; ALL
;
; MAXIMUM SUBROUTINE LEVELS USED
; 3
;
;
; FLOAT ROUTINE
;
; THE FLOAT SUBROUTINE CONVERTS THE FIXED POINT FORMAT DATA
; IN THE A,B,C, AND D REGISTERS TO FLOATING POINT FORMAT
; AND STORES THE RESULT IN THE FLOATING POINT ACCUMULATOR.
;
; ENTRY POINT
; FLT
;
; ENTRY CONDITIONS
; A REGISTER = MOST SIG WORD OF THE FIXED POINT VALUE
; B REGISTER = 2ND WORD OF THE FIXED POINT VALUE
; C REGISTER = 3RD WORD OF THE FIXED POINT VALUE
; D REGISTER = LEAST SIG WORD OF THE FIXED POINT VALUE
; E REGISTER = BINARY SCALING FACTOR OF THE FIXED POINT VALUE
;
; EXIT CONDITIONS
; CONTROL BITS SET AS DEFINED FOR THE SYSTEM
; A REGISTER = ACCUM EXP
; B REGISTER = ACCUM SIGN AND 1ST FRACTION
; C REGISTER = ACCUM 2ND FRACTION
; D REGISTER = ACCUM 3RD FRACTION
;
; REGISTERS ALTERED
; ALL
;
; MAXUMUM SUBROUTINE LEVELS USED
; 2
;
;
; FIX ROUTINE
;
; THE FIX SUBROUTINE CONVERTS THE VALUE IN THE FLOATING
; POINT ACCUMULATOR TO FIXED POINT FORMAT AND RETURNS
; THE RESULT IN THE A,B,C, AND D REGISTERS
;
; ENTRY POINT
; FIX
;
; ENTRY CONDITIONS
; E REGISTER = BINARY SCALING FACTOR OF THE FIXED POINT VALUE
;
; EXIT CONDITIONS
; IF THE VALUE CANNOT BE REPRESENTED AT THE SPECIFIED
; BINARY SCALING FACTOR
; CARRY BIT = 1
; OTHERWISE
; CARRY BIT = 0
;
; ZERO BIT = 0 IF THE VALUE IS NON-ZERO
; = 1 IF THE VALUE IS ZERO
; SIGN BIT = 0 IF THE VALUE IS POSITIVE
; = 1 IF THE VALUE IS NEGATIVE
; A REGISTER = MOST SIG WORD OF THE FIXED POINT VALUE
; B REGISTER = 2ND WORD
; C REGISTER = 3RD WORD
; D REGISTER = LEAST SIG WORD OF THE FIXED POINT VALUE
;
; REGISTERS ALTERED
; ALL
;
; MAXIMUM SUBROUTINE LEVELS USED
; 1
;
ORG 3000Q
SCR EQU 5400Q
SCRB EQU 13Q
ARITH EQU 1400Q ;BASE ADDRESS OF ARITHMETIC PKG
SPACE EQU 360Q
PLUS EQU 373Q
MINUS EQU 375Q
POINT EQU 376Q
EXPO EQU 25Q
;
; 8008 BINARY FLOATING POINT SYSTEM
; FORMAT CONVERSION PACKAGE
; PROGRAMMER: CAL OHME
; DATE: 26 DECEMBER 1973
; ARITH IS THE BEGINNING ADDRESS OF THE
; ARITHMETIC AND UTILITY PACKAGE OF THE FLOATING POINT SYSTEM
; SCR IS THE BEGINNING ADDRESS OF THE RAM USED AS SCRATCHPAD
;
OVER EQU 56Q ;OVERFLOW FLAG
ACCE EQU 60Q ;ACCUM EXP
ACCS EQU ACCE+1 ;ACCUM SIGN
ACC1 EQU ACCS+1 ;ACCUM 1ST FRACTION
ACC2 EQU ACC1+1 ;ACCUM 2ND FRACTION
ACC3 EQU ACC2+1 ;ACCUM 3RD FRACTION
SF EQU ACC3+1 ;SUBTRACTION FLAG
ADRL EQU SF+1 ;CHARACTER STRING WORD
ADRH EQU ADRL+1 ;CHARACTER STRING BANK
TMP1 EQU ADRH+1 ;TEMPORARY STORAGE
TMP2 EQU TMP1+1
TMP3 EQU TMP2+1
VALE EQU TMP3+1 ;VALUE EXPONENT
VAL1 EQU VALE+1 ;VALUE 1ST FRACTION
VAL2 EQU VAL1+1 ;VALUE 2ND FRACTION
VAL3 EQU VAL2+1 ;VALUE 3RD FRACTION
TMP4 EQU VAL3+1 ;TEMPORARY STORAGE
;
; ADDRESSES IN THE ARITHMETIC AND UTILITY PACKAGE
; REFERENCED BY THE FORMAT CONVERSION PACKAGE .
;
STR EQU ARITH+76Q
ZRO EQU ARITH+106Q
ABS EQU ARITH+120Q
TST EQU ARITH+131Q
LOD EQU ARITH+156Q
MUL EQU ARITH+214Q
DIV EQU ARITH+264Q
ADD EQU ARITH+327Q
ADD10 EQU ARITH+553Q
LSH EQU ARITH+674Q
RSH EQU ARITH+711Q
COMP EQU ARITH+757Q
;
; SUBROUTINE TO CONVERT FROM FIXED POINT TO FLOATING POINT FORMAT
;
FLT: MOV L,E ;INPUT EXP
MOV E,D ;4TH INPUT FRACTION
MOV D,C ;3RD INPUT FRACTION
MOV C,B ;2ND INPUT FRACTION
MOV B,A ;1ST INPUT FRACTION
MOV A,L ;INPUT EXP
XRI 200Q ;APPLY EXPONENT BIAS
MVI H,SCRB ;ADDRESS SCRATCH BANK
MVI L,ACCE ;ADDRESS ACCUM EXP
MOV M,A ;STORE ACCUM EXP
INR L ;ADDRESS ACCUM SIGN
MVI M,200Q ;SET ACCUM SIGN POSITIVE
INR L ;ADDRESS ACCUM 1ST FRACTION
MOV A,B ;1ST INPUT FRACTION
ANA A ;SET SIGN BIT
RAL ;INPUT SIGN TO CARRY
JMP ADD10 ;COMPLETE CONVERSION
;
; SUBROUTINE TO CONVERT FROM FLOATING POINT TO FIXED POINT FORMAT
;
FIX: MVI H,SCRB ;ADDRESS SCRATCH BANK
MVI L,ACCE ;ADDRESS ACCUM EXP
MOV A,M
ANA A ;SET CONTROL BITS
JZ FIX1 ;IF ACCUM IS ZERO
MOV A,E ;INPUT EXP
ADI 177Q ;ADD BIAS-1
SUB M ;SHIFT COUNT -1
RC ;RETURN IF ACCUM TOO LARGE
CPI 31 ;COMPARE TO LARGE SHIFT
JNC FIX1 ;IF ACCUM TO SMALL
ADI 1 ;SHIFT COUNT
MVI L,ACC1 ;ADDRESS ACCUM 1ST FRACTION
MOV B,M
INR L ;ADDRESS ACCUM 2ND FRACTION
MOV C,M
INR L ;ADDRESS ACCUM 3RD FRACTION
MOV D,M
CALL RSH ;POSITION THE FRACTION
MVI L,ACCS ;ADDRESS ACCUM SIGN
MOV A,M
ANA A ;SET CONTROL BITS
CP COMP ;COMPLEMENT FRACTION IF NEGATIVE
MVI A,1 ;NON-ZERO
ORA B ;SET CONTROL BITS FOR EXIT
MOV A,B ;1ST RESULT
MOV B,C ;2ND RESULT
MOV C,D ;3RD RESULT
MOV D,E ;4TH RESULT
RET
FIX1: XRA A ;SET A REG TO ZERO
MOV B,A
MOV C,A
MOV D,A
RET
DB 0 ;CHECKSUM WORD
;
; INP SUBROUTINE ENTRY POINT
; INITIALIZE TEMPORARY STORAGE
;
INP: MOV E,M ;FIRST CHAR OF STRING
CALL SVAD ;SET CHAR ADDR, PNT FLAG, EXP
INR L ;ADDRESS VALUE SIGN
MVI M,200Q ;SET VALUE SIGN POSITIVE
MVI L,ACCE ;ADDRESS ACCUM EXP
MOV M,D ;SET ACCUM TO ZERO
MOV A,E ;1ST CHAR
CPI SPACE ;COMPARE TO SPACE
JZ INP1 ;IF SPACE CHAR
CPI PLUS ;COMPARE TO PLUS
JZ INP1 ;IF PLUS SIGN
CPI MINUS ;COMPARE TO MINUS
JNZ INP2 ;IF NOT MINUS SIGN
MVI L,TMP3 ;ADDRESS VALUE SIGN
MOV M,D ;SET VALUE SIGN NEGATIVE
;
; ANALYZE NEXT CHARACTER IN STRING
;
INP1: CALL CHAD ;CALL CHAR ADDRESS SUBROUTINE
MOV A,M ;NEXT CHAR
MVI H,SCRB ;ADDRESS SCRATCH BANK
INP2: MVI B,0 ;DIGIT 2ND WORD OR DEC EXP
CPI POINT ;COMPARE TO DECIMAL POINT
JZ INP3 ;IF DECIMAL POINT
CPI EXPO ;COMPARE TO EXPONENT SIGN
JZ INP4 ;IF EXPONENT SIGN
CPI 10 ;SET CARRY IF CHAR IS A DIGIT
JNC INP8 ;IF CHAR IS NOT A DIGIT
MVI L,TMP4 ;ADDRESS CURRENT DIGIT
MOV M,A ;SAVE CURRENT DIGIT
LXI H,FTEN ;ADDRESS FLOATING TEN
CALL MUL ;MULTIPLY BY TEN
MVI L,VALE ;ADDRESS VALUE
CALL STR ;STORE OLD VALUE TIMES TEN
INR L ;ADDRESS CURRENT DIGIT
MOV A,M
MVI B,0 ;CLEAR 2ND WORD OF DIGIT
MOV C,B ;CLEAR 3RD WORD
MOV D,B ;CLEAR 4TH WORD
MVI E,8 ;INDICATE DIGIT IS IN REG A
CALL FLT ;CONVERT DIGIT TO FLOATING POINT
MVI L,VALE ;ADDRESS VALUE
CALL ADD ;ADD OLD VALUE TIMES TEN
MVI L,TMP2 ;ADDRESS DECIMAL POINT FLAG
MOV A,M
ANA A ;SET CONTROL BITS
JZ INP1 ;IF NO DECIMAL POINT ENCOUNTERED
DCR L ;ADDRESS INPUT EXP
MOV B,M
DCR B ;DECREMENT INPUT EXP
MOV M,B ;UPDATE INPUT EXP
JMP INP1 ;GET NEXT CHAR
INP3: MVI L,TMP2 ;ADDRESS DECIMAL POINT FLAG
XRA M ;ZERO IF FLAG SET
MOV M,A ;SET DEC POINT FLAG
JNZ INP1 ;IF FLAG NOT ALREADY SET
JMP INP8 ;IF 2ND DECIMAL POINT
;
; PROCESS DECIMAL EXPONENT
;
INP4: CALL CHAD ;CALL CHAR ADDR SUB
MOV A,M ;NEXT CHAR OF STRING
MOV B,A ;CURRENT CHAR
SUI MINUS ;COMPARE TO MINUS CHAR
MOV E,A ;CHAR - <MINUS SIGN>
JZ INP5 ;IF MINUS SIGN
ADI MINUS-PLUS ;COMPARE TO PLUS SIGN
MOV A,B ;CURRENT CHAR
JNZ INP6 ;IF NOT PLUS SIGN
INP5: INR L ;ADDRESS NEXT CHAR
MOV A,M ;NEXT CHAR OF STRING
INP6: MVI B,0 ;POSSIBLE DECIMAL EXPONENT
CPI 10 ;SET CARRY IF CHAR IS A DIGIT
JNC INP8 ;IF CHAR IS NOT A DIGIT
MOV B,A ;DEC EXP EQUAL DIGIT
INR L ;ADDRESS NEXT CHAR
MOV A,M
CPI 10 ;SET CARRY IF A DIGIT
JNC INP7 ;IF CHAR IS NOT A DIGIT
;
; FORM COMPLETE DECIMAL EXPONENT
;
MOV C,A ;LS DIGIT OF DEC EXP
MOV A,B ;MS DIGIT OF DEC EXP
ADD A ;2 * MS DIGIT
ADD A ;4 * MS DIGIT
ADD B ;5 * MS DIGIT
ADD A ;10 * MS DIGIT
ADD C ;10 * MS + LS DIGIT
MOV B,A ;DECIMAL EXP
INP7: MOV A,E ;SIGN OF DEC EXP
ANA A ;SET CONTROL BITS
JNZ INP8 ;IF SIGN PLUS
SUB B ;COMPLEMENT DEC EXP
MOV B,A ;DEC EXP
INP8: MVI H,SCRB ;ADDRESS SCRATCH BANK
MVI L,TMP3 ;ADDRESS INPUT SIGN
MOV C,M
MVI L,ACCS ;ADDRESS ACCUM SIGN
MOV M,C ;STORE ACCUM SIGN
MOV A,B ;DEC EXP
;
; CONVERT DECIMAL EXPONENT TO BINARY
;
INP9: MVI L,TMP1 ;ADDRESS DEC EXP
ADD M ;ADJUST DEC EXP
JZ TST ;IF DEC EXP IS ZERO
MOV M,A ;CURRENT DEC EXP
LXI H,FTEN ;ADDRESS FLOATING POINT TEN
JP INP10 ;IF MULTIPLY REQUIRED
CALL DIV ;DIVIDE BY 10
MVI A,1 ;TO INCREMENT DEC EXP
JMP INP9 ;TEST FOR COMPLETION
INP10: CALL MUL ;MULTIPLY BY 10
RC ;RETURN IF OVERFLOW
MVI A,-1 ;DECREMENT DEC EXP
JMP INP9 ;TO TEST FOR COMPLETION
;
; OUT SUBROUTINE ENTRY POINT
; SAVE CHARACTER ADDRESS AND ACCUMULATOR.
;
OUT: DCR L ;DECREMENT CHAR ADDRESS
CALL SVAD ;SET CHAR ADDR, DIG CNT, DEC EXP
CALL TST ;LOAD ACCUM TO REGISTERS
MVI L,VALE ;ADDRESS ACCUM SAVE AREA
CALL STR
;
; OUTPUT SIGN CHAR
;
CALL CHAD ;CALL CHAR ADDR SUBROUTINE
MVI M,SPACE ;STORE SPACE CHAR
ANA A ;SET CONTROL BITS
JZ OUT3 ;IF ACCUM IS ZERO
MOV E,A ;ACCUM EXP
MOV A,B ;ACCUM SIGN AND 1ST FRACTION
ANA A ;SET CONTROL BITS
MOV A,E ;ACCUM EXP
JP OUT1 ;IF ACCUM IS POSITIVE
MVI M,MINUS ;CHANGE SIGN TO MINUS
;
; SCALE ACCUM TO .1 - 1. RANGE
;
OUT1: CPI 176Q ;COMPARE TO SMALL EXPONENT
OUT2: LXI H,FTEN ;ADDRESS OF FLOATING TEN
JC OUT4 ;IF EXPONENT TOO SMALL
CPI 201Q ;COMPARE TO LARGE EXP
JC OUT5 ;IF EXP SMALL ENOUGH
CALL DIV ;DIVIDE BY TEN
OUT3: MVI H,SCRB ;ADDRESS SCRATCH BANK
MVI L,TMP2 ;ADDRESS DECIMAL EXP
MOV E,M
INR E ;INCREMENT DEC EXP
MOV M,E ;STORE DECIMAL EXP
JMP OUT2 ;TEST FOR SCALING COMPLETE
OUT4: CALL MUL ;MULTIPLY BY TEN
MVI L,TMP2 ;ADDRESS DECIMAL EXP
MOV E,M
DCR E ;DECREMENT DEC EXP
MOV M,E
JMP OUT1 ;TEST FOR SCALING COMPLETE
;
; ROUND THE VALUE BY ADDING .0000005Q
;
OUT5: CALL ABS ;SET ACCUM POSITIVE
LXI H,RND0 ;ADDRESS ROUNDER
CALL ADD ;ADD THE ROUNDER
CPI 201Q ;CHECK FOR OVERFLOW
JNC OUT2 ;IF EXP TOO LARGE
;
; SET DIGIT COUNTS
;
MVI L,TMP2 ;ADDRESS DEC EXP
MOV A,M
MOV E,A ;DIGITS BEFORE DECIMAL POINT
CPI 8 ;COMPARE TO LARGE EXP
JC OUT6 ;IF EXPONENT IN RANGE
MVI E,1 ;DIGITS BEFORE DECIMAL POINT
OUT6: SUB E ;ADJUST DEC EXP
MOV M,A ;DEC EXP
MVI A,7 ;TOTAL NUMBER OF DIGITS
SUB E ;DIGITS AFTER DECIMAL POINT
INR L ;ADDRESS 2ND DIGIT CNT
MOV M,A ;DIGITS AFTER DEC POINT
DCR E ;DECREMENT DIGIT COUNT
MOV A,E ;DIGITS BEFORE DEC POINT
;
; OUTPUT SIGNIFICANT DIGITS
;
OUT7: MVI L,TMP1 ;ADDRESS DIGIT COUNT
ADD M ;ADJUST DIGIT COUNT
MOV M,A ;NEW DIGIT COUNT
JM OUT8 ;IF COUNT RUN OUT
LXI H,FTEN ;ADDRESS FLOATING TEN
CALL MUL ;MULTIPLY BY TEN
MVI E,8 ;TO PLACE DIGIT IN REGISTER A
CALL FIX ;CONVERT TO FIXED POINT FORMAT
CALL CHAD ;CALL CHAR ADDRESS SUBROUTINE
MOV M,A ;SEND OUT DECIMAL DIGIT
XRA A ;CLEAR CURRENT DIGIT
MVI E,8 ;BINARY SCALING FACTOR
CALL FLT ;RESTORE VALUE MINUS DIGIT
MVI A,-1 ;TO ADJUST DIGIT COUNT
JMP OUT7 ;LOOP FOR NEXT DIGIT
OUT8: MVI L,TMP3 ;ADDRESS 2ND DIGIT CNT
MOV A,M ;DIGITS AFTER DECIMAL POINT
MVI M,-1 ;SET 2ND COUNT NEGATIVE
ANA A ;SET CONTROL BITS
JM OUT9 ;IF 2ND COUNT RAN OUT
CALL CHAD ;CALL CHAR ADDR SUBROUTINE
MVI M,POINT ;STORE DECIMAL POINT
MVI H,SCRB ;ADDRESS SCRATCH BANK
JMP OUT7 ;LOOP FOR NEXT DIGIT
OUT9: DCR L ;ADDRESS DECIMAL EXP
ANA M ;DEC EXP
JZ OUT13 ;IF DEC EXP IS ZERO
;
; SEND OUT DECIMAL EXPONENT
;
MVI B,PLUS ;PLUS CHARACTER
JP OUT10 ;IF EXP IS POSITIVE
MVI B,MINUS ;CHANGE SIGN TO MINUS
MOV C,A ;NEGATIVE EXP
XRA A ;CLEAR A REG
SUB C ;COMPLEMENT EXP
OUT10: MVI C,-1 ;EMBRYO TENS DIGIT
OUT11: MOV D,A ;UNITS DIGIT
INR C ;INCREMENT TENS DIGIT
SUI 10 ;REDUCE REMAINDER
JNC OUT11 ;IF MORE TENS
MVI A,EXPO ;EXPONENT SIGN
OUT12: CALL CHAD ;CHAR ADR SUBROUTINE
CALL STR ;STORE LAST 4 CHARACTERS
MVI H,SCRB ;ADDRESS SCRATCH BANK
MVI L,VALE ;ADDRESS ACCUM SAVE AREA
JMP LOD ;RESTORE ACCUM AND EXIT
;
; SEND OUT 4 SPACES IF EXPONENT IS ZERO
;
OUT13: MVI A,SPACE ;SPACE CHARACTER
MOV B,A
MOV C,A
MOV D,A
JMP OUT12 ;STORE CHARACTERS
;
; SUBROUTINE TO SAVE CHARACTER STRING ADDRESS
;
SVAD: MOV A,L ;CHARACTER STRING WORD
MOV B,H ;CHARACTER STRING BANK
MVI C,0 ;INPUT EXP OR DIGIT COUNT
MOV D,C ;DEC PNT FLAG OR DEC EXP
MVI H,SCRB ;ADDRESS SCRATCH BANK
MVI L,ADRL ;ADDRESS CHAR STRING WORD
CALL STR ;STORE A,B,C,AND D
RET
;
; SUBROUTINE TO OBTAIN NEXT CHARACTER ADDRESS
;
CHAD: MVI H,SCRB ;ADDRESS SCRATCH BANK
MVI L,ADRL ;ADDRESS CHAR STRING WORD
MOV E,M ;CHAR STRING WORD
INR E ;ADDRESS NEXT CHAR
MOV M,E ;UPDATE CHAR STRING WORD
INR L ;ADDRESS CHAR STRING BANK
MOV H,M ;CHAR STRING BANK
MOV L,E ;CHAR STRING WORD
RET
FTEN: DB 204Q,40Q,0,0 ;FLOATING TEN
RND0: DB 150Q,126Q,277Q,225Q ;.0000005Q
DB 0 ;CHECKSUM WORD
END