Author Topic: O2 Source ?  (Read 32662 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Re: O2 Source ?
« Reply #45 on: July 30, 2011, 06:19:50 AM »
yes, I have understood this.  :D
« Last Edit: July 30, 2011, 08:24:20 AM by peter »

efgee

  • Guest
Re: O2 Source ?
« Reply #46 on: July 30, 2011, 07:40:28 AM »
Quote
the assembler adds $58 to the code section (only valid for the intel processors).
ooups i don't know that...
Anyway Libry is not bad example how write native compiler,right?

It's a bit of a hack but on the other side it's a great learning tool because the code is very small.

Like Oxygen it's an all in one compiler with tokenizer, lexer, parser, assembler and linker and if you know VB it's easy to read and understand.
(the linker just writes the content of different arrays to a file - so its not a "real" linker that handles object files)




JRS

  • Guest
Re: O2 Source ?
« Reply #47 on: July 30, 2011, 09:27:51 PM »
Charles,

I'm convinced that Radare is the best tool to create a multi-platform O2 Basic JIT compiler. I think this direction would shorten the multi-platform development cycle and allow others to help/learn. The (graphic) self documenting feature is also a plus.

I would be willing to learn the guts of O2 if Radare was my framework/toolset.

Once I get my arms around how this all works, I might even try to contribute in someway.

John
« Last Edit: July 30, 2011, 11:37:54 PM by JRS »

Charles Pegge

  • Guest
Re: O2 Source ?
« Reply #48 on: July 30, 2011, 11:39:13 PM »

Hi John,

I would use that Oxygen program to test the binary output file  from your linker. I think getting involved with C modules would be too cumbersome.

I had difficulties getting SB to convert hexadecimal strings to values >9

SB
Code: [Select]
'TEST HEXADECIMAL TO BINARY CONVERSION IN SB

  s="B8 04 03 02 01 c3"
  le=len(s)
  i=1
  j=1
  while i<le
    w="0x"+mid(s,i,2)
    print val(w) & " "
    v[j]=chr(w)
    i+=3
    j+=1
  wend

  op=join("",v)

  print "  " & len(op) & " >> "

  for i=1 to len(op)
    print hex(asc(mid(op,i,1))) & " "
  next

  line input z

Charles

JRS

  • Guest
Re: O2 Source ?
« Reply #49 on: July 31, 2011, 12:04:16 AM »
Code: [Select]
s = CHR(0xB8)&CHR(0x04)&CHR(0x03)&CHR(0x02)&CHR(0x01)&CHR(0xC3)

  • 123
  • 0xFF equals to decimal 255
  • 0x255 equals to decimal 597
  • 0X0 is a hexadecimal zero
  • &H52 equals to decimal 82
  • 17#GG is 288

Quote
There is no internal difference between decimal and hexadecimal numbers for ScriptBasic. The lexical analyzer converts both format to internal representation and stores the value of the number. In other words wherever you are allowed to use a decimal number you are allowed to use a hexadecimal number or any radix number as well. You should decide whether to use decimal or hexadecimal or any other radix number for your convenience taking care of BASIC source code readability.
« Last Edit: July 31, 2011, 01:10:29 AM by JRS »

Charles Pegge

  • Guest
Re: O2 Source ?
« Reply #50 on: July 31, 2011, 02:15:03 AM »
Providing the full hex conversion algo on each character: :)

SB Script
Code: OxygenBasic
  1.  
  2.  ' TEST HEXADECIMAL TO BINARY CONVERSION
  3. ' =====================================
  4.  
  5.  
  6.   s="B8 04 03 02  01    c3"
  7.  
  8.   'CONVERT TO BINARY
  9.  '-----------------
  10.  
  11.   le=len(s)
  12.   i=1
  13.   j=1
  14.   a=0
  15.   n=0
  16.   while i<=le
  17.     w=asc(mid(s,i,1))
  18.     if w>96 then
  19.       w-=39
  20.     elseif w>64 then
  21.       w-=7
  22.     end if
  23.     w-=48
  24.     if w>=0 then
  25.       a=a*16+w
  26.       n=1
  27.     else
  28.       if n=1 then
  29.         v[j]=chr(a)
  30.         a=0
  31.         j+=1
  32.         n=0
  33.       end if
  34.     end if
  35.     i+=1
  36.   wend
  37.   if n=1 then
  38.     v[j]=chr(a)
  39.   end if
  40.  
  41.  
  42.   'SAVE BINARY
  43.  '-----------
  44.  
  45.   op=join("",v)
  46.  
  47.   open "t.bin" for output as 1
  48.   print #1,op
  49.   close 1
  50.  
  51.   'LOAD BINARY
  52.  '-----------
  53.  
  54.   open "t.bin" for binary as 1
  55.   op=input(1000,1)
  56.   close 1
  57.   '
  58.  'DISPLAY
  59.  '-------
  60.  
  61.   print "lENGTH=" & len(op) & "  BYTE CONTENT="
  62.  
  63.   for i=1 to len(op)
  64.     s="0" & hex(asc(mid(op,i,1)))
  65.     print right(s,2) & " "
  66.   next
  67.  
  68.  
  69.   line input z
  70.  

