Page 1 of 1

Posted: Wed Mar 26, 2003 12:59 pm
by BackupUser
Restored from previous forum. Originally posted by tejon.

why does this code not work?

Code: Select all

OpenConsole()
ConsoleTitle ("inline asm test ")                                                  
Dim a.w(3)

Procedure.s myHex(n.w)
   c.w=PeekB(@n+1)
   h.w=c/16
   l.w=c-h*16
   If h<10
     hb.s=Chr(h+48)
   Else
     hb.s=Chr(h+55)
   EndIf
   If l<10
     lb.s=Chr(l+48)
   Else
     lb.s=Chr(l+55)
   EndIf
   mhex$=hb+lb
   c.w=PeekB(@n)
   h.w=c/16
   l.w=c-h*16
   If h<10
     hb.s=Chr(h+48)
   Else
     hb.s=Chr(h+55)
   EndIf
   If l<10
     lb.s=Chr(l+48)
   Else
     lb.s=Chr(l+55)
   EndIf
   mhex$=mhex$+hb+lb
  ProcedureReturn mhex$
EndProcedure

aptr.l=@a(0)
FINIT          ;initialize FPU
FLD1           ;load 1 into st(0)
FADD st,st     ;make st(0) = 2
FSQRT          ;sqrt(2)
MOV ebx,aptr   ;put address of array a into EBX
FST qword [ebx];store sqrt(2) into array a
; array a now has
;a(3)=16374 ;3FF6
;a(2)=41118 ;A09E
;a(1)=26239 ;667F
;a(0)=15309 ;3BCD
For i=3 To 0 Step -1
   a$=myHex(a(i))
   a$=a$+" "
   Print(a$)
;  should print 3FF6 A09E 667F 3BCD 
Next i
b$=Input()
CloseConsole()

Posted: Wed Mar 26, 2003 1:32 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

your code doesn't work because PB uses signed bytes and the sign is transfered when you assign the byte value to another variable of another type.. that's why:
'a.b=-1 : b.w = a'
results in that b now equals -1

solve problem by changing your peekb() lines to this:
c.w=PeekB(@n+1) & $ff

Posted: Wed Mar 26, 2003 1:47 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

If that doesn't work, try making n a global (local variables are in the stack, and I remember having problems with that when using asm in a procedure some time ago).

El_Choni

Posted: Wed Mar 26, 2003 2:11 pm
by BackupUser
Restored from previous forum. Originally posted by PB.

> why does this code not work?

Dunno, but you can do it much shorter with this procedure:

viewtopic.php?t=3477

Posted: Wed Mar 26, 2003 8:10 pm
by BackupUser
Restored from previous forum. Originally posted by tejon.

thanks, as you can see i am toying with the idea of using the fpu
for greater precision.
but some things are missing from the fpu, there's no StrToFloat
or FloatToStr, and apparently no log function.

Posted: Wed Mar 26, 2003 10:40 pm
by BackupUser
Restored from previous forum. Originally posted by El_Choni.

There are StrF(), ValF() Log10() and Log() (base e) functions.

El_Choni