X86 ENTER: What’s That Second Parameter?

[Raymond Chen] wondered why the x86 ENTER instruction had a strange second parameter that seems to always be set to zero. If you’ve ever wondered, [Raymond] explains what he learned in a recent blog post.

If you’ve ever taken apart the output of a C compiler or written assembly programs,  you probably know that ENTER is supposed to set up a new stack frame. Presumably, you are in a subroutine, and some arguments were pushed on the stack for you. The instruction puts the pointer to those arguments in EBP and then adjusts the stack pointer to account for your local variables. That local variable size is the first argument to ENTER.

The reason you rarely see it set to a non-zero value is that the final argument is made for other languages that are not as frequently seen these days. In a simple way of thinking, C functions live at a global scope. Sure, there are namespaces and methods for classes and instances. But you don’t normally have a C compiler that allows a function to define another function, right?

Turns out, gcc does support this as an extension (but not g++). However, looking at the output code shows it doesn’t use this feature, but it could. The idea is that a nested function can “see” any local variables that belong to the enclosing function. This works, for example, if you allow gcc to use its extensions:

#include <stdio.h>

void test()
{
   int a=10;
   /* nested function */
   void testloop(int n)
   {
      int x=a;
      while(n--) printf("%d\n",x);
   }
   testloop(3);
   printf("Again\n");
   testloop(2);
   printf("and now\n");
   a=33;
   testloop(5);
}

void main(int argc, char*argv[])
{
   test();
}

Continue reading “X86 ENTER: What’s That Second Parameter?”

Terminal-Based Image Viewer, and Multi-OS Binary, and Under 100kb

[Justine Tunney]’s printimage.com is a program capable of splatting full-color images to text mode terminal sessions, but that’s not even its neatest trick. It’s also a small binary executable capable of running on six different operating systems: Linux, Windows, MacOS, FreeBSD, OpenBSD, and NetBSD. All without having to be installed or otherwise compiled first. On top of it all, it’s less than 100 kb.

How is this possible? It’s thanks to [Justine]’s αcτµαlly pδrταblε εxεcµταblε format, implemented by a project called Cosmopolitan which aims to turn C into a build-once-run-anywhere language. The printimage.com source code is included within the Cosmopolitan project.

If the name sounds a bit familiar, it’s probably because the Cosmopolitan project is a key piece of a tool we recently covered: llamafile, which allows people to package up an LLM (large language model) as a single-file, multi-OS executable.

As printimage.com shows, terminal windows are capable of more than just text. Still, plain ASCII has its appeal. Check out the ASCII art STL file viewer which might just make your next sick ASCII art banner a bit easier to generate.

One Less Binary Blob

Open-source software has gone a long way into making modern technology the way it is today. The Linux kernel alone is almost single-handedly holding up the entire Internet, and various other open-source projects allow for more access to computing resources not just because the software is often free, but because it’s possible to look under the hood and modify it for specific needs. Without open-source software available we often run into problems both expected, such as software licensing costs, and unexpected, which often come up because a developer can’t or won’t fix issues or add features. To that end, a group at Ghent University in Belgium are attempting to rectify a problem with the ESP32 by eliminating one of its binary blobs and replacing it with an open source driver.

The ESP32 is famously a low-cost microcontroller with on-board wireless capabilities, but its Wi-Fi functionality currently relies on closed-source software from Espressif. The team is currently working on building a fully working open-source networking stack with the hopes of enabling greater flexibility of these devices but also making things like security auditing possible. The other major goal is to improve low-cost mesh networking which is currently not available with the proprietary driver. Reverse engineering is the name of the game here, both from a hardware and a software level, but current versions of the software already able to send and receive packets.

