HomeComputer programmingAssembly: If (MASM/TASM)

Assembly: If (MASM/TASM)

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.

Example:

.MODEL SMALL
.STACK 100H
.DATA
result_msg DB 'true inside if statement',0

.486
.CODE
INCLUDE io.mac

main PROC
.STARTUP

start_go:
mov Ax,0
cmp Ax,0
jne done

putStr result_msg

done:
.EXIT

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)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!