-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code_asm: add ability to align the code #210
Comments
is there any workaround you recommend? |
Would be nice to have some alignment directives without having to run the encoder to get the instruction (data) sizes. |
internal static void int3_align(this Assembler c, int alignment)
{
if (c.Instructions.Count == 0)
return;
var cw = new SizingCodeWriter();
c.Assemble(cw, 0);
var length = cw.Length;
var pad = alignment - length % alignment;
for (var i = 0; i < pad; ++i)
c.int3();
}
internal static void nop_align(this Assembler c, int alignment)
{
if (c.Instructions.Count == 0)
return;
var cw = new SizingCodeWriter();
c.Assemble(cw, 0);
var length = cw.Length;
var pad = alignment - length % alignment;
if (pad > 0)
c.nop(pad);
} public sealed class SizingCodeWriter : CodeWriter
{
public int Length { get; private set; }
public override void WriteByte(byte value) => ++Length;
public void Reset() => Length = 0;
} These are some mediocre hacks that serve good enough for my use cases. |
Tried that first; came out to 0 every time. Looks like it gets set during
encoding.
…On Sat, Jan 28, 2023, 4:43 AM Marco Spampinato ***@***.***> wrote:
Would be nice to have some alignment directives without having to run the
encoder to get the instruction (data) sizes.
You evildoer using C# 😂
now seriously, the code assembler struct/impl is backed up by a vector of
Instruction(s), as far as I know you can query the instruction length, so
the current byte size could be computed, am I right?
—
Reply to this email directly, view it on GitHub
<#210 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIC7PYC7PNN74EFEUKYFVGTWUTS5HANCNFSM5GTESTNQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#207
The text was updated successfully, but these errors were encountered: