BetterOS.org : an attempt to make computer machines run better

BetterOS.org : an attempt to make computer machines run better


home | better linux | games | software | tutorials | reference | web log |
index | syscalls | calling conventions | instructions | x11 | reusable code |
introduction:

This is meant to be a useful list of AMD64 (x86_64) instructions, along with descriptions, operands, and registers needed. This is not an exhaustive list, just a quick and useful reference.


mission:

To help people learn to program efficiently and correctly. To get people back to producing good code again until the rest of the world starts to notice the difference.


InstructionOperandsInformation
OpcodeMnemonicName123DescriptionTips
movMovedestinationsourceCopies data from source to destination. Cannot copy from memory to memory, only register to memory, memory to register, or register to register.
leaLoad Effective AddressdestinationsourceStores an address from source in destination.Can also be used to perform simple math.
addAdddestinationsourceAdds operands and stores result in destination.This sets relavent flags.
subSubtractdestinationsourceSubtracts source from destination and stores result in destination.This sets relavent flags.
syscallSystem CallExecutes a system call.System V Calling Convention states that rax should contain the syscall number.
callCalladdrCalls routine at addr. This also pushes the return address onto the stack.
retReturnReturns execution to the caller (return address).System V Calling Convention states that rax should contain returned 64-bit data, or xmm0 should contain returned 128-bit data.
cmpCompareabCompares a to b and sets relavent flags.
jmpJumpaddrJumps to addr.No return address is pushed to the stack.
jeJump if EqualaddrJumps to addr if the zero flag is set.Zero flag will be set if previous comparison was equal.
jzJump if ZeroaddrJumps to addr if the zero flag is set.Zero flag will be set if previous comparison was equal.
jneJump if Not EqualaddrJumps to addr if the zero flag is clear.Zero flag will be clear if previous comparison was not equal.
jnzJump if Not ZeroaddrJumps to addr if the zero flag is clear.Zero flag will be clear if previous comparison was not equal.
jaJump if AboveaddrJumps to addr if the zero flag is clear and carry flag is clear.Used for comparisons of unsigned intagers.
jnbeJump if Not Below or EqualaddrJumps to addr if the zero flag is clear and carry flag is clear.Used for comparisons of unsigned intagers.
jbJump if BelowaddrJumps to addr if the carry flag is set.Used for comparisons of unsigned intagers.
jnaeJump if Not Above or EqualaddrJumps to addr if the carry flag is set.Used for comparisons of unsigned intagers.
jnbJump if Not BelowaddrJumps to addr if the carry flag is clear.Used for comparisons of unsigned intagers.
jaeJump if Above or EqualaddrJumps to addr if the carry flag is clear.Used for comparisons of unsigned intagers.
jnaJump if Not AboveaddrJumps to addr if the carry flag is set or zero flag is set.Used for comparisons of unsigned intagers.
jbeJump if Below or EqualaddrJumps to addr if the carry flag is set or zero flag is set.Used for comparisons of unsigned intagers.
jgJump if GreateraddrJumps to addr if the zero flag is clear and sign flag is equal to overflow flag.Used for comparisons of signed intagers.
jnleJump if Not Lesser to EqualaddrJumps to addr if the zero flag is clear and sign flag is equal to overflow flag.Used for comparisons of signed intagers.
jlJump if LesseraddrJumps to addr if the sign flag is not equal to overflow flag.Used for comparisons of signed intagers.
jngeJump if Not Greater to EqualaddrJumps to addr if the sign flag is not equal to overflow flag.Used for comparisons of signed intagers.
popcntPopulation CountdestinationsourceCounts the number of bits set in source and stores result in destinationOnly available in processors with at least SSE4.2 or SSE4.a support.
mulMultiply UnsignedmultiplierMultiplies rax (or eax or ax depending on size of multiplier) by the multiplier. Result is stored in rdx:rax.cannot multiply by an immediate.
imulMultiply SignedmultiplierMultiplies rax (or eax or ax depending on size of multiplier) by the multiplier. Result is stored in rdx:rax.cannot multiply by an immediate.
divDivide UnsigneddivisorDivides rdx:rax (or edx:eax or dx:ax depending on size of divisor) by the divisor. Result is stored in rax.cannot divide by an immediate.
idivDivide SigneddivisorDivides rdx:rax (or edx:eax or dx:ax depending on size of divisor) by the divisor. Result is stored in rax.cannot divide by an immediate.
shlShift LeftdestinationcountPerforms a binary left shift on destination by the count.count must either be an immediate or the cl register.
shrShift RightdestinationcountPerforms a binary right shift on destination by the count.count must either be an immediate or the cl register.