Live data from Hacker News

Paint16b: A 16 byte paint program written in 12 lines

sizecoding.org

31–40 of 70 posts

Re: Paint16b: A 16 byte paint program written in 12 lines

#31

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: http://stanislavs.org/helppc/int_33.html http://stanislavs.org/helppc/int_10.html 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 c…

Why is the ret necessary? Is this not an infinite loop?

Re: Paint16b: A 16 byte paint program written in 12 lines

#32
post #9
post #4

Earlier quoted context omitted.

Is assembly not common knowledge anymore?

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.

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.

Re: Paint16b: A 16 byte paint program written in 12 lines

#33

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. either way cool! :D

Apparently these are a valid assumption to make in DOS.

Re: Paint16b: A 16 byte paint program written in 12 lines

#34
post #22
post #18

Earlier quoted context omitted.

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

Should they? Why? 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 impo…

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.

Re: Paint16b: A 16 byte paint program written in 12 lines

#35

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: http://stanislavs.org/helppc/int_33.html http://stanislavs.org/helppc/int_10.html 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 c…

Why is the ret necessary? Is this not an infinite loop?

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:

    ; allows exit if the mouse is leftmost

Re: Paint16b: A 16 byte paint program written in 12 lines

#36

Earlier quoted context omitted.

Why is the ret necessary? Is this not an infinite loop?

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: ; allows exit if the mouse is leftmost

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.

Re: Paint16b: A 16 byte paint program written in 12 lines

#37
post #11

Earlier quoted context omitted.

Hm... If you know one assembly you can easily recognize when it is assembly, even if you don't know the specific architecture.

Not if it is your first time seeing assembly.

Doesn't that then imply that you don't know assembly?

Re: Paint16b: A 16 byte paint program written in 12 lines

#38

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.

Exactly. Every language has its impressive one-liners and terse programs thanks to the underlying layers of abstraction, even asm.

Re: Paint16b: A 16 byte paint program written in 12 lines

#39
post #37

Earlier quoted context omitted.

Not if it is your first time seeing assembly.

Doesn't that then imply that you don't know assembly?

Blargh, I somehow read that as "if you don't know assembly" instead of "if you know one assembly".

Re: Paint16b: A 16 byte paint program written in 12 lines

#40

> assume ah=0; assume bx=0 Hmm. So the second time this program is run, it will fail?

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…

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.
Post reply on HN