Charles
« Last Edit: July 31, 2011, 02:28:44 AM by Charles Pegge »

JRS

  • Guest
Re: O2 Source ?
« Reply #51 on: July 31, 2011, 02:48:55 AM »
Using associative arrays as ASM keywords, the binary string value is assigned. (assembled)

Code: [Select]
MODULE ASM

pop{"eax"} = CHR(0x58)
pop{"ebx"} = CHR(0x5B)
pop{"edi"} = CHR(0x5F)
pop{"esi"} = CHR(0x5E)
pop{"ebp"} = CHR(0x5D)

push{"eax"} = CHR(0x50)
push{"edi"} = CHR(0x57)

END MODULE

Do_Stuff = _
ASM::pop{"eax"}   & _
ASM::push{"edi"}  & _
ASM::pop{"edi"}

JRS

  • Guest
Re: O2 Source ?
« Reply #52 on: July 31, 2011, 03:12:20 AM »
Code: [Select]
  open "t.bin" for binary as 1 
  op=input(1000,1) 

Try ...

Code: [Select]
  t_size = filelen("t.bin")
  open "t.bin" for binary as 1 
  op=input(t_size,1) 

JRS

  • Guest
Re: O2 Source ?
« Reply #53 on: August 01, 2011, 06:36:18 PM »
I guess everyone is stunned and speechless about my associative array ASM keyword emulator. Here are a few advantages as I see them.

  • Reuse of defined ASM keywords
  • Real-time binary image (stitch, load and run) behind keywords
  • Custom keywords (macros)
  • SB does math in decimal, hexadecimal or any other radix number (including binary 0101010)

SB's free form associative arrays should be flexible enough to define the ASM syntax.

ASM::move{"ecx","[ecx]"}

Anyone willing to help me build a ScriptBasic ASM module? (must have good understanding of ASM and Basic)

Charles Pegge

  • Guest
Re: O2 Source ?
« Reply #54 on: August 02, 2011, 01:11:42 AM »

Hi John,

Yes, I've been studying associative arrays. They are an elegant idea but quite expensive to process behind the scenes.

I use quite a few lookup techniques in O2, the main one being hash encoding.

For short lists of around 10-15 words , it is economical to use instr based procedures, placing the most frequently used words first :

Code: OxygenBasic
  1.     m=instr(" mov inc dec push pop add sub mul div cmp and or xor test xchg movsx movzx ",wd)
  2.             '01  05  09  13  18  22  26  30  34  38  42   46 49  53   58   63    69    75
  3.      select case m...
  4.  

Charles

efgee

  • Guest
Re: O2 Source ?
« Reply #55 on: August 02, 2011, 09:23:44 AM »
@JRS
Haven't looked at the SB source but would it not be easier to change the SB interpreter to a VM?

As long Oxygen does not have certain things that SB has you would need to create it yourself, because you need it as native code, don't you?


JRS

  • Guest
Re: O2 Source ?
« Reply #56 on: August 02, 2011, 09:41:50 AM »
The idea is to port O2 to SB as a development environment. A tool to build Basic compilers so to speak.

My first goal is to translate ASM syntax to it's binary image format in but still keep it readable.

« Last Edit: August 02, 2011, 10:45:07 AM by JRS »

efgee

  • Guest
Re: O2 Source ?
« Reply #57 on: August 02, 2011, 01:59:57 PM »
Then this is what you need:

http://ref.x86asm.net/

Charles Pegge

  • Guest
Re: O2 Source ?
« Reply #58 on: August 02, 2011, 02:54:54 PM »

This is the definitive reference for x86 programming:

IntelĀ® 64 and IA-32 Architectures Software Developer's Manual
Volume 2A: Instruction Set Reference, A-M

IntelĀ® 64 and IA-32 Architectures Software Developer's Manual
Volume 2B: Instruction Set Reference, N-Z



http://www.intel.com/products/processor/manuals/

The Assembler has to combine the various bit patterns to create the right opcodes. There are a huge number of combinations. So if you do not want to make a literal translation of o2assm.bas, I would start off with a small instruction set with the essentials like mov add sub mul div push pop

Assembly code follows the 10%/90% rule that 10% of the instructions are used 90% of the time.

Charles

JRS

  • Guest
Re: O2 Source ?
« Reply #59 on: August 03, 2011, 12:48:09 AM »
Quote
Yes, I've been studying associative arrays. They are an elegant idea but quite expensive to process behind the scenes.

I'm not concerned about lightning speed with this ASM scripting extension to SB. My first step is to create an assembly language module in SB that covers the basics. I can use desecrate binary strings for one off code segments. I should be able to add a little C to the mix and run these ASM images in memory.

SB can already interface seamlessly to C functions. Having a ASM extension module that can execute a binary image in memory created by a script should be interesting.