2
votes

I read about virtual machines for languages like C#, Java etc... and I can't understand one of the details how processor know how much data should it write. Let's assume following syntax:

mov [A], 'A';

A is virtual register and 'A' is just 8bit length sign. [A] means that in register is address where in memory will be stored our variable. Let's assume that our register is 32bit length. How does processor will know that we only need to store in memory first 1 byte and others 3 are irrelevant? We can't just load to memory full 32 bits becouse we would override something.

The only idea i could imagine is to create instructions specialized instructions like mov byte, move word etc... but i think it's not best solution.

My question isn't probably 'processor specific', i would like to know what's general rule.

1
The operation size is indeed encoded in the instruction. The syntax depends on architecture, it may be a different mnemonic or some sort of modifier/suffix, or an operator. - Jester
What do you mean by "others 3"? The size of the register A has nothing to do with its contents, or with the semantics of the move operation. As you said yourself, [A] means "use the memory whose address is stored in A". - Kerrek SB
Others 3 means that we placed in register for example char and others bits out of our first 8 bits are irrelevant for us and shouldn't be stored in memory. @Jester - would you provide some simple example? - Puchacz

1 Answers

1
votes

The operation size is indeed encoded in the instruction. The syntax depends on architecture, it may be a different mnemonic or some sort of modifier/suffix, or an operator.

Some examples:

  • x86 intel syntax: mov byte ptr [x], y vs mov dword ptr [x], y
  • x86 at&t syntax: movb $y, x vs movl $y, x
  • mips: sb $t0, ($t1) vs sw $t0, ($t1)
  • sparc: stb %g0, [%o0] vs st %g0, [%o0]
  • arm: strb r0, [r1] vs str r0, [r1]
  • 68k: move.b #0, (A0) vs move.l #0, (A0)