I have some memory address 0x00000100 that I want to read from. The lower 4 bits read from this address indicates the states of 4 buttons - So bit 0 shows the state of button 0, bit 1 shows the state of button 1, etc. My question is- How can I find determine the state of button 0 and button 1 in assembly language? I want to know when button 0 and button 1 are high.

I am using a MiteFPGA processor, and Xilinx Vivado, on a basys 3 board. I am using the MiteASM assembler.

  • \$\begingroup\$ If button 1 is high I want t increment a counter, whereas if button 0 is high, I want to reset it. I think I have the other details of assembly language sorted, but it's this reading from particular bytes of memory address 0x100 that is getting me. \$\endgroup\$ – Angela May 27 at 23:21
  • \$\begingroup\$ You don't want to read specific bytes, but specific bits. I can't find information on your MiteFPGA CPU. Please supply some documentation. \$\endgroup\$ – Janka May 27 at 23:54
  • 1
    \$\begingroup\$ The typical way is to read the byte with the interesting bits into an ALU register, then bit-test on them. Depending on the CPU, it may also be possible to have this bit-test done directly with memory, or there aren't bit-test instructions which means you had to AND the ALU register against a mask and check the zero flag. \$\endgroup\$ – Janka May 27 at 23:55

You want to use the 'lw' operation (load word) to grab 0x100 it has the format 'lw $rt SignImm($rs)'. Then you need to do an 'and' operation with the appropriate bit mask to extract the state of that bit. The and op is in the form 'and $rd, $rs, $rt'.

So say the bottom 4 bits are: 1001, and you AND that with 1000. The result will be 1000, telling you that the 4th bit is a 1.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.