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

10 replies · 3K views · last reply
Pipsqueakalchemist
Messages
142
Reaction score
20
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.

Table titled Instruction Set listing ALU mnemonics with description and opcode columns, from LDR1 (opcode 0) through BNEQZ (opcode D), including arithmetic, logic and control flow operations.

Task 2 page showing a loop example for (i = 5; i >= 0; i--) {result = result + x} and a table of seven assembly instructions: LDRC 5, LDR1 0, ANDA, LDR1 X, LOOP: ADD, DECRC, BNEQZ LOOP, with their results.

State diagram titled FSM implementation of PC for task-2, showing states S0 LDR0, S1 LDR1, S2 ANDA, S3 LDR1, S4 ADD, S5 DECRC, S6 BNEZ and S7 End, with a loop from S6 back to S4 labelled RC!=0 and an exit to S7 labelled RC=0.
 
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?
 
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.
 
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".