Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid goto and jump when coding in assembly?

Tags:

assembly

goto

I'm aware of the numerous posts here and elsewhere on avoiding goto in high-level programming languages. However from the (admittedly small) experience I've had coding in MIPS assembly, there doesn't seem to be an obvious way to avoid goto and jump statements in assembly when implementing control flow.

For example how would this code be implemented in assembly (C equivalent):

if (x < 2)
  { ans = 0; }
else
  { ans = 1; } 

Would the use of a goto or jump statement be necessary, or is there a proper way of avoiding them in favor of more appropriate code practices?

like image 746
rasz Avatar asked Nov 30 '22 16:11

rasz


1 Answers

The recommendation to avoid goto in high-level programming languages only applies to - well - high-level languages.

Assembler is a low-level language and jumps are essential.

like image 120
Nils Pipenbrinck Avatar answered Dec 05 '22 05:12

Nils Pipenbrinck