Assembler Compiler In Bash 126
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."
Re:Let me guess... (Score:1)
rm foo*.eps bar*.eps
fortunately he had a (one day old) backup. It's not exactly an admin horror story, but he knew the root password (his machine).
Re:Java, or... (Score:1)
The poster said " How about a java virtual machine written in bash. Would that be slow enought?".
Was the poster correct saying it would be slow. Yes!!! Guess who is the troll?
Hardcore math (Score:1)
Actually (Score:1)
Re:'Assembler Compiler?' (Score:1)
The mnemonic language is better known as assembly, while the word assembler indicates the translator.
Re:Cut to the chase (Score:1)
:)
1st Law Of Networking: Loose ends are bad, termination is good.
Re:time for a time-out (Score:1)
Re:shasm (Score:1)
The guy who wrote this Colorg (Rick) , also maintains cLIeNUX (Client orientated Linux)
Is he the guy that started that huge flamewar by suggesting that /bin, /etc, etc. be renamed to /.bn, /.et etc. to hide them, and then adding symlinks like "/Binaries -> /.bn". What a weird bloke.
Re:How about (Score:1)
Those nutty Amiga people...
y
Re:Java, or... (Score:1)
Oh come on, everyone knows that Java running under Bash is slow. But when bash is running on Linux it's faster than everything else. In fact, it'd be so fast, it'll finish compiling even before you finish writing the code.
What we're all waiting for is the JVM in E-macs. That'll be the day. :-)
ticks = jiffies;
while (ticks == jiffies);
ticks = jiffies;
Re:'Assembler Compiler?' (Score:1)
Re:Next step (Score:1)
:)
Re:Who cares? (Score:1)
Machine code is another language. You could even program in it if you felt the masochistic urge. It is a language that is interpreted by a microprocessor. I am perfectly aware of what is normal terminology in "the trade." But compiler is also a computer science term that is much broader than the original poster indicated. A lot of terms in "the trade" change pretty frequently (for example, try to define "operating system" in a manner that cannot be debated). So I don't see the point of jumping on someone because of some terminology usage just because it offends some arrogant programmer.
Who cares? (Score:1)
Get off your fsking high horse. The definition of a compiler is a little more broad than what you've given.
A compiler takes something in language source and translates it into its equivalent in language target. Language target is commonly machine code. However, language could be something like assembly code, C code, or even a TeX DVI file (tex has rightly been called a compiler).
What's the big deal if source is an assembly language instead of a high-level language? Yeah, you might want to be more specific and call it an assembler, but by the accepted definition of a compiler it is in the domain of compilers.
Now, consider your definition of a compiler:
Basically, an assembler is a compiler by my definition and your definition. So stop the elitist arrogancy because you think you know what is and is not a compiler unlike the so-called uneducated masses.
Re:huh? (Score:1)
Instead of a shell script that converts C code to machine language. Yes, it would require other atomic pieces (sed/awk) but the shell script would do the conversion.
Who is the author? (Score:1)
Re:Next step (Score:1)
Okay, so 'Hello world\n' took 20 minutes to compile...
Re:'Assembler Compiler?' (Score:1)
Not the first one (Score:1)
I'm glad to see I'm not the only weirdo out there. Be creative! Think about what your tools *do*, not just how everybody else uses them. Has anybody else tried doing DHTML in m4?
that's nice... (Score:1)
implement BASH itself in a SH script (Score:1)
f C compilers are written in C why not write a BASH interpreter using BASH...
that'll probably be about 100 times slower than the original BASH, so you can even run SHASM in this new thing and get a 10000 times slower assembler..
which will be cool of course
Re:time for a time-out (Score:1)
echo "Shell-script is not an effective tool for complex programming tasks."
done
Speaking of asembly (Score:1)
Re:Who cares? (Score:1)
Machine code is another language
Its not!!! That's my point MC and assembly are the same thing! Two different representations of the same thing. Define 'programming' in machine code and you will discover that I can argue that what you are really doing is programming in some symbolic representation of 'machine code'. '0x90' is no more machine code than 'nop' but we don't call it that. Think of an assembler more like a text to speech software rather than a babblefish like translator.
< RANT sorry... >
I understand that you can take the definition of compiler to include assemblers. Your argument about definitions changing is bogus. Rarely do we take a broad definition and use it to cover specific instances when we are trying to be specific. Sure definitions get broader. Name something that was part of the definition of an OS in 1980 that isn't currently part of at least one piece of software generally accepted to be an OS! Broad definitions often extend themselves. When I say "EPROM" I don't have to say "ROM EPROM" its assumed and understood that EPROM is a ROM. When I said memory 10 years ago, that meant DRAM, SRAM, assorted XXROM's. Today memory is all that it was in 1991 but we have additional descriptions like SDRAM, RDRAM, DDR, and assorted other 'new' things.
You have a valid point about jumping people for terminology, but why do we teach grammar? Its because having a standardized method for expressing something aids in understanding. It is far clearer to call it an 'assembler' than a 'assembler compiler' even though it might be correct by the definitions of a compiler. Which as other people pointed out is actually incorrect, an assembler is the 'compiler'. To be correct, in ones terminology it is really an 'assembly compiler'.
<
Re:Who cares? (Score:1)
This is precisely why its not appropriate to call an assembler a compiler. Its not technically a language translation. Its rather a symbolic conversion. The language is, for the most part, 1:1 between the human readable symbols and the machine readable symbols. Assuming x86, "NOP" is exactly 0x90 all the time and 0x90 is exactly NOP all the time. Early assemblers were simply advanced search and replace engines. Early compilers still had scan, parse, code generation, and in some cases an optimization pass. Sure you can construe an assembler into a compiler but its really a subset of a compiler because many of the compiler requirements aren't really needed with an assembler. If your going to call an assembler a compiler you might just as well call the disassembled dumps from your favorite debugger "decompiled code".
Calling an assembler a compiler is not acceptable for someone in the trade. Its acceptable for a layperson to not understand the differences just like it is acceptable for them not to completely understand the differences between flash, PROM, EPROM and RAM.
Now to support another view point. Using your definition of a compiler what is the difference between a compiler and a cross-compiler? There isn't any is there? Well then how do we distinguish the difference. What about java then, which is (as far as I'm aware there still isn't a true java machine that support the whole spec) always a cross compiler or maybe just a tokenizer. Maybe the whole thing has to do with language! You express and idea with the understanding the audience you are expressing it to understands the basic premises of your topic. Now on
Big Deal (Score:1)
Re:Speaking of asembly (Score:1)
Re:You are mistaken, Dumass! - No, you are! (Score:1)
Three possibilities:
1) Hardened militarized versions of the chip were discovered and used in the bender units,
2) The 6502 was reversed engineered from surviving copies of 'Attack of the Mutant Camels'
3) The templates used in the manufacture of 6502s were discovered and reused.
Re:I Guess they beat the Emacs people (Score:1)
Now for those of you thinking -- wait, isn't that a compiler? -- remember that the bytecode compiler has a lower level section that you can use as an assembler, which again points out that with LISP you can do anything, and make it look the way you like, as long as you like lists
I *love* EMACS... I love LISP even more.
Re:Interactive assembler -- already done (Score:1)
MS-DOS since v 1.0 has included Paul Allen's DEBUG.COM . IMHO, this is the unsurpassed high-water mark of MS's products.
DEBUG.COM (now DEBUG.EXE) is remarkably interactive. It has a built-in miniassembler and disassembler and is remarkably interactive in use.
Re:PerlOS (Score:1)
IIRC I had heard that there is someone, somewhere, merrily hacking away writing PerlOS (complete with device drivers, of course.)
all right! (Score:1)
You've truly inspired me. I think I'm going to write an OS in QBasic now!
Getting SHASM (Score:1)
Ed.
Re:Disassembler would be better. (Score:1)
Re:'Assembler Compiler?' (Score:1)
Re:LOL (Score:1)
borg (Score:1)
(Sorry--Couldn't resist)
let's hear it for turing-completeness (Score:1)
Joe Ganley
ganley.org [ganley.org]
C++ Compiler in XSLT (Score:1)
Go G! (Score:1)
Re:'Assembler Compiler?' (Score:1)
[...]
Moderators: copy/pasting text from the site a story links to isn't "Informative," it's "Redundant."
I don't know, but don't you think someone else is being really really pedantic?
Re:Bullshit (Score:1)
I know him, and he is.
--
How about (Score:1)
Re:Slashdotted ftp (Off Topic!) (Score:1)
Re:Slashdotted ftp (Off Topic!) (Score:1)
Re:hee, hee, hee (Score:1)
Really ugly.... (Score:1)
Long time ago, an anonymous hacker where I worked did a fortran compiler in TECO. Someone else started to (re)write system utilities in Teco, as well (like SYSDPY on the PDP-10.) Nice hack....
Re:Bullshit (Score:1)
Re:Getting SHASM (Score:1)
Nope, just slashdotted. Maximum of 60 anoyn connections. I've provided a mirror on Freenet [freenetproject.org]; see another post.
------
Re:Slashdotted ftp (Score:1)
I have provided this mirror on Freenet [freenetproject.org]:
KSK@/slashdot/mirror/shasm.TGZ [freenet]
The direct CHK is CHK@CZMmKmFfPIBICsilSsDybTofi1oOAwE,cNNb4iRSoRGynx ANzqhByQ [freenet]
If you have Freenet node and a plugin for your browser that can understand freenet: URIs, you can click the above to get it. Otherwise, go to www.freenetproject.org [freenetproject.org] and download and install Freenet. Then request the key.
------
Freenet Mirror (Score:1)
I have provided this mirror on Freenet [freenetproject.org]:
KSK@/slashdot/mirror/shasm.TGZ [freenet]
The direct CHK is CHK@CZMmKmFfPIBICsilSsDybTofi1oOAwE,cNNb4iRSoRGynx ANzqhByQ [freenet]
If you have Freenet node and a plugin for your browser that can understand freenet: URIs, you can click the above to get it. Otherwise, go to www.freenetproject.org [freenetproject.org] and download and install Freenet. Then request the key.
------
Re:How about (Score:1)
Amiga Virtual ASM is, if you can really call it "assembly". In any case, OO is really something better left for high-level work.
------
Re:huh? (Score:1)
By that logic I could make a C compiler by just making a bash script that runs gcc...
--
Re:Slashdotted ftp (Off Topic!) (Score:1)
My suggestion was a compromised server, since
the trace stopped dead somewhere in the states.
Hmmm...
Re:Critic (Score:1)
What about XFree86 4.0.2 ? Get the darwin distribution at xfree86.org then the rest from http://mrcla.com/XonX/
Now that I have completed your life, could you refrain to post garbage ? A bash assembler is just awsome...
Cheers,
--fred
rtfm? (Score:1)
time for a time-out (Score:1)
Now, take this pencil and pad of paper and go sit in the corner. Write the following line 1,000 times:
Shell-script is not an effective tool for complex programming tasks.
------
Life would be better and Linux would have far fewer bugs if we could somehow force this time-out on lots of other folks too. Case in point: teTeX.
Re:I Guess they beat the Emacs people (Score:1)
If by "beat the Emacs people" you mean, "Invented something needlessly slow to perform a task which is already better-performed elsewhere", then you are wrong. Emacs has been doing that since its inception.
--
ALL YOUR KARMA ARE BELONG TO US
Re:huh? (Score:1)
Duh. But you're still missing the point of my post, which was to say that no app in unix is intended to stand alone. The whole IDEA of Unix is that you can string your commands together; Implementing something solely in bash is the right way to do it if it's the fastest and/or easiest, but if using sed and/or awk would have made it easier, then doing it without them is contrary to the lazy* [slashdot.org] nature of Unix.
* This is, of course, the type of laziness made famous by Larry Wall.
--
ALL YOUR KARMA ARE BELONG TO US
Re:huh? (Score:1)
When I started this sub-thread (way up the tree from here) I wasn't saying I didn't get it; I was saying that it was pointless and unnecessary, and I was attempting to explain why.
HTH, HAND.
--
ALL YOUR KARMA ARE BELONG TO US
Re:huh? (Score:1)
Ah, grasshopper, you are missing the whole point of Unix - The pipe. Everything on Unix is [intended to be] part of everything else.
Remember, pipes as we know them in the Unix (and everything else these days) shells came from Unix. That's where that shit was invented. The idea was to produce a bunch of atomic utilities that one could tie together with shell scripts, exactly as one does on any other mainframe (Or at least, you used to need a 'frame to run this junk. OS/400. OS/390. Etc.)
ObDisclaimer: I don't think OS/400 or OS/390 are junk. I Think they're both very nice. Please do not send men in blue suits to beat me up.
--
ALL YOUR KARMA ARE BELONG TO US
Re:Java, or... (Score:2)
huh? (Score:2)
Re:'Assembler Compiler?' (Score:2)
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.
Re:Arrrrgh! (Score:2)
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.
Re:Strange... (Score:2)
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 -_-
Re:LOL (Score:2)
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.. :)
Re:huh? (Score:2)
The assembler was written entirely in bash. It uses no external utilities. It does not use sed or awk or perl or python or ed or anything else. The post I was replying to was an idiot that got modded as insightful by other idiots.
huh? (Score:2)
Re:Java, or... (Score:2)
Re:Some People. (Score:2)
Re:'Assembler Compiler?' (Score:2)
Indeed, on some processors the assembler does even more including expanding one assembly instruction into multiple machine instructions. On a MIPS [mips.com] for example there's even a register reserved for the assembler ( at - assembler temporary) to use when expanding instructions.
Cut to the chase (Score:2)
Re:Slashdotted ftp (Off Topic!) (Score:2)
efficiency, fairness (Score:2)
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
But you still leave "assembly language" undefined (Score:2)
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 [pineight.com] are belong to us.
Depends on definition of "high-level" (Score:2)
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 [pineight.com] are belong to us.
Portable asm has been done (Score:2)
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 [nyu.edu] (Java virtual machine assembly) is even binary-compatible across Linux/x86, Solaris/SPARC, Mac/PowerPC, and Windows/x86.
All your hallucinogen [pineight.com] are belong to us.
Re:huh? (Score:2)
I think you're missing the point of the original post, though; nobody's arguing that bash is meant to stand alone; I think you may have jumped into the argument a few posts too late. If you write a compiler using bash, and do string manipulation through sed and awk, then you haven't written a compiler just using bash. You've used bash AND sed AND awk. We're talking about semantics here, not practical programming.
--
Re:huh? (Score:2)
Alright; the post that started all these threads said that the bash language contains good string manipulation utilities in the form of sed and awk. Someone pointed out that these were not part of bash. You said UNIX apps weren't meant to run as stand-alones. Nobody disputed this; we're just saying that from a strictly technical point bash, sed, and awk are all different programs, not that they should be run alone.
--
Re:'Assembler Compiler?' (Score:2)
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.
Re:Java, or... (Score:2)
Java, or... (Score:2)
No, how about something like a PDP-11. Any other ideas?
Re:Critic (Score:2)
Arrrrgh! (Score:2)
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.)
Re:Critic (Score:2)
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....
Re:Critic (Score:2)
www.hugi.de [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 [x86.org] loads of info about x86 programming
www.cfxweb.net [cfxweb.net] Loads of articles on assembly programming and HLL too.
Hope that clears a few things up *g*
hee, hee, hee (Score:3)
A standard mirror... (Score:3)
HTTP: http://www.bluecherry.net/~rain/shasm.tgz [bluecherry.net]
FTP: ftp://ftp.bluecherry.net/pub/misc/shasm.tgz [bluecherry.net]
Our FTP server has a limit of 15 anonymous users, so I'd highly recommend using the HTTP mirror unless some BOFH [everything2.com] firewalled port 80 outbound. (I've seen it happen!).
--
Ben Winslow..........rain@bluecherry.net
bluecherry internet..http://www.bluecherry.net/
Interactive assembler (Score:3)
shasm (Score:3)
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
Re:'Assembler Compiler?' (Score:3)
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.
Re:Next step (Score:3)
Let me guess... (Score:3)
Assembler vs. compiler (Score:4)
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).
'Assembler Compiler?' (Score:5)
--
Next step (Score:5)
the next crazy step
bash in assembler.
By the way, that would make bash self booting ...
---
recursion, n: see recursion.
Strange, stupid things to do with common tools (Score:5)
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".
--
Bullshit (Score:5)
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.
--
LOL (Score:5)