45 points · by ____Sash---701_ · 7y ago · 51 comments
procedure init; assembler;
asm
mov ax,13h
int 10h
end;
You can even have only the asm block in a regular pascal function and make use of regular arguments in the asm block.PC compilers always followed that path.
The same in Turbo C would be:
void init()
{
asm {
mov ax, 0x13
int 0x10
}
}You wouldn't even need both of those lines with gcc. You could ask the compiler to put 0x13 into ax, and the compiler might schedule that instruction far earlier or even take advantage of the value already being in the register by luck.
Turbo C makes a simplistic assumption about what registers might have been trashed. With gcc, the compiler knows because you told it. Turbo C must save things to memory before the assembly and then reload registers afterward, which adds enough slowness that the assembly might not even be worthwhile.
void init() {
asm("ax"(0x13)) { int 0x10 }
}
and as TFA suggests, plenty of implementations use the string-syntax without any register/clobber extensions.Your remarks are a mute point in modern Windows compilers with Assembly intrinsics, the evolution of those inline assembly instructions.
There's also a Rust version of Dynasm.
I grew up in the late 80's early 90's doing exactly this type of thing as a kid. Having worked as a professional dev for the past few decades I started to notice that I've been taking my work home for all that time, and even though I like my work, I felt I needed a hobby as I'm getting older.
So, I'm currently making a shooting game for the 286/16 in modex VGA with SoundBlaster digitised sound and Adlib for music. All programmed from scratch...
It's a thing literal as it is literally dumped straight into the generated .s file by the compiler, as most C compilers don't do the actual assembly or generation of object file.
Of course these days it's not literally dumped in unmodified -- various compilers do substitutions for you. But that's the legacy.
https://idea.popcount.org/2013-07-24-ir-is-better-than-assem...
- Free Pascal: https://www.freepascal.org/docs-html/prog/progch3.html#progs...
- Delphi: http://docwiki.embarcadero.com/RADStudio/Rio/en/Inline_Assem...
You can even do assembly in batch files via Debug if you really want to:
On a related note, I always find the official docs for GCC inline assembly are insufficient for figuring out what I am trying to do. I nearly always have to resort to dumb trial and error. I was just recently planning to write some docs of my own on the subject. Not tutorial docs, but reference docs.
Quite a meaty document, should provide you with help for material on the subject.
I'm reminding myself of Z80 assembly at the moment, building a simple computer and I've done a bit of that.
The syntax looks like this:
jsm.define("test", new Block(x64) {{
__asm(
"nop", // no-op
"ret" // return
);
}}).invoke();https://stackoverflow.com/questions/48593734/calling-goto-on...
https://codegolf.stackexchange.com/questions/2203/tips-for-g...
This is not recommended for anything in production but is an amusing parlor trick.
Edit: Recent toolchains may require the -zexecstack flag to avoid a segfault.
What to Submit
On-Topic: Anything that good hackers would find interesting. That includes more than hacking and startups. If you had to reduce it to a sentence, the answer might be: anything that gratifies one's intellectual curiosity.
But thing you are talking about indeed recurs here. The way I typically guess is that new generations of programmers are coming up all the time and may be unfamiliar with some old stuff. Or, maybe even some experienced people who never happened to touch c or c++ [there are more of those as time goes on].
EDIT: I see several, just from doing a simple search against 'movq'
https://github.com/torvalds/linux/search?q=movq&unscoped_q=m...
I am not a kernel programmer, though, so I can't say whether it's being used in any capacity on modern, x64 systems or whether it's a compatibility mode for low-powered embedded architectures. Maybe someone more knowledgeable can chime in.
Things like: Hm, I need to swap my stack register and page table with this other process.
Or writing interrupt handlers.
Atomic operations and memory barriers used to be one of those things, but compiler extensions and new language standards have been catching up on some of that... Though to be honest a kernel will want enough control that it will likely still go outside the standard or extra compiler support for these anyway.
For example, there's an article about gorillas on the front page right now that has exactly 7 points. HN is nowhere near that anemic that 7 votes would be enough to push to the front page on its own.
To boot, I once submitted something that went unnoticed. An HN mod then emailed me and said it looked cool, asking me to resubmit it again so that it could get more prominent featuring.