Oxygen Basic

Programming => Problems & Solutions => Topic started by: Peter on October 01, 2011, 08:46:34 AM

Title: Ethic
Post by: Peter on October 01, 2011, 08:46:34 AM
Deleted
Title: Re: Ethic
Post by: Charles Pegge on October 01, 2011, 01:40:45 PM

Hi Peter.

Put the dot first.

Code: [Select]
jmp fwd bac

.bac pushad
     mov  eax,10
     a=eax
     print a
     popad

Charles
Title: Re: Ethic
Post by: Charles Pegge on October 01, 2011, 03:26:02 PM
It has been around for a while.

'a' has been automatically created (auto dim)

a=eax

will translate to something like:

mov [ebx+4096],eax


You can do this with any general purpose register but the value will always pass through the eax register, which is used as the accumulator for most integer arithmetic.

This is also possible

a=ecx+edx+42


Charles
Title: Re: Ethic
Post by: Charles Pegge on October 02, 2011, 01:43:50 PM

Hi Peter,

Static arrays require a constant expression to specify the array size, not a variable. I will need to prevent this:

Code: OxygenBasic
  1.  
  2. indexbase 0
  3. sys dm=2
  4. dim Bild(dm)
  5.  

Charles
Title: Re: Ethic
Post by: Charles Pegge on October 02, 2011, 02:15:02 PM
Hi Peter,

Code: OxygenBasic
  1.  
  2. sub fill(int *x, *y, f1, f2)
  3. int j
  4. for j=0 to 5
  5.     x(j) = f1
  6.     y(j) = f2
  7. Next
  8. End Sub
  9.  
  10.  

This works perfectly for arrays of numbers and user-defined types but beware passing arrays of strings in this way.

The technique below will work for filling string arrays and all other arrays too.

string s at a

Code: OxygenBasic
  1. dim string s(4)
  2.  
  3. function f(sys a,e)
  4. string t at a
  5. sys i
  6. for i=1 to e
  7.   t(i)=chr(i+64)
  8. next
  9. end function
  10.  
  11. f @s,4 '&s,4
  12.  
  13. print s(2)
  14.  

Charles
Title: Re: Ethic
Post by: Aurel on October 03, 2011, 05:27:56 AM
Quote
I have no idea, what I can do with strings
:D
But i have ;)
Title: Re: Ethic
Post by: JRS on October 03, 2011, 09:54:29 AM
Quote
But good to know that using of strings are very dangerously.

Not if you have a good memory manager. All data is stored as strings internally in SB. The interpreter is smart enough to know if your passing data not appropriate for the requested function being called.

 
Title: Re: Ethic
Post by: Charles Pegge on October 03, 2011, 10:11:28 AM

Hi Peter,


string s="Oxygen strings are not hard to use :)"
putfile "t.txt",ucase s
print getfile "t.txt"


Title: Re: Ethic
Post by: Charles Pegge on October 03, 2011, 03:58:49 PM

String overlays can be useful

Code: OxygenBasic
  1. include "window.h"
  2.  
  3. string s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  4.  
  5. byte txt at *s 'overlay technique
  6.  
  7. SaveFile "Text.txt",txt,26
  8.  

Charles