flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > JASM: Java Assembler. Applet + JFrame!

Author
Thread Post new topic Reply to topic
uart777



Joined: 17 Jan 2012
Posts: 369
JASM: Java Assembler. Applet + JFrame!
Image

JASM is an extension of Tomasz's "Assembling JVM bytecode". Features: Minimal macros to create classes, methods, variables, if statements, imports, etc, and this is only the beginning. Includes: 3 examples/templates with .BAT scripts.

Image

Download: Click Here

Console:

Code:
include 'j.inc'

constants
 module MAIN
 string message='Java Assembler'
endcs

class MAIN
 method main(String[] a)
  System.out.println message
 endm
endc



JFrame Application:

Code:
include 'j.inc'

constants
 module APPLICATION
 string message='Java Application'
endcs

class APPLICATION
 method main(String[] a)
  f=1                      ; JFrame f =
  new JFrame               ; new JFrame()
  dup                      ; use twice
  astore f
  calls JFrame.init()
  aload f                  ; f
  ipush 720                ; width
  ipush 480                ; height
  call JFrame.setSize()    ; f.setSize(720, 480)
  aload f                  ; f
  ldc message              ; "..."
  call JFrame.setTitle()   ; f.setTitle("...")
  aload f                  ; f
  iconst_1                 ; 1
  call JFrame.setVisible() ; f.setVisible(1)
 endm
endc



Applet:

Code:
include 'j.inc'

constants
 module APPLET
 string message='Java Assembler'
endcs

class APPLET extends Applet
 method create()
  aload 0
  gets Color.blue
  call Applet.setBackground()
 endm
 method paint(Graphics g)
  aload 1
  ldc message
  ipush 8
  ipush 16
  call Graphics.drawString()
 endm
endc



Description:
Download
Filename: jasm.zip
Filesize: 52.15 KB
Downloaded: 148 Time(s)



Last edited by uart777 on 27 Aug 2013, 03:06; edited 3 times in total
Post 23 Aug 2013, 07:30
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 790
Location: Jakarta, Indonesia
Whoa. Programming in Java bytecode.
This is seriously awesome Very Happy
Post 23 Aug 2013, 13:38
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 6924
Location: ˛                              ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣ Posts: 6699
i think this is kinda cool!
Post 23 Aug 2013, 14:53
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2624
Location: dank orb
I am not familiar with the Java execution environment. Is there a benefit to installing the JDK, or is the JRE sufficient?

Code:
set KIT=JavaSoft\Java Runtime Environment
call :read_key VERSION "HKLM\Software\%KIT%" "CurrentVersion"
if "%VERSION%" neq "" goto ok

...seems to work, but maybe I should also install the JDK?
Post 23 Aug 2013, 19:40
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3172
Location: Denmark

bitRAKE wrote:
I am not familiar with the Java execution environment. Is there a benefit to installing the JDK, or is the JRE sufficient?


The JDK has documentation of the class libraries, a lot of source code, and a Java compiler. If you don't need any of those, don't bother Smile

Oh, might be one other difference - on Windows, the JRE didn't use to include the server version of the JIT, only the client... they have quite different optimization goals. This is why you'd see benchmark differences between Java on Windows vs. Linux, because server JIT is default on *u*x. Dunno what the situation is now, but iirc the JDK always included both.

_________________
Image - carpe noctem
Post 23 Aug 2013, 20:22
View user's profile Send private message Visit poster's website Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 790
Location: Jakarta, Indonesia
JDK is used to compile Java apps from source.
JRE is used only to run Java apps.

I just take a look at the batch files and it seems that JRE is sufficient, because the bytecode generation is done by FASM, and not by Java compiler itself. Smile
Post 24 Aug 2013, 03:29
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
WHY JASM?

* Syntax is customizable, extendable
* Understanding of bytecode which can be executed in hardware by some CPUs (example: ARM Jazelle technology)
* Universal translation to/from X86/ARM/Bytecode, portability in every direction
* Easy alternative to writing bytecode directly
* Fast processing. FASM+IDE is a magnitude faster than javac+Eclipse/Netbeans/etc (JCreator is the only IDE I like).
* For smaller OSs to make a JVM emulator

Learning Java Bytecode

* Oracle's Official .CLASS Specification
* All Java Bytecode Instructions - Wikipedia
* "Mastering Java Bytecode with ASM" .PDF animated slideshows. By Anton Arhipov. His teachings are straight forward and easy to understand
* Jasmine Bytecode Assembler. Oldest, first Java Assembler.

Instructional Videos:

* JVM Bytecode for Dummies (and the Rest of Us Too).
* Mastering Java Bytecode with ASM. Anton Arhipov

Disassemble Bytecode

Try my Java Disassembler package. Click DISASSEMBLE.JS.

Usage: In FILENAME.TXT, just replace the first line MAIN with the NAME of your .class (case-sensitive, no .ext) then click DISASSEMBLE.JS. JavaScript will silently run DISASSEMBLE.BAT (no console), get FILENAME.TXT, try to detect JDK directory, run javac silently to output FILE.TXT, then it displays disassembly in text editor. MAIN.BAT is like a mini-library used by other .BAT files. COMPILE.BAT will use javac to compile MAIN.java (standard) to MAIN.class then run it after. RUN.JS/RUN.BAT just executes.

JASM 2-DO List:

It will take time to do all of this by myself:

* #1. Automatic constant pool, names, numbers and literal text, forward references (somehow). Prevent redefinition and duplication of non-unique values/entries. In the meantime, users must manually create all class/field/method names and indices.

