Knowing my PC address is 0x00402000, what is it's value after a:
beq $t0 $t0 64
?
How can I calculate this?
Unfortunately, your question is confounded by the fact that the 64
there is unclear in meaning.
For example, the two popular MIPS simulators used in education: the MARS simulator and the QtSPIM simulator (each with their own integrated assembler) reject that line of assembly code!
Most assembly branch instructions will use a label as the target rather than a number — the intent of the usage of a label there is clear: go/branch to the next instruction after the label.
Is this line of assembly supposed to mean the value 64 is:
Because of these issues it would be better (for your coursework/material) to have asked the question in terms of machine code encoding rather than in terms of assembly language: the immediate in the I-type instruction is value X.
Even if you know which of the above, the answer depends on the environment you're using. For example, MARS uses PC+4 as the base (whether branch delay slots are disabled or enabled) so if the immediate encoded in the instruction is -1 it will branch to self — whereas QtSpim uses PC+0 as the base, if delay slots are disabled (as by default) so if the immediate encoded in the instruction is 0 it will branch to self (and uses PC+4 as base if delay slots are enabled). Still, PC+4 is probably the proper base to use and I might consider QtSpim's choice of PC+0 under delay slot disabled as broken. So, the rest of this answer will ignore QtSpim with default options.
If the value 64 refers to:
the actual immediate, then the branch target will be PC+4 + (SignExt32(imm16) << 2), where the immediate value, 64, is the actual imm16 16-bit immediate encoded in the instruction, and that value is sign extended to 32 bits (so still is 64 but now in 32 bits).
a byte offset, then we would use the same formula but without the shift by 2 (without scaling/muliplying by 4).
There is no way to reach absolute address 64 given a current PC of 0x00402000 — the minimum address you could reach with an I-Type branch instruction is about 0x00338260. A J-type instruction (e.g. j
) could get there from your premise PC. However, let's note that RISC V (the newest relation to the MIPS-style architecture line) linux assembler would have considered this as the intent and emitted an instruction sequence that would go to absolute location 64.