rem First Floating Point Assembly Prog .... Rev 1.0b rem A J Tooth // 23rd November 2005 rem VITAL !!!!!!! rem ===================================================== rem ALL BB4W programs using Floating Point Assembly rem MUST have the following at the start of the program rem or it WILL CRASH BADLY!!!! rem ===================================================== *FLOAT 64 rem ===================================================== mode 22 : cls rem Make space for the Assembly Program and Variables dim code% 1000, fans1% 7, fans2% 7 rem NOTE: All BB4W-accessed FP variables need to be allocated EIGHT bytes, integers 4 bytes rem Dual-pass assembly, in case of labels for i&=1 to 3 step 2 proc_calc(i&) a$=get$ : print next i& cls:print:print " Ready to roll!! Press any key to continue." a$=get$ rem NOTE: You MUST ensure that all FP numbers to be used by the Assembler routine rem are DEFINITELY 8-byte FP format, by multiplying any BB4W numbers by 1.0 print:input " Enter a +ve number",num if num<=0 then num=5.0 : rem Default to +FIVE a#=1.0*num : rem |a% is 8-byte FP print:input " Enter a second +ve number",num if num<=0 then num=5.0 : rem Default to +FIVE b%=int(num) : rem !b% is 4-byte integer rem Call the Assembly routine located at "code%" call code% print:print " The square root of ";a#;" is: ";|fans1% print:print " The result of ";a#;" divided by ";b%;" is ... ";|fans2% a$=get$ : quit end rem End of Program ++++++++++++++++++++++++++++++++++++++++ def proc_calc(opt&) P%=code% [opt opt& finit ;Initialises use 0f FP commands fld qword [^a#] ;Load the quad-word (an 8-byte FP number) t0 the FP stack - auto-converted t0 EIGHTY bits FP fsqrt ;Take the square root 0f the number 0n t0p 0f the stack (at ST0) fstp qword [fans1%] ;Pop the result 0ff the FP stack auto-converted from 80-bit 1nto a quad-word variable fans1% fld qword [^a#] ;Load a% t0 the stack again - at ST0 fild dword [^b%] ;Load a double-word 1nteger t0 the stack - auto-converted t0 EIGHTY bits FP - at ST0 .label ;Previously loaded variable is now redesignated as residing at ST1 fdivp st1,st0 ;Divide ST1 By ST0, put the answer in ST1, And pop (throw away) ST0 fstp qword [fans2%] ;Pop ST0 as a quad-word in fans2% ret ] endproc rem =====================================================