2

I need to generate random ASM instructions. I found a really helpful XML file from UOPS which makes the random instruction generator program really simple. However, the XML file provides the instructions in Intel's X86 Encoder Decoder (XED) syntax, and I wanted to know if there is a way to compile them to an executable as you would with a NASM or MASM program.

The list of instructions would look something like this:

DEC R8W
LOCK ADC byte ptr [0xB8], 0x82
IN AX, DX
BTR qword ptr [RBX], 0xF7
IN EAX, DX
ADD RAX, 0x25C9FB2C
LOCK BTC qword ptr [RBP], 0xA5
CMOVBE ESI, R10D
{load} MOV CH, DL

I'm using Ubuntu 22.04

  • 1
    That looks like masm syntax (except for the `{}` which is probably a comment and is easy to filter out.) On linux you might want to use jwasm. – Jester Jul 06 '22 at 21:45
  • 3
    @Jester `{load}` is not a comment but a "pseudo prefix" for the Gnu assembler to select the load form of the instruction (https://sourceware.org/binutils/docs/as/i386_002dMnemonics.html#i386_002dMnemonics). – Andreas Abel Jul 06 '22 at 22:57
  • @Jester: GAS's `.intel_syntax noprefix` is MASM-like. – Peter Cordes Jul 07 '22 at 00:02

1 Answers1

2

The instructions generated from the XML file are intended to be used with the Gnu assembler (in Intel syntax mode).

You have to add the line .intel_syntax noprefix to the beginning of your file:

.intel_syntax noprefix

DEC R8W
LOCK ADC byte ptr [0xB8], 0x82
IN AX, DX
BTR qword ptr [RBX], 0xF7
IN EAX, DX
ADD RAX, 0x25C9FB2C
LOCK BTC qword ptr [RBP], 0xA5
CMOVBE ESI, R10D
{load} MOV CH, DL

Then, you can generate an executable by running as <filename>.

Andreas Abel
  • 1,376
  • 1
  • 10
  • 21