It is currently Sat Oct 21, 2017 8:03 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Tue Aug 09, 2016 11:57 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7233
Location: Chexbres, VD, Switzerland
psycopathicteen wrote:
I'm still confused on what Bregalad said.

What I meant is that his example code could be changed from:
Code:
        ; put $1234 on the stack
        lda #<$1234
        sta STACK0, x
        lda #>$1234
        sta STACK1, x

        ; put $1337 on the top of the stack
        lda #<$1337
        sta TOS
        lda #>$1337
        sta TOS+1

        jmp add2


To something like
Code:
      jsr Pushconst
      .dw $1234
      jsr Pushconst
      .dw $1234
      jmp add2


Or even better, don't even use the "jsr" and have a bytecode interpreter, and then it would reduce to
Code:
     .db PUSHCONST
     .dw $1234
     .db PUSHCONST
     .dw $1234
     .db ADD2

Where constants like PUSHCONST and ADD2 are single byte instructions that gets intepreated.
Quote:
I imagine it would work like in Sweet16. Sweet16 is a virtual assembly language.

Note quite. Sweet16 is based on a register machine, not a stack machine.


Top
 Profile  
 
PostPosted: Wed Aug 10, 2016 1:35 pm 
Offline

Joined: Sun Jan 31, 2016 9:55 pm
Posts: 31
Yes, Sweet16 is a register machine, but it is similar in that it uses an interpreted byte code.

The reason I didn't go for byte code is because of speed -- an interpreter would have a lot of overhead, especially if the instructions are different lengths because of constant loads. I did experiment with making a fast interpreter using self-modifying code. An interpreter would also have to implement branching and subroutine call instructions, while direct code can just use the 6502 branching instructions.

It is possible to have the best of both worlds, however. An interpreter could be bolted onto a system like I described. It would read the byte code and translate it into calls to the stack machine functions. The compiler could selectively compile functions into either byte code or function calls. Apparently, the PLASMA language for 6502 already does this -- each function can be compiled to byte code, calls to the interpreter, or even directly to assembly, depending on how you want to trade-off speed and size.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group