Slashdot Mirror


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."

39 of 126 comments (clear)

  1. Re:Java, or... by Anonymous Coward · · Score: 2

    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.

  2. huh? by Zach+Baker · · Score: 2
    sed and awk aren't part of bash.

    1. Re:huh? by kaisyain · · Score: 2

      What do pipes have to do with anything?

      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.

    2. Re:huh? by nomadic · · Score: 2

      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.

      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.
      --

    3. Re:huh? by nomadic · · Score: 2

      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.

      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.
      --

  3. Re:'Assembler Compiler?' by Hulver · · Score: 2

    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.

  4. Re:Arrrrgh! by paul.dunne · · Score: 2
    > Anyone that puts a single-quote in a UNIX filename needs to be shot.

    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.

  5. Re:Strange... by mcc · · Score: 2
    As of this posting neither netscape 4/windows nt or wget/slackware were able to connect, with or without email address passwords.

    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 -_-

  6. Re:LOL by mcc · · Score: 2
    As a perl -e oneliner :)

    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.. :)

  7. huh? by kaisyain · · Score: 2

    sed and awk aren't part of bash.

  8. Re:Java, or... by humphrm · · Score: 2

    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
  9. Re:Some People. by hugg · · Score: 2

    Just think what would have happened if Linus decided to go for a walk instead of hack!!! Flood. Famine.

  10. Re:'Assembler Compiler?' by mistered · · Score: 2
    Assembly language is pretty much a straight one for one conversion into machine code

    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.
  11. Cut to the chase by lildogie · · Score: 2

    Clearly the ultimate would be bash in bash.

  12. Re:Slashdotted ftp (Off Topic!) by Snard · · Score: 2

    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
  13. efficiency, fairness by anonymous+cowerd · · 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

  14. But you still leave "assembly language" undefined by yerricde · · 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:

    • The macroinstruction support in more powerful assemblers distorts the "one asm instruction, one binary instruction" aspect of the commonly accepted definition of asm. The MIPS asm specification specifies a large number of "pseudoinstructions," that is, short macros that use MIPS register 0. A rich macro system in an assembler could possibly make MIPS look like PowerPC look like ix86 look like Sparc look like Alpha look like XScale look like ARM look like even good ol' Z80 and 6502.
    • One word: Java.
    • How do we know it isn't possible to create a machine that runs C bytecode in hardware? It's already been done for Forth.

    All your hallucinogen are belong to us.
    --
    Will I retire or break 10K?
  15. Depends on definition of "high-level" by yerricde · · 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 are belong to us.
    --
    Will I retire or break 10K?
  16. Portable asm has been done by yerricde · · 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 (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?
  17. Re:'Assembler Compiler?' by saider · · Score: 2

    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.
  18. Re:Java, or... by Marc2k · · Score: 2

    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
  19. Java, or... by FreeMath · · Score: 2

    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.
  20. Re:Critic by FreeMath · · Score: 2

    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.
  21. Arrrrgh! by sparcv9 · · Score: 2

    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 .sig
  22. Re:Critic by Kurt_Rambone · · Score: 2

    >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....

  23. Re:Critic by Kurt_Rambone · · Score: 2

    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*

  24. hee, hee, hee by Anonymous Coward · · Score: 3

    Bash (bæsj) means poop in Norwegian!

  25. A standard mirror... by Rain · · Score: 3

    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/

  26. Interactive assembler by coreman · · Score: 3

    We've had intereactive C for a while now, interactive assembler seems a reasonable extension... hmmm interrupt latency is what, 3-4 days?

  27. shasm by _Gnubie_ · · Score: 3

    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

  28. Re:'Assembler Compiler?' by commbat · · Score: 3

    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.
  29. Re:Next step by UberLame · · Score: 3

    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.
  30. Let me guess... by Soft · · Score: 3

    Someone has had a bad experience of the Admin Horror Stories kind, rm-rf/ and the like?

  31. Assembler vs. compiler by eap · · Score: 4

    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).

  32. 'Assembler Compiler?' by emerson · · Score: 5

    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....


    --

  33. Next step by geirt · · Score: 5

    the next crazy step

    bash in assembler.

    By the way, that would make bash self booting ...

    ---
    recursion, n: see recursion.

    --

    RFC1925
  34. Strange, stupid things to do with common tools by multipartmixed · · Score: 5

    ...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()?
  35. Bullshit by multipartmixed · · Score: 5

    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()?
  36. LOL by jawtheshark · · Score: 5

    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)