home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.whtech.com
/
ftp.whtech.com.tar
/
ftp.whtech.com
/
Geneve
/
9640news
/
CAT14
/
FLTNGPN.ARK
< prev
next >
Wrap
Text File
|
2006-10-19
|
9KB
|
316 lines
?
**************************************
* *
* ASSEMBLY LANGUAGE *
* *
* FLOATING-POINT MATH *
* *
* by Steve Langguth *
* Ozark 99'er Users Group *
* *
**************************************
Recently I was writing an assembly
language program and all of a sudden
realized that I needed to use decimal
numbers. "Time to learn about floating
point math in assembly language," I
said to myself. But as usual with A/L
it was easier said than done. I knew
that I needed to use various "GPLLNK"
and "XMLLNK" routines, but how they
were used I learned by trial and error,
luck, and by using "Explorer"
frequently. The program below is
worthless except that it demonstrates
some of the techniques I "created" for
working with floating point numbers.
The program prints two numbers on the
screen, converts them into FP, adds
them together, converts the FP result
into a string and displays the result.
The explanation follows the program.
*
DEF START
*
REF VSBW,VMBW,KSCAN
REF XMLLNK,GPLLNK
*
FAC EQU >834A F/P ACCUM
ARG EQU >835C ARGUMENT
STRNG EQU >8356 FAC+12
KEYADR EQU >8374
KEYVAL EQU >8375
*
SPBR BYTE >20
*
ONE TEXT '11.1111'
TWO TEXT '2.222'
LINE TEXT '-------'
*
EVEN
*
MYREG BSS >20
ONEFP BSS 8
SUM BSS 16
*
START LWPI MYREG
*
LI R0,>008A
LI R1,ONE
LI R2,7
BLWP @VMBW DISPLAY "ONE"
*
BL @WAIT WAIT FOR SPACE
*
LI R0,>00C9
LI R1,>2B00
BLWP @VSBW DISPLAY "+"
*
BL @WAIT WAIT FOR SPACE
*
LI R0,>00CB
LI R1,TWO
LI R2,5
BLWP @VMBW DISPLAY "TWO"
*
BL @WAIT WAIT FOR SPACE
*
LI R0,>010A
LI R1,LINE
LI R2,7
BLWP @VMBW DISPLAY "LINE"
*
LI R0,>008A
MOV R0,@STRNG PUT ADDRESS OF
* "ONE" IN FAC+12
BLWP @XMLLNK
DATA >1000 F/P NUMBER NOW
* IN FAC
*
LI R1,FAC
LI R2,ONEFP
BL @TRANS MOVE RESULT TO
* "ONEFP"
*
LI R0,>00CB
MOV R0,@STRNG PUT ADDRESS OF
* "TWO" IN FAC+12
BLWP @XMLLNK
DATA >1000 F/P # IN FAC
*
LI R1,ONEFP
LI R2,ARG
BL @TRANS "TWOFP" IN FAC,
* "ONEFP" IN ARG
*
BLWP @XMLLNK
DATA >0600 (ONEFP + TWOFP)
* RESULT IN FAC
*
CLR R0
MOVB R0,@>8355
*
CLR R1
MOVB R1,@>837C
BLWP @GPLLNK
DATA >0014 CONVERT FP SUM
* TO ASCII STRING
*
CLR R1
MOVB @>8355,R1
SWPB R1
AI R1,>8300 R1 = ADDR. OF
* ASCII STRING
LI R2,SUM
*
CLR R3
MOVB @>8356,R3
SWPB R3 R3 = # OF BYTES
* IN NEW STRING
*
X MOVB *R1+,*R2+
DEC R3
MOV R3,R3
JNE X MOVE STRING
* INTO "SUM"
*
CB @SUM,@SPBR IS FIRST CHAR
* A "SPACE" ?
JNE Y
*
LI R0,>014A
LI R1,SUM+1
LI R2,7
BLWP @VMBW DISPLAY "SUM"
* WITHOUT SPACE
JMP LOOP
*
Y LI R0,>014A
LI R1,SUM
LI R2,8
BLWP @VMBW DISPLAY "SUM"
*
LOOP LIMI 2
JMP LOOP
*
WAIT CLR R0
MOV R0,@KEYADR
A BLWP @KSCAN
CB @KEYVAL,@SPBR
JNE A
*
LI R0,10000
B DEC R0
CI R0,0
JNE B
*
RT
*
TRANS CLR R3
C MOV *R1+,*R2+
CI R3,3
JEQ D
INC R3
JMP C
*
D RT
*
END
The first two lines of source code
define the name of the program and
reference the utilities to be used.
The next group of 5 lines "name"
various addresses that will be used
later. The 4 lines that follow label
certain data we will also use later.
The EVEN statement is used to make sure
we begin on an even address after our
TEXT statements. Following the EVEN
statement, we set up 3 buffers.
The line labelled START is the
beginning of the actual program
statements. First we tell the computer
to use the MYREG buffer for the
workspace registers, using the LWPI
command. The next group of 4 lines
displays the text string labelled ONE
at screen address >008A. Then, we
branch to a subroutine that waits for
the space bar to be pressed. The same
sequence of commands is used to display
the "+" sign, the text string TWO, and
the text string LINE.
After the "line" has been drawn,
we actually begin to use the floating
point routines. The first routine
converts a text string into a floating
point number. You can read the details
about how this routine works on pages
257-262 of the E/A manual. First, we
put the address of the string we wish
to convert into R0, and then MOVe it to
address FAC+12 (which we named STRNG
earlier). The next two lines tell the
computer we want to use the XMLLNK
routine to convert a string to a FP
number. The result of this conversion
is put at address FAC (>834A). Each
floating point number is 8 bytes long,
and is in a form known as Radix 100
notation. The details of this form of
notation are on page 279 of the
manual.
Next, we use a little routine I
came up with to easily move FP numbers
around. Since each FP number is 8
bytes long, we can't use a simple MOV
command. Instead we use the TRANS
routine found near the end of the
program. This routine moves 8 bytes (4
words) of data from the address put in
R1 to address put in R2. The routine
uses Workspace Register Indirect Auto
Increment Addressing Mode. (See page 58
of the E/A manual.) We put the address
FAC into R1, ONEFP into R2, and then
branch and link to the TRANS
subroutine. This moves the FP number
(11.1111) from FAC into the ONEFP
buffer.
After that, we convert TWO in the
same way, but this time we leave the
result in the FAC. Then, we move ONEFP
into ARG (using the TRANS subroutine),
and call the XMLLNK routine that adds
the two FP numbers together.
Now we must convert our sum back
into a form that can be displayed on
the screen. To do this, we need to use
a GPLLNK routine. (The details of using
these routines are found on page 251 of
the E/A manual.) First we set >8355 to
0. This means our string will be in TI
Basic format. I haven't been able to
find a description of what that format
is, but I was able to get this to work
using Basic format and NOT using "Fixed
Mode". Next we clear the status
register and call the GPLLNK routine to
do the conversion. After the
conversion, the byte at >8355 is added
to >8300 to determine the address of
our new string. This address is put in
R1. R2 is loaded with the address of
our buffer to hold the result. Then,
we use a routine similar to our TRANS
routine to move the string to the SUM
buffer. This time, however, we use the
value at >8356 to determine how many
bytes to move.
After the string is moved, we
display it on the screen. Sometimes,
the string created by the conversion
routine begins with a space, and
sometimes not. I assume this is to
leave room for a minus sign if one is
needed, but it complicates the
displaying of our result. So, we check
to see if the first character of the
string is a space. If so, we jump to a
set of statements that puts the result
at the correct place on the screen. If
the first character is a space, we skip
that character and print the next 7
characters where they belong.
Finally, we enter a loop that
allows us to end by pressing the "QUIT"
button. The source code after the LOOP
is the WAIT subroutine that waits for
the space bar to be pressed, then goes
into a delay loop before returning to
the main program. This keeps the
program from jumping through more than
one step if you hold the bar down just
a little too long. After the WAIT
routine is the TRANS subroutine
described above.
I realize this description is not
too detailed, but the best way to
really understand what is going on is
by experimenting. Try changing the
numbers, or subtracting or multiplying
them instead of adding. With a little
practice, you too can become an
"expert" at using floating point
numbers in 99/4A Assembly Language.
Download complete. Turn off Capture File.