rem First Floating Point Assembly Prog .... Rev 1.0c 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 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 ans1#=0.0 : ans2#=0.0 : rem These variables have to be declared rem Call the Assembly routine located at "code%" call code%,a#,b%,ans1#,ans2# print:print " The square root of ";a#;" is: ";ans1# print:print " The result of ";a#;" divided by ";b%;" is ... ";ans2# a$=get$ : quit end rem End of Program ++++++++++++++++++++++++++++++++++++++++ def proc_calc(opt&) P%=code% [opt opt& finit ;Initialises use 0f FP commands mov esi,[ebp+2] ;Load esi with the address 0f a# contained in ebp+2 fld qword [esi] ;Load the quad-word number at the address in esi 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) mov esi,[ebp+12] ; fstp qword [esi] ;Pop the result 0ff the FP stack auto-converted from 80-bit 1nto a quad-word mov esi,[ebp+2] fld qword [esi] ;Load a% t0 the stack again - at ST0 mov esi,[ebp+7] ;Load esi with the address 0f b% held at ebp+12 fild dword [esi] ;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 mov esi,[ebp+17] ;Load esi with the address 0f ans2# held at ebp+17 fstp qword [esi] ;Pop ST0 as a quad-word t0 the address held in esi ret ] endproc rem =====================================================