In a ALU in a simple processor, what does the operation BNEQZ mean?

  • Thread starter Thread starter Pipsqueakalchemist
  • Start date Start date
  • Tags Tags
    Alu Mean Processor
AI Thread Summary
BNEQZ is an assembly language instruction that stands for "Branch if Not Equal to Zero." It checks the value of the RC register; if RC is not zero, the processor branches back to a specified loop label, allowing the program to repeat a sequence of instructions. In the discussed example, RC is initialized to 5 and decremented in each loop iteration until it reaches zero, at which point the loop stops executing. The instruction essentially controls the flow of the program by determining whether to continue looping or proceed to the next code block. Understanding BNEQZ is crucial for implementing loops effectively in assembly programming.
Pipsqueakalchemist
Messages
138
Reaction score
18
TL;DR Summary: So I'm doing this coding assignment that involves a simple processor with an ALU. I have a list of operation of the ALU but I don't understand one operation called BNEQZ. I have the list of operation below and an example of it being used to form some loop. Would be very grateful if someone here can explain what the operation means and how it works in the example.

1669517777591.png

1669517841582.png

1669517923301.png
 
Physics news on Phys.org
I assume it means branch on not equal To zero

EDIT: Ah, I see it's even in the table, so it must mean branch if register RC is not equal to zero
 
Is there a typo in your question? BNEQZ is in the table you posted.
 
Vanadium 50 said:
Is there a typo in your question? BNEQZ is in the table you posted.
I know but I'm not sure what it means. Does it mean that if RC is not equal to zero then it will return to state zero and if it's equal to zero it just continues with the current program?
 
jedishrfu said:
Do you understand how bneqz works now?
Nope, still trying to figure it out
 
In assembler code, branching operations test for a register condition. In this case, the BNEQZ will look to see if the RC register is not zero. If not zero then it will branch to the loop label and repeat the loop.

RC is initialized to 5 in line 1. your program executes lines 2,3,4,5,6 and then line 7 where RC is decremented by 1 meaning it’s now a 4. 4 is non zero so the bneqz op branches back to line 5 and repeats the loop.

Do you see how it works now? What happens when RC is zero?
 
jedishrfu said:
In assembler code, branching operations test for a register condition. In this case, the BNEQZ will look to see if the RC register is not zero. If not zero then it will branch to the loop label and repeat the loop.

RC is initialized to 5 in line 1. your program executes lines 2,3,4,5,6 and then line 7 where RC is decremented by 1 meaning it’s now a 4. 4 is non zero so the bneqz op branches back to line 5 and repeats the loop.

Do you see how it works now? What happens when RC is zero?
Ok first off thank you for not insulting me. And yes I think got it now, so it will keep getting stuck in the loop until RC is decremented to zero. So if RC isn't zero it will return to the adder state, so in that state It should add X to X during the first loop, then after RC will decrement by 1 so RC = 4 - 1, and then it will return to the add state where it will be X + X +X. Basically it will keep adding X until RC is zero then it will stop.
 
Pipsqueakalchemist said:
Ok first off thank you for not insulting me. And yes I think got it now, so it will keep getting stuck in the loop until RC is decremented to zero. So if RC isn't zero it will return to the adder state, so in that state It should add X to X during the first loop, then after RC will decrement by 1 so RC = 4 - 1, and then it will return to the add state where it will be X + X +X. Basically it will keep adding X until RC is zero then it will stop.
Also in picture 2 in the instruction sequence. Is it in the last instruction in the sequence, instruction 7 where it says BNEQZ loop, is that where the address of the loop state is set. So in this case the address of the loop state is the adder state so instruction 7 BNEQZ loop means it's setting the adder state as the state where the loop will restart from?
 
  • #10
Pipsqueakalchemist said:
wow, well thank you for the insult, now I know not to use these forums anymore
Ignore it. You will get answers from others.
It will depend on the processor. It may be a macro rather than a native mnemonic.

"BNEQZ loop" suggests the processor is counting down to zero, and so must Branch back to do the loop again if the status register is Not EQual to Zero. When the counter reaches zero, the processor will not loop but will continue with the next code block.
 
  • #11
Have you been told to call that diagram a finite state machine? I would call this a "flowchart": calling it a FSM is confusing because it doesn't show the complete set of states: in particular it doesn't show the RC register.

Pipsqueakalchemist said:
Also in picture 2 in the instruction sequence. Is it in the last instruction in the sequence, instruction 7 where it says BNEQZ loop, is that where the address of the loop state is set. So in this case the address of the loop state is the adder state so instruction 7 BNEQZ loop means it's setting the adder state as the state where the loop will restart from?
LOOP is just a label for sequence number 5. So BNEQZ loop means "If the RC register is not equal to zero, the next instruction to execute is at sequence number 5".
 
Back
Top