The source code for the project is available on the team’s GitHub page for any open-source aficionados to take a look at. We certainly hope the project gains some steam, as any new open source project helps all of us using the platform. Open source projects frequently get stymied by a single or small handful of binary blobs too, often with little hope for recourse. Examples include Android being an open-source operating system but generally using the closed-source Google Play suite in practice, or Firefox including support for Adobe Flash. Another great example is that even computers running 100% open-source code once they boot their operating systems, there’s still some black boxes running in the background few of us think about.

Thanks to [Crote] for the tip!

BASIC In Your Browser

If you are a certain age or just like retrocomputers, you probably have a soft spot for good old-fashioned BASIC. If you miss those days but don’t want to install a modern interpreter, you don’t have to. Just load a web page containing the “BASIC Anywhere Machine” from [CJ Veniot]. Worried about it being “in the cloud?” It isn’t? It runs in your browser, and if you are a TiddlyWiki fan, it will even live inside your Wiki, which you can host as you please.

The project has lots of features, including some integration back into TiddlyWiki, which we haven’t tried. But you can use graphics commands, work with the mouse, and do other fun things.

Continue reading “BASIC In Your Browser”

Wine Is For Windows And Darling Is For MacOS

Wine has become a highly optimized and useful piece of software for those that live in Linux, but occasionally need to walk on the Windows side. In case you’d wondered, there’s a similar tool for when you need to run a MacOS program in your Linux environment. Enter Darling, the translation layer you’ve needed all along.

Just as Wine is not an emulator, nor is Darling. As a translation layer, it duplicates functions of the MacOS operating system that programs need to operate but within Linux. It’s fast, because it’s effectively running the MacOS software directly. Initially, Darling was mostly only capable of running MacOS apps at the console level. However, there is rudimentary support for running graphical applications that are based on the Cocoa framework.

Hilariously, if you’re into weird recursive situations, you can go deeper and run Darling within Windows Subsystem for Linux, itself running within Windows. Why? Well, you’re probably bored or just trying to for the sake of it. Regardless, we don’t judge. If you’ve got your own nifty translation or virtual machine hacks in the works, don’t hesitate to let us know!

Zork Zcode Interpreters Appear Out Of Nowhere

Some of our readers may know about Zork (and 1, 2, 3), the 1977 text adventure originally written for the PDP-10. The game has been public domain for a while now, but recently, the interpreters for several classic 1980s machines have also appeared on the internet.

What’s the difference? Zork is not a PDP-10 executable, it’s actually a virtual machine executable, which is in turn run by an interpreter written for the PDP-10. For example, Java compiles to Java bytecode, which runs on the Java virtual machine (but not directly on any CPU). In the same way, Zork was compiled to “Z-machine” program files, called ZIP (which was of course used in 1990 by the much more well known PKZIP). To date, the compiler, “Zilch” has not been released, but the language specification and ZIP specifications have, which has led some people to write custom ZIP compilers, though with a different input language.

For more on the VM, check out Maya’s Zork retrospective. (And dig the featured art. Subtle!)

Of course, that’s not the only type of interpreter. Some programming languages are interpreted directly from source, like this BASIC hidden in the ESP32’s ROM.

Bringing Back The CRT TV Experience In Software

Cathode-Retro is a collection of shaders and sample C++ code for reliving the glorious days when graphics were composite video signals displayed on a CRT screen. How? By faking it in software and providing more configuration options than any authentic setup ever had.

Love it or don’t, there’s nothing quite like it.

Not satisfied with creating CRT-style color images with optional scanlines and TV picture controls like tint and saturation, Cathode-Retro can emulate more nuanced elements as well.

The tool includes the ability to imitate things like the slight distortion of a period-correct curved screen, the subtle effects of different methods CRT displays used to actually work (such as shadow mask vs aperture grille), and even taking into account the slight distortion of light refracting imperfectly through the glass face of the CRT. There’s even options for adding noise and ghosting, which may spark some artistic ideas.

If all you need is software to recreate an old-school CRT terminal, we have you covered. But if your needs are a bit more low-level, Cathode-Retro might be what you’re missing.