Assembler Compiler In Bash
sTeF writes "This guy is crazy, he wrote an assembler totally in Bash. After all those awk/sed/ps httpservers this is the next crazy step. what's next? a virtual machine in Bash? anyhow here's the url to the source."
← Back to Stories (view on slashdot.org)
I'm guessing you just fell off the boat yesterday. While the current jvms are a bit faster than some of the previous ones they are still slower than their non p code counterparts. I for one am tired of hearing the bs from zealots like you who have probably never done any real coding and think java is a god send. It has it's points but it is hardly the end all be all so many make it out to be.
Assembly language is NOT machine code, so it does need a compiler to turn it into Machine code. Thats what this is, its a compiler for assembly language.
Assembly language is pretty much a straight one for one conversion into machine code, but the assembler does do things like, convert labels into relative jumps. Things like that are a real pain when you are coding in straight Machine Code.
-- Hulver's site
Why? The single-quote is not a special character to a Unix filesystem. It may be special to the shell, it's true. So change your shell? Or just use the facilities in the shell for dealing with this. I have files with single-quotes in. I don't find typing \ or enclosing the name in double-quotes to be appallingly hard work.
My guess is it's just slashdot effect, and the problem is that the quota for simultaneous anonymous connections is exceeded. Or the sysadmin was so horrified by the number of people hammering on her server that she disabled the anonymous acct. altogether. Wait 24 hours, it'll be ok -_-
Irritable, left-wing and possibly humorous bumper stickers and t-shirts
Don't laugh, you just know SOMEBODY in the slashdot reading audience saw jawtheshark's post and started writing a oneline perl assembler immediately -_-
(hell.. whenever i can get through to the /.ed ftp server, i'll try to write one myself.. :)
Irritable, left-wing and possibly humorous bumper stickers and t-shirts
sed and awk aren't part of bash.
I will not rest until I have a 36 bit operating system written in base. TOPS-10 ALL THE WAY!!!!
-- "In order to have power, I must be taken seriously." -Mojo Jojo
Just think what would have happened if Linus decided to go for a walk instead of hack!!! Flood. Famine.
Indeed, on some processors the assembler does even more including expanding one assembly instruction into multiple machine instructions. On a MIPS for example there's even a register reserved for the assembler ( at - assembler temporary) to use when expanding instructions.
Enjoy your job, make lots of money, work within the law. Choose any two.
Clearly the ultimate would be bash in bash.
It appears that the IP address for www.slashdot.org (and just plain slashdot.org) changed in the last 24 hours or so - my nameserver hadn't sync'd up with the change until sometime yesterday afternoon. But people on other name servers were apparently able to connect just fine. I must have a slow nameserver here...
- Mike
Once I wrote a plot program for an HP71B, a handheld computer, in that machine's dialect of BASIC, which would print out lines and arcs (land survey drafting) on their weirdass inkjet printer - took about an hour per 8-1/2" x 11" page...
Unlike these cheat-o-matic languages in popular use these degraded days, which basically run way too God damn fast for you ever to win, BASIC is a sporting language, plays fair, gives you the competitor at least a chance to keep up or even surge ahead and break the ribbon, with nothing more than a pencil and paper and your own slow brain as a processor.
Yours WDK - WKiernan@concentric.net
Why can't we just define what an assembler is ? It would be much easier. An assembler assembles assembly. Simple. Anything that does not do this is not an assembler.
Now your definition of an "assembler" is "a program that translates assembly language into object code"; you still leave "assembly language" undefined. The task of defining asm precisely is complicated by the virtual machines that exist on several levels:
All your hallucinogen are belong to us.
Will I retire or break 10K?
Common practice where I work is to call programs that convert assembly into machine code assemblers, and programs that convert high level source (C,Fortran) into machine code compilers.
Scheme and Perl advocates would say that C and Fortran aren't much higher level languages than assembly; thus the common joke about C compilers being PDP-11 assemblers. I still haven't seen a hard distinction made between "an assembler with a rich macro language" and "a compiler."
All your hallucinogen are belong to us.
Will I retire or break 10K?
The idea is to try to make a porttable ( to an extent ) assembler so asm written on one Arch can port easily to another.
C source code is pretty close to a portable assembly language, source-compatible across any conforming ANSI C compiler. Jasmin (Java virtual machine assembly) is even binary-compatible across Linux/x86, Solaris/SPARC, Mac/PowerPC, and Windows/x86.
All your hallucinogen are belong to us.
Will I retire or break 10K?
It is a matter of semantics, but compilers typically convert a high level language into assembly which is then assembled into the binary machine code.
Common practice where I work is to call programs that convert assembly into machine code assemblers, and programs that convert high level source (C,Fortran) into machine code compilers. Interpreters are the third way to get text to turn into machine code, although they are usually based on compilers (script->C source->object).
Summary
Assemblers - 1 to 1 conversion of keywords to object code
Compilers - keywords often result in many lines of object code
Interpreters - statements are compiled and run as they are being entered.
Remember, You are unique...just like everyone else.
Java only undergoes pseudo-compilation. Even after it is compiled, it is still only in byte code, which must be interpreted. This wonderful combination of a compiled/interpreted language brought to you by Sun makes for incredibly slow runtime versus purely compiled languages. While it's not required to be knowledgable to post on slashdot, it really should be a prerequisite for reprimanding someone on misinformation.
--- What
How about a java virtual machine written in bash. Would that be slow enought?
No, how about something like a PDP-11. Any other ideas?
This sig intentionally left blank.
Yeah, it's kind of like that Linus guy who wanted to learn about the 386. Just look at all the time he waisted on another version of UN*X.
This sig intentionally left blank.
Anyone that puts a single-quote in a UNIX filename needs to be shot.
Anyone that pluralizes CPU with a single-quote needs to be shot.
(I am referring to the directory named sh.asm/CPU's in the tarball.)
This is not a Fugazi
>So you can write a driver in a HLL huh? umm yes.
;)
Erm, let me rephrase the question...
So you can write a driver in a HLL without relying on libraries or LowLevel calls? (think about it..also asm directives don't count)
>So you can code a routine to a certain byte size in a HLL? if you have to
Maybe, but you've still got section padding which still adds bytes...
>So you can code a routine to execute in a certain number of cycles in a HLL? can you in asm? think about it.
Actually yes. every instruction has a cycle count, and any out of order execution or pipelining can be countered using simple optimizing trix.
>Is it pointless to squeeze the last bit of performance from a routine?
You didn't answer the question....
>i think you are asking the wrong questions. i think you should be asking:
Am I a fag? no
Do I have any idea? plenty. I am a regular contributor to a rather large open-source project (xmame/xmess) so that probably gives me an idea or two
Should I kill myself? Wrong question, because I am on a course of antidepressants at the moment to stop me from thinking about exactly that.
Next....
There's not enough space inthis little box for a diatribe, so here's a few links for x86 assembly language programming:-
www.hugi.de Windows based (linux ver on its way) assembly diskmag with plenty of articles on the advantages and disadvantages of ASM vs HLL
www.x86.org loads of info about x86 programming
www.cfxweb.net Loads of articles on assembly programming and HLL too.
Hope that clears a few things up *g*
Bash (bæsj) means poop in Norwegian!
Here's a standard mirror of the beast, since (as posted earlier), the site has a limit of 60 anonymous connections, and I didn't notice any mirror that wasn't FreeNet based.
HTTP: http://www.bluecherry.net/~rain/shasm.tgz
FTP: ftp://ftp.bluecherry.net/pub/misc/shasm.tgz
Our FTP server has a limit of 15 anonymous users, so I'd highly recommend using the HTTP mirror unless some BOFH firewalled port 80 outbound. (I've seen it happen!).
--
Ben Winslow..........rain@bluecherry.net
bluecherry internet..http://www.bluecherry.net/
We've had intereactive C for a while now, interactive assembler seems a reasonable extension... hmmm interrupt latency is what, 3-4 days?
The guy who wrote this Colorg (Rick) , also maintains cLIeNUX (Client orientated Linux) and was awarded the Efnet #Linux "King of the Geeks" crown a few days ago for SH.ASM. I've had a look at the code.
The idea is to try to make a porttable ( to an extent ) assembler so asm written on one Arch can port easily to another.
The cool thing about this is it only needs Bash. no other external utils.
Tre Geek Cool
At the moment not all the instructions are support and it doesnt do Elf and A.out - Only flat listings
the difference between assemblers and compilers
For the newbies who can't understand what we're talking about:
'Assembler' used to mean both the mnemonic 'language' that coincided with machine code (the actual ones and zeros that hardware understands -- sort of) and the program that turns that language into a form that the linker needs to produce the executable.
'Compiler' is a program used to 1) scan the source code looking for keywords and other constructs in the language in question, substituting 'tokens' and making entries into a symbol table. 2) produce meaningful error messages concerning syntax. 3) parse the result determining the meaning of the program, sending this information to a 3) code generator and optionally to a 4) code optimizer. That's a very simplistic definition and one that's not necessarily 100 percent correct for all programs calling themselves 'compilers'.
The current trend of calling assemblers 'assembler compilers' grates against my sensibilities too.
'Intellectual Properties' are uncontrollable in the wild. To base an economy on them is just stupid.
Well, we used to have lisp machines. So, a self booting bash would just make for a bash machine. All programs would just be bash macros that get called from the command line. All storage would be scalars, arrays, and associative arrays. For persistance, bash would need to modified to save it's state to disk, but that would probably fit on a floppy for most people.
I'm a loser baby, so why don't you kill me.
Someone has had a bad experience of the Admin Horror Stories kind, rm-rf/ and the like?
I've done a little bash programming, and I've also written a compiler (in C), and it would seem to me that writing an assembler would not be especially difficult in bash because the langauge contains very good string manipulation utilities (sed, awk, etc.). As one poster mentioned, assembly maps very well to machine code. Building in support for assembler macros could get tough, though.
Now, if you were to try and write a 3rd generation language compiler (such as Pascal) in bash, you might get into trouble fast. This would require some very extensive control and data structures that bash doesn't support as well as, say, C. I'm not sure bash has multidimensional arrays or pointers, and these make constructing things like symbol tables a lot easier.
Still, I would say this guy knows a lot more about bash than I do, and there is probably something I am missing (since I can't read the source right now).
Good thing the Slashdot editors are calling non-coders "l4m3" in the poll this week, since they're SO clear on the difference between assemblers and compilers....
--
the next crazy step
bash in assembler.
By the way, that would make bash self booting ...
---
recursion, n: see recursion.
RFC1925
...many moons ago, my 3rd year AI prof asked us to hand in a solution to the `Blocks World Problem' in any language we wanted to. (Of course he actually wanted a solution in Lisp, but I had just finished hacking some extra functionality into Emacs and was sick of that language)
;-)
I turned in a solution in ksh. He asked me "Why Ksh??", and I said "It doesn't fork to run functions like the bourne shell." Hee hee! I love given right-wrong answers to profs.
A few weeks later I wrote a normal-math to RPN-math parser in Bourne shell using the Shunting Yard algorithm.
You can do all kinds of things in shell -- for those of you among us who extoll p*rl as the be-all and end-all of programming languages, I say, "Try Shell! If you can't do it in shell, you should be writing it in C, anyhow".
--
Do daemons dream of electric sleep()?
You don't need to build anything on the machine-to-be-h4x0rd if you know the target architecture -- which you must if you're going to write your 31337 buffer overflow 3xpl017 in assembler.
Anything which can generate binary from your telnet connection will do -- I've transfered binaries from one system to another by cutting and pasting them in base64, or escaped octal before. Hell, there are even special t00lz designed for transfering binaries which are often available on the target system.. Lets see... I think they are called "ftp", "rsh", "ssh", and other funny nam3z like that.
Yeesh. You people are idiots. Sysadmins beware? Puh-lease.
No 5cr1pt k1dd13 is going to be writing custom one-offs in assembler on a target box.. after all, the 5cr1pt k1dd1e collective IQ is somewhat near the value the ax register holds after xor ax,ax.
No skilled cracker is going to need this tool to do the deed, although it might be handy to have around.
Next time, think before you speak -- alarmism is not useful. If you weren't posting as an AC, I'd think that you were almost certainly trying to a frist psot karma-whore trick.
--
Do daemons dream of electric sleep()?
Now we just need an assembler written in perl! Everyone knows that will be the more elegant code ;-)
Ahhh...the great dumpster continuum. Many a free computer will be found there. -- sowth (748135)