* #2. Type recognition and safety. It should store types/sizes/etc internally and use appropriate instructions

* Error checking. Extremely important. If a macro fails to detect syntax errors, it will generate incorrect code without warning, or even worse, no code at all or the error messages may be totally misleading. An example is a HL IF/LOOP block that always executes once. When this occurs, chances are, macro did not produce code, failed match with no verification. New "syntax" and "verify" keywords to minimize this.

* Names of parameters and locals. In standard bytecode, you refer to locals and parameters by index #. One trick is to create a numeric constant that = index. Example: Replace iload 3 with n=3 then iload n. From here on, n = index #3 until it's reassigned. See APPLICATION.ASM > Font f

* Members and local variables. Example: int a=1, char b='Z', String c='Future JASM'

* Method calls with parameters. Example: aload f | iconst_1 | call JFrame.setVisible() should be replaced with just: f.setVisible(1) Type must be known first. Instance is the invisible first parameter. Example: g.drawString("X", 8, 16) = call Graphics.drawString(g, "X", 8, 16)

* HL assignments and arithmetic: . a=b ; JVM stack-based architecture would make it easy to convert infix expressions with its predefined stack, arithmetic and unlimited "registers".

* HL blocks: .if/.else/.while/.for/.loop/.repeat.

* Imports should be easier and more versatile. Example: import JFrame:setTitle(String)(void), JFrame:setVisible(int)(void).

With these improvements, JASM could realistically be used for serious development with the option to write pure bytecode inside asm-enda (asm {}) block. Preview of what JASM could be:

Image

JASM may be a way for FASM programmers to finally get paid by making Java applications for the Android market (if anyone could find documentation on the internals of .APK).

What if we convert FASM to bytecode? Just the preprocessor+directives, not the actual assembler. Someday, I'd like to create a "Pocket Assembler" + IDE that supports X86+ARM+Bytecode + emulator. Then a HL compiler that generates code for any custom CPUs+OSs. In theory, one could be programming on an Android phone/tablet for WinX/Linux/X360/PS3/etc and vice versa.
Post 24 Aug 2013, 04:39
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
TmX wrote:

Quote:
the bytecode generation is done by FASM, and not by Java compiler itself. Smile

Yes, that's the beauty of it Cool

FASM is the most efficient, powerful preprocessor that I've ever seen, 1,000s of times faster and smaller than M$ compilers (though I wish FASM had a way to load/save/run external files, fsave would be opposite of file 'my.bmp'. Then we could eliminate these .BATs).

A common misconception is that FASM is all about writing X86 assembler. It's not. We don't really need the assembler aspect of FASM that converts instructions, only the preprocessor + directives, that runs before (and while) assembly. We can use db/dw/dd/etc to define unrecognized CPU instructions and OS file formats.
Post 24 Aug 2013, 06:02
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1171
Location: Unknown
Stupid post removed.


Last edited by HaHaAnonymous on 28 Feb 2015, 20:05; edited 1 time in total
Post 24 Aug 2013, 17:50
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4150
Location: https://pastebin.com/Vw7WXXf4
a sort of macro based assembler can be interresting.



in fact, we don't need a compiler with a build in instruction set. but a compiler than accepts a macro include, and let the user write code based only on macros defined before.

the syntax of the operands and the tricks to declare/exploit address is the interresting part of fasm.


Code:

include 'x86.inc'
macro copy a,b {
;a is a pointer to a source table
;b is also a pointer to a destination table
mov ecx,[a];read the first dword (the size of the table)
mov esi,a+4
mov edi,b+4
cld
rep movsd
}

...
mov [buffer+4],PowerSignalColor;set the first pixel to a color
copy buffer1,buffer2
...



Post 24 Aug 2013, 20:48
View user's profile Send private message Visit poster's website Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
Quick logo sketch (5 minutes):

Image
Post 25 Aug 2013, 00:14
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
and of course my awesome DNS filter.

Image


HMM. Really ? Confused Confused
Post 26 Aug 2013, 01:58
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
Zymic (zxq.net) servers went down again Neutral So, all of my images and downloads disappear until they restore. Wait about 1-4 days. A server from my own PC (I32 netbook) is impossible because I don't have my own internet service (use neighbor's and nearby WIFI modems).
Post 26 Aug 2013, 07:03
View user's profile Send private message Reply with quote
questlima



Joined: 27 Aug 2014
Posts: 37
is that writing java in assembly this is awesome tho i have never tried to understand java anyway thank you

_________________
Linux command are not what you intended to
learn but your were forced to learn it, without it
you will be like a sitting duck on your beautiful newly installed Linux desktop:)
Post 28 Aug 2014, 11:23
View user's profile Send private message Reply with quote
jiangfasm



Joined: 08 Mar 2015
Posts: 56
I can't download, could you give a new address??
Post 12 Jul 2015, 13:51
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000

jiangfasm wrote:
I can't download, could you give a new address??



Wait until he pays his bills. Or you can simply donate $100 to my PayPal account.
Post 12 Jul 2015, 23:39
View user's profile Send private message Reply with quote
filox



Joined: 13 Feb 2013
Posts: 10
Hi uart777,
is there a Linux version of your environment?

It is possible to make a version for all OS so?

I think the problem is the "CASE INSENSITIVE" methods including files....

Many thanks
Post 07 Sep 2016, 14:45
View user's profile Send private message Reply with quote
TheRaven



Joined: 22 Apr 2008
Posts: 73
Location: U.S.A.
Anyone try this with .Net byte code yet?

At any rate, nice project here uart. This stuff should be interesting.
Post 10 Sep 2016, 18:57
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.