Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the BEQ instruction do exactly?

I have the following assembly code snippet I am trying to understand. It is assembly for a MC68332 microcontroller.

LOOP
    some instructions
    some more instructions
BEQ LOOP

I've googled BEQ and I have found it means branch on result zero, but I still don't really understand what it does. Does it compare the result of the last instruction to 0, and if it is 0, it goes back to the LOOP line?

like image 225
jazzybazz Avatar asked Feb 05 '12 20:02

jazzybazz


2 Answers

On Motorola 68k family, it stands for "branch if equal" which means "jump to given address if zero flag is set" such as when previous comparison is successful.

However, 68332 seems to be different. Based on uppercase syntax, it could be a macro around another instruction which essentially does the same thing.

Assembly programmers who port code from other systems can make use of similar macros to ease the porting process.

like image 123
Sedat Kapanoglu Avatar answered Nov 19 '22 18:11

Sedat Kapanoglu


The exact answer will depend on which microcontroller you are using. In general, if there are no operands, BEQ would be expected to branch if the Accumulator is 0. This is most likely on simple micros where the Accumulator is the primary register for calculations.

Which microcontroller are you using? You should be able to find a definition for the BEQ instruction in the manual for that micro.

like image 27
Stefan Avatar answered Nov 19 '22 19:11

Stefan