x86 Assembler JWASM Hits Stable Release 209
Odoital writes "January 2010 is an exciting month for x86 assembly language developers. Software developer Andreas Grech, better known to the x86 assembly language community and the rest of the world by his handle "japheth," has released another version of JWASM — a steadily growing fork of the Open Watcom (WASM) assembler. The main benefit of JWASM, arguably, is the nearly full support of Microsoft's Macro Assembler (MASM) syntax. As those in the assembly language community may already know, Microsoft's desire to continually support the development of MASM has been dwindling over the years — if only measurable by a decreasing lack of interest, updates and bug fixes — and thus the future of MASM remains uncertain. While Intel-style syntax x86 assemblers such as NASM have been around for a while, JWASM opens up a new possibility to those familiar with MASM-style syntax to develop in the domains (i.e. other than Windows) in which assemblers such as NASM currently thrive. JWASM is a welcomed tool that supplements the entire x86 assembly language community and will hopefully, in time, generate new low-level interests and solutions."
Just for some perspective... (Score:5, Interesting)
To know how abandoned MASM really is... try and make an assembler project in 64 bit under Visual Studio 2008. It's not even supported out of the box - like, they never actually tested the configuration.
But, for all that, I prefer YASM as the assembler. Still, congrats to the OpenWatcom port.. NICE WORK. It's always good to have more hands in an area that so many people see as dead.
Re:Just for some perspective... (Score:4, Informative)
I'm also a big YASM fan. YASM can generate object files for Windows, OS X, and Linux. That, combined with its macro features, let you write a single x86 file that can be used on all three platforms.
I'll certainly take a look at JWASM, though!
xor my heart (Score:5, Interesting)
cwd
xor ax,dx
sub ax,dx
It's nothing rocket, just some fun with 2s-complement.
-- Rabid
Re: (Score:2)
i'm terrible with x86 assembly, is that the xor swap algorithm [wikipedia.org]?
Re: (Score:2)
I believe it sets dx to the MSb of ax and ends up leaving ax unchanged.
Re:xor my heart (Score:4, Informative)
I believe it sets dx to the MSb of ax and ends up leaving ax unchanged.
oops! I guess I'm getting my AT&T syntax and my Intel syntax confused. If it's Intel syntax, then:
cdw ;; copy MSb of ax to all bits of dx ;; if MSb of ax was 1 then flip bits of ax, otherwise, no effect ;; if MSb was originally 1, this will add 1 to the flipped bits. otherwise, no effect
xor ax, dx
sub ax, dx
So, assuming Intel syntax, this computes to absolute value of ax and sets all the bits of dx to be the sign bit
Re: (Score:2)
Re: (Score:2)
Re: (Score:2, Informative)
No, that snippet compares AL and DX, leaving AX with 1's everywhere except the first different bit, which will hold a 0.
Ex:
AL= 00001101
DX= 00000010 00011001
CWD just puts a 0 in AH
AX= 00000000 00001101
DX= 00000010 00011001
XOR ax,dx computes ax ^= dx
AX=00000010 00010100
DX unchanged
SUB ax,dx computes ax -= dx
AX=1111111111111011
DX unchanged
The XOR swap algorithm to swap ax and dx is:
xor ax,dx
xor dx,ax
xor ax,dx
Re: (Score:2, Informative)
Incorrect. It converts AX to the absolute value of AX.
Re: (Score:3, Informative)
Don't think that's quite right. As I said in my other reply, I had to look up CWD in the Instruction Set Reference:
So this means if AX was originally positive, nothing happens, and if AX was originally negative the XOR flips the bits of AX, then the SUB subtracts minus one from it (which is the same as adding one). This is the same as the two's complement unary minus operation. So the s
Re: (Score:2)
Re: (Score:2)
You also have to be really careful using instructions that update less than a full 32-bit register on modern X86s (such as these 16-bit instructions). You could get "partial register stalls" if you try to read the full-width EAX or EDX after such a sequence. That could toss a big wrench into the deep execution pipeline while the CPU hunts around amongst dozens of pending micro-ops for the appropriate contents of the upper half of the register.
Re: (Score:2)
Amazing how rusty the pipeline-stall instruction group becomes after twenty years of disuse. CWD is a little outside the nucleus of RISC instructions screaming to break free. Not the inner circle of hell, but one of the antechambers. More worth forgetting than recollecting.
The true lesson of our x86 heritage: discretion is the greater part of valour. There's a *lot* of aging x86 instructions that belong to the HCF group for all practical purposes.
Re: (Score:2)
I've never done anything really big in assembler but I'd say cwd is somewhat obscure thing, poor kid. :) I'd rather check if they understand what and how lea does, or some basic non-obvious test stuff.
([spoiler] So, am I completely stupid or is the snippet abs()?)
Re: (Score:3, Informative)
The modern equivalent in 32-bit mode is cdq
These is absolutely necessary instruction when performing division, because on the x86 line division takes a double wide numerator from dx:ax in 16-bit, or edx:eax in 32-bit.
Re: (Score:2)
mov dx, ax
mov cl, 16
sar dx, cl
damn i'm old.
Re: (Score:2)
Except, of course, that shifting is basically free but is only one extra instruction, not two.
Re: (Score:3, Interesting)
Re: (Score:2)
Do you hire people who need to know obscure bits of x86 asm often, or is this just a way of catching people who exaggerate on their CVs?
Probably the later, which is completely legit. It could be a bit uncalled for if the position the interview is for is, say, for developing web pages. But still, with something put on the resume, you take it (or put it) at risk. It would be very questionable, however, if a person is solely dismissed for passing a trivia, specially if it is not related to the job at hand (not that I'm accusing RabidOverYou of doing that, just sayin'...)
If you put something on your resume, you better be able to back it up te
Re: (Score:3, Insightful)
Re: (Score:2)
Re: (Score:2)
It took me a minute to remember what CWD does, but it converts a word (AX) to a dword (dx:ax).
So, if AX is positive, you have this:
dx:ax
0000:ax - cwd - zeros out DX
0000:ax - xor ax,dx - xors AX with 0000
0000:ax - sub ax,dx - subtracts 0 from AX
Whereas, if it’s negative, you have:
dx:ax
FFFF:ax - cwd - fills DX with 1s
FFFF:~ax - xor ax,dx - takes the bitwise complement of AX
FFFF:(~ax)+1 - subtracts -1 from AX
So in the end you have (~ax)+1, which is of course the absolute value of your original AX.
Re: (Score:3, Informative)
the absolute value of your original AX
Come to think of it, that’s just in AX. DX contains the sign of AX.
I.e. it’s this, in terms of pseudo-code:
DX = sign(AX)
AX = abs(AX)
Re: (Score:3, Interesting)
Re: (Score:2)
aww did it hurt your poor little eyes, did having to move them around so much leave you out of breath? Go take a jog or something, fatty.
Re: (Score:2)
Possibly off-topic - but - can anyone tell me if there is much demand for x86 assembler developers?
I'm a 'cookie cutter' .Net Developer. From what I understand, I'm pretty much a dime a dozen....I'm thinking of trying something new.
Re: (Score:2)
I see your x86 absolute value trick and raise you my MIPS absolute value trick:
bgtz a0, label
label:
subu a0, zero, a0
Re: (Score:2)
I feel your pain. I'm in a similar position, but it's even a bit more specialized. I need people who have experience with reverse engineering and no criminal background (i.e. are not only good reversing...). And are available. And that includes being able to read and understand asm code written by someone else. Worse, asm code that a disassembler created. Which is mostly straightforward, granted, since high level languages create fairly easy assembler code. Still, there's always that odd debugger trap and a
Japheth's Other Projects! (Score:2, Informative)
Japheth has a number of rather interesting projects that extend the functionality of DOS.
JEMM, which is his EMM386 replacement: http://www.japheth.de/Jemm.html
HX DOS Extender, which adds Win32 PE & basic API support to DOS to allow the execution of a whole array of apps: http://www.japheth.de/HX.html
Re: (Score:2)
Note: NOT the same JEMM that came with Privateer.
Re:Japheth's Other Projects! (Score:5, Funny)
Awesome, I'm always on the lookout for cool stuff like this to keep my DOS workstation cutting edge.
Re: (Score:2)
HX DOS Extender, which adds Win32 PE & basic API support to DOS
I wasn't quite sure what you meant by this, because what you seemed to imply it did seemed just too wrong to exist, but it turns out that it really is a DOS extender that comes with partial Win32 support. Yes, you can now run DOSBox under DOS (and a lot of other single-window Windows apps; it probably wouldn't be too hard to add a windowing system either, but that would be far too wrong). Now all he needs to do, I guess, is add a POSIX layer...
Re: (Score:2)
can you run wine for windows in it ?
Who needs JWASM? (Score:3, Funny)
We have Java!
Re: (Score:2)
I think you just had a JWASM!
Hey that's great (Score:5, Funny)
Let's write some nVidia drivers in Java!
Re: (Score:2)
Re: (Score:2)
Let's write some nVidia drivers in Java!
They'd probably run faster or better. I can't count the number of engines that have trouble with nVidia multi-threaded rendering. (Source, for example) Java would chug memory, but at least it's reliable.
You'd probably need to static compile it, though.
http://www.excelsior-usa.com/jetinternals.html [excelsior-usa.com]
Re: (Score:2)
I thought they already were!
Re: (Score:2)
JWASM
JWASM is JaWa-asm, and is very useful for programming droids (the non-cellphone kind).
Re: (Score:2)
An exciting month for who? (Score:5, Funny)
January 2010 is an exciting month for x86 assembly language developers.
I'm sure the two of them will be pleased.
Re: (Score:3, Funny)
The first thing I'm going to do with this new assembler is to write a C compiler, and then write Python in C, and then I can get down to work...
Programming from the Ground Up (Score:4, Informative)
Programming from the Ground Up [igsobe.com]
Re: (Score:2)
I'll ask it (Score:3, Interesting)
What's the difference between all of these different Assemblers? Aren't they all just x86, AMD64, or IA32
Re:I'll ask it (Score:5, Informative)
Re: (Score:2)
FASM is another cross-architecture assembler, but with an interesting philosophy. Everything you need to compile something is stored inside the files.
There's none of this gcc.exe --[4 lines and 900 characters of garbage resolving dependancies and changing settings]
Watcom, I cry for thee. (Score:5, Interesting)
I still weep slightly when I think of Watcom and their products. They were, by far, among the best out there in the 1980s and early 1990s. I mean, they made Borland's offerings look like garbage, and Borland was pretty damn good at that time, too.
Their assembler and C and C++ compilers were fucking amazing. Nobody generated faster code than them. I remember once moving some code from Microsoft's C++ compiler to Borland C++, and getting a 5 times speedup. Then we moved it from Borland C++ to Watcom C++, and got an additional 8 times speed improvement! We were totally blown away. Their code generator was just that much better than that of much larger competitors.
Watcom SQL was another gem. So much faster than the competition, but also so much easier to use and develop for. It's good to know that Sybase has kept this product alive and well.
To see such a small shop create some high-quality products is truly a testament to the fantastic talent that they had working there. It saddened me greatly to see them consumed by Powersoft, and then Sybase.
Re: (Score:2)
To see such a small shop create some high-quality products is truly a testament to the fantastic talent that they had working there. It saddened me greatly to see them consumed by Powersoft, and then Sybase.
This is the big benefit of Capitalism. You produce something good, it rocks the boat, then you get bought over and buried. It's the natural order.
jello stacking (Score:4, Interesting)
I never got a five times speedup over Microsoft, but we consistently got 30% reduction in code size, which on a 640KB machine is not to be sneezed at. A big part of that was the excellent register calling conventions and pragma support.
The reality is that Watcom C++ was crushed by Microsoft Visual C++ which had a slick interface lashed onto appalling C++ language support. This was an era when anything slapped in a box was saleable software.
People forget that before eyeballs displaced profit, fatuousness displaced quality. It didn't matter very much if the feature worked as advertised. Software users, like deluded sports fans, believed that hope springs eternal. Maybe it would work in the next version? Sadly, programmers fell for the hype just as often as the end consumers. RIP Watcom.
The day Watcom packed it in—effectively about a version before their last release—I knew that quality had lost the race for many years to come. I didn't have it in me for a career in jello stacking, so I went off for a while to do my own thing. These days, quality is back on the table, for jobs that no longer exist. But if they did, it would be good times again.
Bill Watterson really knew what he was doing when he drew all those snowmen in the first half of the 1990s.
Excited x86 assembly developers (Score:2)
"January 2010 is an exciting month for x86 assembly language developers"
Somehow I have a hard time imagining a bunch of x86 assembly programmers getting excited. I've done assembly on a lot of different architectures, and I can't say "excitement" was ever a term I'd use to describe any emotions related to it.
"Oh wow! There's a new tool that might make some poor saps lives suck slightly less! This is such an awesome month!"
Re: (Score:2)
I dunno. The first time I successful assembled the code to boot my '386 into protected mode, spawn a task, print 'Hello, World.' to the screen, then gracefully exit I was rather excited. I was close to 20 years younger then and had less of a life though.
Mostly off topic question about ASM on x86 (Score:2)
I've done that on ATmega processors, but not x86. With x86 hardware so cheap now, the only reason I have to use ATmega's is power savings, but the loss of CPU power makes it not worth it for my toying around.
I'm interested in doing exactly what you did 20 years ago. Would you know of a decent place to find the documentation required to do this? Like info on video output and such? Just a general basic getting started website or even a book, I don't mind buying something for the knowledge.
I'm a C guy, but
Re: (Score:2)
Re: (Score:2)
why? (Score:4, Interesting)
What is primary use of assembly these days? I thought C gave you the same level of control, but with portability and much-improved readability.
And to give you an idea of where this question is coming from, the last app I wrote was a web app runs in JRuby, using DataMapper to free me from dealing with SQL and Sinatra to free me from dealing with HTTP/CGI. It runs on the Google App Engine cloud. My world is so high-level, with so many layers of virtualization and encapsulation, that I can barely see assembly way down there at the bottom of the stack...
Re:why? (Score:4, Insightful)
And this is precisely why Facebook requires 30,000 servers.
Re: (Score:2, Informative)
And this is precisely why Facebook requires 30,000 servers.
They might need 30.000 servers, but at least they don't need 30.000 programmers and another 30.000 testers.
Re:why? (Score:4, Informative)
Not quite. There are always situations when writing an operating system where you need assembly. For example, impelmenting the actual 'guts' of a context switch requires fine tuned control over what is in each register.
(C programs tend to assume the stack is available. But in the middle of a context switch, it might not. Assembly gives that level of control).
Re:why? (Score:5, Informative)
Re: (Score:2)
C programs should better not assume a stack is available, what if they're compiled for a system that features no stack?
The basic problem is that C programs do not assume anything about low level hardware, because there are so few tools that can actually access things like registers, flags or stack directly. Simply because of the all important notion that C code is to be portable and that you must not assume those registers, flags or stack exist on that other platform.
Re: (Score:2)
Not everything is exposed to C. C is designed for PDP-11s. It doesn't have any of the more advanced CPU features. If you want to use any privileged instructions (required for writing an OS), if you want to use SIMD units, if you want to use things like population count instructions, then you can't use portable C.
This doesn't always mean that you have to use assembly. Most instructions are exposed via platform-specific intrinsic functions. The code generator in the C compiler will handle register alloc
Re: (Score:2)
There's a couple of places:
1) Really tiny microcontrollers with 100 bytes of RAM. These are pretty easily programmed in assembly, though, because there's just not that much to do. However, this isn't affected by this news, since these microcontrollers are most certainly not x86-architecture.
2) The Linux kernel has a little bit of assembly for some low-level hardware initialization stuff. However, for the x86 stuff, they seem to be getting along just fine with nasm. Why anyone would care about a differe
Re: (Score:2)
In addition to what others have said, it's helpful for compiler programmers to have a little knowledge of assembler too.
Re: (Score:2)
It's helpful for any kind of programmer (if he's not going to be stuck in C#, Java or some other language that gives him zero chance to fuck with the contents of his memory directly) to know a bit about the architecture underneath his program.
If programmers did know a bit more about how the stack on a x86 machine works, we'd probably have fewer buffer overflow security holes.
Re: (Score:2)
NOD32 (one of the faster antivirus programs for windows) uses assembly for speed reasons.
Re: (Score:2)
Listen, I have a PIC Microcontroller here on my desk. I toy with it from time to time, to build my killer robot... but even that wimpy little 8-bit fleck of baked sand can be programmed with C.
And I am aware that the languages I do useful (non-killer-robot) work in all run on top of something which runs on top of something (etc.) which was programmed in C.
My question is: who out there is saying "gee, C just won't cut it. I need assembly."?
Re: (Score:2)
I still program my PICs in assembly. However, I'm using the really tiny ones (PIC12F510). I also haven't found a convenient C compiler for them that runs in Linux, but the gpasm, gpsim, and pk2 utilities work just fine for me in Linux.
Re: (Score:2)
Assembly is useful for creating self-modifying code, which finds at least some use in emulation. However, that still doesn't make x86 assembler and self-modifying code anything other than abominations. Writing code in assembly when the same code in C would be at least 90% as fast should qualify one for immediate execution by firing squad.
Re: (Score:2)
Re: (Score:2)
You're right when you say that most areas have been taken over by C or some other high level language that used to be the field of asm, notably the area of embedded development, and the "market" for asm is shrinking as we speak. But there are still a few things that can only be done sensibly in asm.
1) Reverse Engineering. I'll start with this one 'cause it's my field of work. When you're trying to analyze malware, you have no source code available (well, usually). So the disassembly is all you have to work
not needed for MMX anymore (Score:4, Insightful)
You can use compiler builtins for SIMD these days (fairly standardized across Intel, GNU, etc. compilers). (And don't complain about portability if you are using hand-coded SIMD....you have to be using #ifdefs or something anyway.)
Aside from using specialized instructions that are usually accessible from C anyway via builtins, it's not like x86 assembly has much relationship anymore to what actually happens in the hardware; you can't even control the real registers anymore (most CPUs have many more physical registers than are exposed in the instruction set, and rename on the fly).
Besides, most useful optimizations are much higher-level than that (besides the obvious question of algorithm choices, performance is typically dominated by memory access and you are better off focusing on locality than instruction-level efficiency).
Flat Assembler? (Score:2)
Wikiwars (Score:5, Informative)
Be warned -- JWASM's Wikipedia article was nominated for deletion [wikipedia.org], as it was thought that notability was not sufficiently asserted. The flame war there might spill over here as well. :-(
Re:Wikiwars (Score:5, Insightful)
Be warned -- JWASM's Wikipedia article was nominated for deletion
And that right there's why I won't donate a penny to that project. Honestly, WTF? That article's source is about 13KB long. At $100/TB, it costs about 1/7800th of a penny to store. "But what if it clutters up the site!", say the Deletionists. Apparently there's an alternate front page to Wikipedia that lists every single article and it's critical that it be kept tidy and short.
Actually, I take that back: can I send Wikipedia a penny and sponsor a few thousand articles of my choosing, starting with this one?
Re: (Score:2, Interesting)
"Deleted" articles don't get deleted from the Wikipedia database at all. They just get hidden from the public. An administrator can undelete them at any time. So, there's no monetary saving involved. Arguably, plain spam should be removed from the site, but JWASM is obviously not that. It is even discussed in Fog Agner's book, which normally meets the requirements for a Wikipedia article. See my post [slashdot.org] above. I can't be bothered to read the insanely long deletion discussion to see why that's not enough for th
Re: (Score:2)
Untrue, deleted articles will eventually be purged. They may not be instantly purged, but Wikimedia most certainly is capable of completely removing data from itself.
Re:Wikiwars (Score:5, Interesting)
Articles about old hardware often get deleted too. Socket A motherboards and stuff. I've seen articles on older cellphone SoCs and their companies vanish as well. Apparently never getting large and then finally going out of business means you don't deserve to be noted in history.
Re: (Score:2)
Seems like a pretty shitty repository of knowledge doesn't it.
Its certainly no Jedi archive or Stargate Ancients head sucker repository of knowledge downloader thingy.
Re: (Score:2)
egad. can we please expose, bring out and torture people who delete (or propose for deletion) such pages ?
the power of wikipedia is finding all kinds of pretty obscure information, neatly laid out and described. if it's not, i sometimes fix a thing here or there myself.
notability requirements are required, we wouldn't want an article on every person ever lived, but that's the opposite extreme.
Re:Wikiwars (Score:4, Insightful)
we wouldn't want an article on every person ever lived
Why? Say that's 10 billion people, and each article is 10KB. That comes out to 100TB and a modest database to reference it all. In 2010 technology, I could afford to buy and run that hardware out of my basement if I really wanted to. Keep in mind that hosting 10G articles is a lot different from serving that many.
As long as it doesn't bog down the search engine, is there any practical reason to care? Especially when instead of 10G articles, we're talking about something on the order of 1 million.
Re: (Score:2)
LLVM (Score:3, Informative)
Frankly, optimizing assembly code is a PITA, since there are so much different flavors.
For example, AMD and Intel processors have different types of optimization.
If I were to code in assembly nowadays, I'd prefer to use something like LLVM: http://llvm.org/ [llvm.org] which should be able to generate good optimized code for any kind of processors, without the hassle of maintaining one routine per processor.
In some very extreme cases (like coding a RC5 decoder or multiprecision routines), it's still useful to use assembler, but in most other cases, I'm sure that LLVM is able to generate code much better than you could achieve manually in the same amount of time.
Re: (Score:2)
That's good news (Score:3, Interesting)
pusha
msg db 'Because I kinda like assembly.$'
mov ax, seg msg
mov ds, ax
mov ah, 9
int 21h
popa
mov ax, 4c00h
int 21h
nop
Re:That's good news (Score:4, Insightful)
You forgot to jump around your message, or put it at the end, or use segments to tell the assembler to do that automatically.
IDA Pro (Score:3, Interesting)
Assembler (Score:2)
you haven't needed asm for SIMD for years (Score:2)
I will still prefer YASM/NASM (Score:2)
MASM abstracts too much for my tastes. MASM does a lot of things automatically that you don't necessarily want, and it's irritating. Also, it is sometimes context-sensitive: "mov eax, meow" differs in meaning in MASM depending on whether "meow" is a variable or a label. The former means to read the value stored in "meow" (mov eax, [meow]), and the other means to load the address of "meow" (mov eax, offset meow).
Also, MASM code frequently uses things like ".IF" statements to build conditional blocks for y
Re:And how does it differ ? (Score:5, Informative)
And how does its syntax differs from NASM and AT&T ?
Intel syntax doesn't feel like it was designed by a sadist.
More seriously, this site [imada.sdu.dk] link covers some differences. Among the things I like much more about Intel syntax: there's no need to add a ton of visual noise with what-should-be-extraneous $ and % symbols, and things like memory indirection is much easier to learn. Compare "[ebx+ecx*4h-20h]" to "-0x20(%ebx,%ecx,0x4)"; the former almost tells you what it does even if you're not at all familiar with the syntax, the latter definitely doesn't.
The main benefit that AT&T syntax has is that they "hungarian notation" their instructions: movb works on 1 byte, movw on 2 bytes, movl on 4. Most of the time this is extra visual noise (I don't need the 'l' to tell me that 'mov eax, ebx' works on 4 bytes), but it does make memory dereferences more concise. With Intel syntax you'll get a lot of 'dword ptr' stuff lying around to tell how much should be brought in from memory.
Re: (Score:2)
Compare "[ebx+ecx*4h-20h]" to "-0x20(%ebx,%ecx,0x4)"; the former almost tells you what it does even if you're not at all familiar with the syntax, the latter definitely doesn't.
I'm guessing you started with intel syntax then? because I honestly find the latter more readable. As for the % and $ symbols I find it makes for clearer reading, like having comments in your code.
The best thing I find about at&t syntax is that it is portable across architectures. You can code in arm, mips etc all with the same syntax. I have not yet seen intel syntax used on anything but intel.
Re: (Score:2, Informative)
To answer your other question about benefits, most of the benefit comes from your toolchain. If you're using a toolchain that is designed to work with AT&T syntax, like GCC, then no, there's no benefit. If you want to interoperate with MSVC, there's a ton of benefit. (In particular, if you want to use inline asm in a MSVC program, it uses Intel syntax.)
Re: (Score:2)
There are many other x86 assemblers that are in the same boat as NASM. They are just simple assemblers.
MASM is all about the macro language. While terribly hard to learn to do more advanced macro stuff due to the way it evolved (feature creep while maintaining compatibility)
Re: (Score:2)
The nice thing about this nearly-compatible masm assembler is its license terms. Like if I want to write a domain-specific compiler I can just package this thing up and send it along so
Re: (Score:2)
Um, so who's the other guy?
Re: (Score:2)
As someone mentioned above: http://mirrors.igsobe.com/nongnu/pgubook/ProgrammingGroundUp-1-0-booksize.pdf [igsobe.com]
Re: (Score:2)
It's not Sunday, 9am yet.