Skip to content

AsmX G2 v5 Technical Overview

Compare
Choose a tag to compare
@TaiHusk TaiHusk released this 21 Jun 13:09
· 9 commits to main since this release

AsmX G2 v5: Enhanced 32-bit Registers and Sign Extension Instructions

This release of AsmX G2 introduces two new 32-bit registers and two powerful sign extension instructions:

New Registers:

  • $ebx: A general-purpose 32-bit register.
  • $ecx: A general-purpose 32-bit register.

New Instructions:

  • movzx: Move with Zero Extension. This instruction copies the value of a source operand into the destination register, zero-extending it to the size of the destination register. This means that the higher bits of the destination register are filled with zeros.

    Example:

    @movzx $eax, 10  
    

    This will move the value 10 (0x0A) into the $eax register, resulting in $eax holding the value 0x0000000A.

  • movsx: Move with Sign Extension. This instruction copies the value of a source operand into the destination register, sign-extending it to the size of the destination register. This means that the higher bits of the destination register are filled with the sign bit of the source operand.

    Example:

    @movsx $ax, 10
    

    This will move the value 65530 (0x0000fffa) into the $ax register, resulting in $ax holding the value 0x0000fffa.

Example Usage:

@function main {
   @mov $eax, 14                         # Assign 14 to $eax
   @push $eax                              # Push $eax onto the stack
   @system 4                                # Print 14 (0x0000000e)

   @mov $ebx, $eax                     # Copy the value of $eax into $ebx

   @call calloc(4, sizeof(uint8))    # Call calloc to allocate memory
   @push $ax                              # Push the return value (memory address) onto the stack
   @system 4                              # Print the <ptr *> address

   @mov $eax, $ebx                  # Copy the value of $ebx back into $eax
   @push $eax                          # Push $eax onto the stack
   @system 4 #0x0000000e      # Print 14 (0x0E) again

   @movzx $eax, 65535            # Zero-extend 65535 (0xFFFF) into $eax
   @push $eax                         # Push $eax onto the stack
   @system 4 #0x0000ffff        # Print 65535 (0xFFFF)

   @movsx $ax, 139                # Sign-extend 139 (0x8B) into $ax
   @push $ax                         # Push $ax onto the stack
   @system 4 #0x0000ff8b    # Print 65419 (0xFF8B)
}

Benefits:

  • Increased Register Availability: The addition of $ebx and $ecx provides more flexibility for storing and manipulating data.
  • Enhanced Sign Handling: The movzx and movsx instructions allow for precise control over how values are extended during data movement, preventing unexpected sign-related errors.

This release significantly enhances the capabilities of AsmX G2, making it more powerful and versatile for low-level programming tasks.