1

For example you have the code:

addi $s1, $zero, 0x1234

andi $t0, $s1, 0x0f0f

You can figure out what goes in $t0 by converting 0x1234 (the value inside $s1) and 0x0f0f into binary code and doing the AND operation from the two numbers. However, is there another way you can figure out the answer without converting to binary code?

  • 2
    Well, in this particular case it's trivial, because 0 is "nothing" and F is "everything". So you drop the 1 and 3, and keep the 2 and 4, i.e. `0x0204`. In general you just got to learn how to visualize each hexadecimal digit as a group of four bits. – Michael May 16 '18 at 05:36
  • Sure, instead of doing it in your head, use a calculator or MIPS assembler. e.g. `addiu $t0, $zero, 0x1234 & 0x0f0f` and look at the disassembly output. If you do want to do it in your head, then like Michael said look at each 4-bit hex digit separately. – Peter Cordes May 16 '18 at 06:06
  • 1
    @PeterCordes btw MARS (and also SPIM?) don't support math expressions, so this option may be not available to OP, depends which MIPS assembler the OP is using. It's quite annoying in MARS, when you need for example something like label2-label1, etc... But that's how it is. Maybe one day somebody will fork it and rewrite the parser to fix all those problems. :) – Ped7g May 16 '18 at 10:55

0 Answers0