Reputation: 2105
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
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:
mov byte ptr [x], y
vs mov dword ptr [x], y
movb $y, x
vs movl $y, x
sb $t0, ($t1)
vs sw $t0, ($t1)
stb %g0, [%o0]
vs st %g0, [%o0]
strb r0, [r1]
vs str r0, [r1]
move.b #0, (A0)
vs move.l #0, (A0)
Upvotes: 1