This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Your Projects subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Project Ideas/Start New Projects => Your Projects
Author Message
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 26 Mar 2009 11:02:01 am    Post subject:

Java for ASseMbly is a project that I thought about working on for a while. First off, I do not know much about assembly :confused:, and have tried it before, but I get so confused on some of the topics Cool . Basically, what would happen, is that there would be a compiler that would turn the JASM code into asm code. In java, each line of code is ended with a ";", but in assembly, it is not necessary, so the compiler could tell the difference between java and asm.

As for how the java would be converted to the asm code, it wouldn't. In java, you can use other people's classes, to make your code better, or because you don't want to have to write out a function for something every time. So, what I was thinking, was that you could have classes be interdependent upon each other. Say I have this java Method:

Code:
Public void HLtoDE(HL) {
    ld HL,DE
}

Wherever I put that method, the compiler would translate that method into "ld HL,DE". However, if it was say an object that the method was called from it, then it would store it as a function, that would be like something you "call" in asm. When you created the object, before you called the method, the constructer method would create a form, and the name of the object would be the pointer to the address for it, (which would be turned into the actual byte codes when TASM translated it. Anyway, when the method is called, any object variables that would be accessed in the method, would be changed to HL+ wherever the data was located. (I hope that last paragraph was confusing enough, how about an example?)
Say I have this JASM class for an object:

Code:
public class MyObject {
public int myvar1;
public int myvar2;
public MyObject(int HL,int DE) {
    myvar1=HL;
    myvar2=DE;
}

public void MyMethod() {
     int tempVar = myvar1;
     myvar1=myvar2;
     myvar2 = tempvar;
}

}

Okay, so that was my object, and here would be my JASM file:

Code:
ld HL,00
ld DE,$FF
MyObject object= new MyObject(HL,DE);
object.MyMethod();

and the compiler would translate it into this:

Code:
#define tempVar .equ AppBackupScreen
ld HL,00
ld DE,$FF
ld object,HL
ld object+1,DE ; So far, it has been the constructer method
call MyMethod ; now to call the method
MyMethod:
ld tempVar,object
ld object,object+1
ld object+1,tempVar

object: ; yep, it's the object.
.db $00,$00


That is the basics of how it works. If you have any questions, just ask. I can see people going crazy now... My mind... What did you do with my mind...
Back to top
calc84maniac


Elite


Joined: 22 Jan 2007
Posts: 770

Posted: 26 Mar 2009 01:56:50 pm    Post subject:

Give me an example that uses valid ASM commands, plzkthx.

For one thing, DE and HL are each 2 bytes, but your variables are one byte.

Also, you need parentheses around references to memory (aka your variables).

One more thing... you can't directly load one "variable" into another. You must load it into a register first, then from the register into the destination.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 26 Mar 2009 06:21:51 pm    Post subject:

As I said before, I don't know how to program asm very wel. I was just saying as a example.
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 27 Mar 2009 01:22:57 am    Post subject:

Well, I'm afraid that if you learn asm, you will leqlize therevis no way java could ever be translated into usable z80 assembly code...sorry to burst your bubble Sad But good news is, if you work at learning assembly code for real, you can do much awesomer stuff Very Happy
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 27 Mar 2009 08:01:00 am    Post subject:

That's why I said in the first post that it wasn't translating java to asm, If you read it, although there are some errors in the asm because I can't program asm. You would have realized that the java methods would be made up of asm. It would be possible. I just need help with the asm part.
Back to top
WikiGuru
ADOS (Attention deficit... Oh! Shiny!)


Elite


Joined: 15 Sep 2005
Posts: 923

Posted: 27 Mar 2009 02:16:31 pm    Post subject:

Here are some flaws i see with doing something like this:
1. Methods in java have there own workspace. In z80, there is only one workspace, and everything operates on more or less the same level. To implement something like what java (or most higher level programming languages) does with the scope and lifetime of variables/objects would not work if you were writing z80 code in the methods. Implementing objects would be even more taxing on the z80 processor, and much harder to maintain (especially since in assembly you pretty much have access to everything)
2. Translating a higher level language to assembly has always been inefficient. The reason we do it with computers is because projects are massively huge, and the computational power and storage capacity of your pc is vastly superior to the TI calculator, and thus these inefficiencies are for the most part negligible. In z80, many times these deficiencies are not negligible (especially size), and programs are small enough the benefit of higher level languages usually don't outweigh the consequences.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 27 Mar 2009 04:09:36 pm    Post subject:

Let me make myself clear. It is not java translated into assembly. It is the basic syntax of java, but it is ported for the z80 processor.

As for objects, the z80 processor wouldn't maintain them as a virtual machine. Instead, say I had a JASM object that used 4 bytes to store an object. The first byte is the x pos, the second byte is the y pos, and the third and fourth are the address for the start of the text. Well, the JASM object code might look like this:

Code:

JASMObject {
byte xpos;
byte ypos;
word string;
     JASMObject(byte x, byte y, word stringref) {
     this.xpos = x;
     this.ypos = y;
     this.string = stringref;
     }
}

This is the test class with the main() method:

Code:

Test {
     Main(String args) {  // Whatever you want in ans.  Can be empty
          // Code to take the x position, the y position, and the rest of the string is left out for space reasons.
          // Just know that the x position is stored in xpos, the y position in ypos, and the string is in string.
          JASMObject myobject = new JASMObject(xpos, ypos, string);
     }
}

The JASM compiler would change it into something like this: (Note: I do not know ASM, so this is just a demonstration on what, basically, the compiler would translate it to.)

Code:

xpos .equ AppBackupScreen
ypos .equ xpos+1
stringref .equ ypos+1
; Note, since I don't know asm, the code to retrieve ans, and parse it is left out.
; Just know that the JASM commands that I used to parse the string would be methods
; that would get translated to the appropriate z80 asm code.  That is not the point of this post.
; just know, that those values are now stored into the "xpos", the "ypos", and the "stringref" variables.
; (In all technicality, the string is stored at the "myobjectstring" place, but the reference is in "stringref:
; I don't know exactly how to do this, so here goes...
    ld (myobject),xpos
    ld (myobject)+1,ypos
    ld (myobject)+2,stringref ; I don't know about two bytes though... not the point in this demonstration.
myobject:
.db $00,$00
.dw $00000
myobjectstring: ; specifically put the object name in front of it due to duplicate objects.
.db "this is not really my string, but it is just for the example.



Sorry about all the comments. I know this wouldn't be the exact translation, but then again, it is not really java, but JASM. It just has the basic java syntax. I could use WikiGuru's help with the asm part. As for writing your own classes, anything that you want to do in asm, simply do not abbend a semicolon to the end of the statement. Otherwise, it would be JASM code.
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 27 Mar 2009 09:44:34 pm    Post subject:

I don't understand what you're trying to do here. On the one hand you're saying that you wouldn't actually be compiling Java into assembly, and on the other hand you're talking about objects with variables and such.

Could you write a compiler from Java-the-programming-language (or from some simplified subset) to Z80 assembly? Of course you could. Would it be difficult? Yes. Would it be useful? Perhaps. Would the result be better than TI-BASIC? Hard to say.

Writing a compiler is certainly an interesting project, and quite a challenging one. To do so requires a very good understanding of both the source language (Java, or whatever subset interests you) and the target language (Z80 assembly, and by extension the internals of the TI calculators and their operating system.) A compiler is an incredibly complex program, miserable to debug and extremely unforgiving of errors. Not a project for newbies by any stretch of the imagination!

(In other words: if the problem is that you don't understand assembly very well, writing a compiler is not a solution. Unless you're figuring that trying to write a compiler would somehow motivate you to learn vastly more about assembly than you do now.)
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 27 Mar 2009 10:15:07 pm    Post subject:

Actually, I will be writing a compiler, but I won't write much asm code. Instead, the programmer will. That's correct, you will. After I make the basic things, writing your own code would be more than easy. If I remember the pm correctly, then I think wiki guru could help with the asm
Part.

I just wanted your opinion. Would you use it?
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 27 Mar 2009 10:18:58 pm    Post subject:

So, is this intended to just let people write direct assembly code in a java-ish format? If so....I don't even know what to say Razz It's a confusing concept, for sure.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 27 Mar 2009 11:06:18 pm    Post subject:

Well, yes and no... People don't really need to program in asm, but they can. Most people will write in jasm format. I just want to know if it would be worth my time to do this. Would you use this?
Back to top
FloppusMaximus


Advanced Member


Joined: 22 Aug 2008
Posts: 472

Posted: 27 Mar 2009 11:42:41 pm    Post subject:

Um. You can't write a compiler without writing some assembly code. And while you're not being very clear about what the source language here *is*, I assure you that you can't write a compiler for a halfway useful language without writing a substantial amount of assembly code.
Back to top
Galandros


Active Member


Joined: 29 Aug 2008
Posts: 565

Posted: 28 Mar 2009 03:22:29 am    Post subject:

Well I wouldn't use it.
First I don't know Java. Second using a Java syntax to do exactly same thing as macros and defines doesn't really worth. That is the easy part of assembly.

This is my opinion what I think being your objectives.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 28 Mar 2009 08:00:40 am    Post subject:

well, you would be taking advantage of the object part of java. Never mind... It is too hard to explain...
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement