It really is quite amazing how small you can make things when you try. Then you realise you're wasting most of a disc sector, and the thing you have is unportable and unmaintainable.
But still, being able to look at a binary and know what every byte does, being unconstrained by the rules of a language is liberating.
All the program has to do is repeatedly get the current mouse position and set the pixel there, and that's all it does. These two links should help make sense of it:
The main loop contains an implicit state-machine that does multiple things on different iterations, which is partly responsible for the small size.
Another thing that you can clearly see is how efficient it is at using the registers; this is one area where compiler-generated code is consistently behind, and something I wish compilers would get better at --- an HLL could take as many bytes as this entire program just to put the parameters onto the stack and call a function.
Finally, one small correction:
ret ; assume [[FFEE]] = [0] = CD20 = int 20
...should be "assume [FFFE] = 0", because that's where the stack pointer is initially, and this program does not use the stack itself for its entirety --- it doesn't need to!
The loop instruction decrements CX, and then jumps if it is nonzero. Otherwise it "falls through". At that point CX contains the X coordinate of the cursor. Hence the comment:
Ah, I had zoomed in to see the code and completely disregarded the comments; in hindsight, I see that was a mistake. Although, I guess I should have guessed that cx could contain 0 in it.
Not to poo-poo this (I think this is very impressive) but the reason why it is so small is that it just calls a bunch of bios and mouse driver routines. If those items didn’t already exist the program would surely be larger.
Not unique to Wintel, or this program. That's the reason programs were so small for the original Macintosh. Most of the essential routines, especially Quicktime, were in ROM.
(I think you mean QuickDraw.) Yes, and the ROM itself was only 64kb of hand-written assembly, using a variety of techniques to cram in all that functionality, like sharing function prologues and epilogues.
https://www.pouet.net/prod.php?which=63826 has download links. In theory if someone were to put this onto archive.org you could use the JS version of DosBox to try it out.
pretty cool, but why not have it a tiny tiny bit longer code and not strt with 2 flat out assumptions? I mean im not familiar with dos deeply and if these will be true 100% of the time, but as it reads, it reads like silly code which might crash or work unexpectedly in certain situations.
cool :) learning more about low level codes, and everyone tells me never to assume anything about a booting system ,but i suppose DOS will offer a more stable environment for programs to start then 'any x86_^64 hardware' :D thanks for clearing that up! it's a simple program but it sure shows that you can already do a lot with just a few bytes =]
No, AFAIK MS-DOS always initialises it to zero before starting the program. I'm trying to find a better reference, but I think this[0] effectively explains what state the registers are in on entry to your program.
Edit: I take that back. According to [1]:
.COM-format executables begin running with the following register values:
AL = 00h if first FCB has valid drive letter, FFh if not
AH = 00h if second FCB has valid drive letter, FFh if not
The value of BX is however strictly undefined, but practically always 0. Potentially some DOS will load this register with a different value, but probably no version of MS-DOS.
On x86, some instructions are longer than others. Incrementing is a single byte. Setting the value 1 if you don’t assume anything is going to be 2 bytes (al, ah, bl, etc.) or 4 bytes for (ax, bx, etc.)
It's interesting how many people would not recognize assembly language if shown a sample. In a way that is a statement as to how far compilers have come, that it is possible to produce perfectly good software that runs fast enough that only a limited number of people still has to know about the details of the underlying processor.
And in the case of interpreted languages or JIT'd languages the lines get blurred a bit more but even there it is clear that whoever uses say 'numpy' does not need an understanding of the underlying operations to get through their working day.
Higher levels of abstraction translate into higher productivity, in ever more rare cases it is worth breaking open those black boxes to go to work on the underlying plumbing.
In the parents defense 'assembly' isn't one thing. Every assembler has a different syntax, as does every chip family. The parent might be a master of 6502 ASM.
And as that XKCD comic says. Everyone has to learn even the most obvious thing for the first time at some point.
I admit my experience is limited, but there are few things that should immediately identify some code as assembly to someone with previous experience, regardless of the platform, such as the prevalence of the "mov" command, a "jump" command or the use of registers, using memory addresses as parameters, accssing stack using "push" and "pop" commands.
Registers might have different names depending on the platform, actual command names may vary, but I would be surprised to see non-obscure platforms for which the pattern above is not valid.
I suppose my gp wasn't very clear. Language in this context could be just ASM or it could be intel x86 DOS ASM.
As I said, the gp could be a master of 6502 ASM, but not be able to tell the difference between ARM and X86.
The question is whether it's recognizable as assembly at all rather than which specific flavor. I think it's correct that all assembly flavors tend to look very similar to each & very dissimilar from any language.
The syntax is different but the structure (or... lack thereof) is almost always the same (excluding the "edge cases" like highly-macroised code.) Asm looks like a step-by-step list of instructions, which is exactly what it is.
Confusing Asm with early (GOTO-only) BASIC, on the other hand, would seem far more common to me.
This applies to general public but someone with Freelance Web developer based in Amsterdam. Mostly Node and React. in their bio should probably know what Assembly is...
Look, I wrote assembly when I was a teen, went to school for CS twice and can't do squat with it today. I know it is ASM but beyond that it's not that interesting or exciting to me.
This person's job is strictly to build frontend web apps. Knowledge of assembly is largely ornamental to that pursuit. I'm not even sure someone getting as BSCS and MSCS would spend enough time with it to care.
It's important, critically so for some people, but I wouldn't ding a job applicant for a node job for not recognizing it.
I don’t think everyone who writes code needs to know how to write assembly, but I think it’s important to know that it exists and possibly what it looks like. Maybe not while you’re still learning to code, but once you’ve actually started working in the industry it’s a good thing to know, if only because it gives you a bit of context of how computers actually work.
1) No, you only need to know about assembly language if you go for deep microoptimizations.
2) Assembly is vastly more high level than modern hardware, so much that most of those CISC instructors are broken into tens to thousands micro operations.
It's not even close to any kind of machine architecture course.
You will need that kind of deep knowledge to write optimal compilers which probably take (extended) C and not assembly language.
Assembly (well, machine code if you want to nitpick) is still the representation of a program right at the interface between software and hardware. It's the processor's native API, no matter how many layers of additional abstraction behind that API. So it's a pretty important level of abstraction if you want to have a reasonable high-level idea of how a computer works.
Why? Serious question. Nothing about that bio says “this person should know about the existence of assembly” to me.
And besides, with their question they’ve made an effort to learn about it so I don’t see any reason to criticize them for not knowing. It’s like the xkcd referenced says, every day there are a bunch of people hearing about something for the first time. We should be happy that they hear about it!
Really? A programmer of any stripe who doesn't recognize assembly just seems like a very wrong thing. One wonders what their mental model of the computer is like.
I imagine that most people abstract at the levels above and below assembly languages. E.g. they know about high level languages, and that a CPU cannot directly run that, but their view of the lower level probably does not include any human readable artifacts such as latin characters but rather binary and voltages.
We have web pages with multiple seconds of latency because devs don't have a deep understanding of the performance hits of composing programs. And for that you need to understand how the CPU works.
I do not believe that knowing ASM would even remotely translate into the ability to optimize web pages for latency: understanding high-level concepts like TLS, HTTP/HTTP2, and being to understand JS engines seems far more applicable.
You also seem to be making the assertion that you cannot understand how a CPU works without knowing ASM, which seems equally spurious.
There is a significant portion of developers ( particular web and app ) and IT staff who never studied computer science in college but instead moved into programming/IT mid career. Most of them probably never heard of or seen assembly code.
However, I would be shocked if anyone who went through a CS program wasn't aware of assembly programming.
It's obvious in the context of that wiki. From the front page:
> SizeCoding.org is a wiki dedicated to the art of creating very tiny programs for the 80x86 family of CPUs. By "very tiny programs", we mean programs that are 256 bytes or less in size, typically created by members of the demoscene as a show of programming skill. The size of these tiny programs is measured by their total size in opcode bytes, and are usually presented as executable .COM files to be run in pure DOS, a DOS VM running inside another operating system, or an emulator that can run DOS such as DOSBox.
And something I found useful https://www.muppetlabs.com/~breadbox/software/tiny/teensy.ht...
It really is quite amazing how small you can make things when you try. Then you realise you're wasting most of a disc sector, and the thing you have is unportable and unmaintainable. But still, being able to look at a binary and know what every byte does, being unconstrained by the rules of a language is liberating.