News for hackers. Stuff that matters.
Re:Please restore our registers when you’re done with them by masklinn on Tuesday November 22, 2022 @11:24AM (#33707491)
Yes, but it's not a property of the assembly (or assembler), it's a necessity for the compiler to correctly codegen around the inline assembly.

Historically, assemblers have been really dumb, so ABI is not a thing they'd track, especially as... I don't think they know what functions are? So while they can notice call/ret, they have no knowledge of a label being a jump or call target per-se, do they?

So you'd need an assembly-like language to encode this sort of information.

Re:Please restore our registers when you’re done with them by ElevenLathe on Tuesday November 22, 2022 @12:55PM (#33708665)
I mean if you have a macro assembler you should be able to write a macro that generates "save registers" instructions before a section of code and "restore registers" instructions after it. The assembler doesn't need to know our care that this section of code is a function.

It's interesting how blurry the line is between a good, full-featured assembler and a crappy compiler!

Re:Please restore our registers when you’re done with them by masklinn on Tuesday November 22, 2022 @01:01PM (#33708732)
> I mean if you have a macro assembler you should be able to write a macro that generates "save registers" instructions before a section of code and "restore registers" instructions after it.

Except you want a "macro" which:

- saves only the registers you touched

- which are callee-saved

- according to the ABI you're targeting

And you really only want that for functions, because... that's where ABIs come into play.

Re:Please restore our registers when you’re done with them by denton-scratch on Tuesday November 22, 2022 @01:53PM (#33709513)
> I don't think they know what functions are?

It's a long time since I tangled with x86 assembler; but as I recall, ENTER and LEAVE were specifically for functions, and I'm not aware of any other use for them.

Re:Please restore our registers when you’re done with them by tremon on Tuesday November 22, 2022 @03:35PM (#33711109)
ENTER and LEAVE were specific x86 instructions though, not some kind of assembler special sauce. The assembler just translated your ENTER instruction into the corresponding machine opcode; no ABI knowledge required whatsoever.
Re:Please restore our registers when you’re done with them by brucedawson on Tuesday November 22, 2022 @11:34PM (#33715211)
I think most assemblers know what functions are. There are usually directives to indicate this. They help with emitting symbols (you need the function name to be emitted or no-one can call it), stack unwind information, and other information (some of which may also be required by the ABI). Here's some relevant documentation for MASM https://learn.microsoft.com/en-us/cpp/assembler/masm/proc?vi...

The short version of it is that assemblers these days are rarely - if ever - just a zero-context stream of machine instructions. There is far more, some of it actually required.