Assembly: If (MASM/TASM)
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 most programmers are used to (eg: Java, C, C++, Perl, etc), it doesn't have all the same features that these languages have.. like an if statement, but it can be implemented in a more baic way.
assembly language runs top down, from label to label through the main of the program, only varying upon jumps etc (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 ouptput will be: 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: william_a_wilson@hotmail.com
-William. (marvin_gohan)
Also see ...
H3How to use mov/H3Pmov is a useful tool in assembly language, it can move constants, or dynamics such as offsets. br / br /span style="font weight: bold"mov/span takes 2 parameters, the first is the reciever and the second is the operand. br / br /span style="font weight: bold"E
H3How to use jmp/H3Pjmp used as a jump statement jumps from one place to another: br / br /span style="font weight: bold"Example:/span br /div class="code" br /.MODEL SMALL br /.STACK 100H br /.DATA br /result_msg DB 'true inside if statement',0 br /test
H3How to use the conditional jmp, jumps (je, jg, jl, jne, etc)/H3Pa conditional jump, is just that, it jumps on a condition, if the condition is false, then if continues with the next line. br /eg: br / br /cmp 0,1 br /je one_equals_0 br /mov AX,0 br / br /if je ret
H3The size and reason for defining different sized parameters/H3Pdiv class="code" br /&91;b&93;DB&58;&91;/b&93; Define Byte ;allocates 1 byte br /&91;b&93;DW&58;&91;/b&93; Define Word ;allocates 2 bytes br /&91;b&93;DD&
H3how to use the DUP duplicate command, nested or un nested/H3PAs it sounds, DUP duplicates text. br / br /span style="font weight: bold"Straight Example:/span br /div class="code" br /text DB 10 DUP &40;W&41; ;initializes 20 bytes to W br /P
