Puchacz
Puchacz

Reputation: 2105

Store variable with specific length in memory

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.

Upvotes: 2

Views: 110

Answers (1)

Jester
Jester

Reputation: 58772

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)

Upvotes: 1

Related Questions