Assembly: If (MASM/TASM)

Posted March 5, 2006 by William_Wilson in Computer programming

Last Updated on

This tech recipe explains how to implement the in Assembly, the effect of the if statement, which is available to other languages.

Being that Assembly is a low-level language, as opposed to the high-level languages to which most programmers are accustomed (e.g., Java, C, C++, Perl, etc.), it does not have all the same features that these languages have (such as an if statement). However, it can be implemented in a more basic way.

Assembly language runs top down, from label to label through the main of the program. It only varies upon jumps etc. (This is described in full later.) We can take advantage of this to implement our if.


result_msg DB 'true inside if statement',0

INCLUDE io.mac

main PROC

mov Ax,0
cmp Ax,0
jne done

putStr result_msg


main ENDP
END main

The output will be as follows: true inside if statement. Try changing the value placed into Ax. Anything else and it will print out nothing. The if condition will not be satisfied.

Combining the compare and jump on not equal or any other dynamic jump is the basis of an if statment.

Questions/Comments: [email protected]
-William. ยง (marvin_gohan)

The Conversation

Follow the reactions below and share your own thoughts.

Leave a Reply