What does the BEQ instruction do exactly?

jazzybazz picture jazzybazz · Feb 5, 2012 · Viewed 77.2k times · Source

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?

Answer

Sedat Kapanoglu picture Sedat Kapanoglu · Feb 5, 2012

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.