views:

75

answers:

3

What is the shortest way to fetch a value from memory in X86 Assembler?

+2  A: 

You mean other than mov register, [address]?

Dan Story
I just want the shortest way to get a value from memory into a CPU register. I don't mind which way...
Tony
well, that's it
klez
Assuming you're using Intel syntax you won't find a shorter or faster way than that. I'm not sure how to put this delicately... if you had to ask that question, I would strongly recommend getting a book on assembly language fundamentals before you go any further.
Dan Story
+1  A: 

OK, the shortest way is to pop registers, like pop eax, it's one byte instruction.
But that can be used only in special cases, where the stack pointer ESP will point to a buffer,
and probably you won't use the stack for other purpose until the code that uses it is done.

The standard way is to use the mov instruction.

Nick D
+3  A: 

There is no workaround in assembler haw to do that. All assembler instructions are strictly dedicated.

mov AL, 0x12

will load immediate the value 0x12 to register AL

xor  AL,AL

the result of operation in AL register is 0

lodsb

will load byte from DS:[ESI] (or DS:[SI] under 16 bit CPU) memory address to AL

mov AL,[ESI]

will load byte from DS:[ESI] (or DS:[SI] under 16 bit CPU) memory address to AL

mov AL,[0xFFFF]

will load byte from DS:[0xFFFF] memory address to AL

pop AX

will load byte from SS:[ESP] (or SS:[SP] under 16 bit CPU) memory address to AL

in AL, 0x123

will load byte from port address 0x123

xlatb [EBX + AL]

will load byte from DS:[EBX + AL] memory address

...

GJ