MASM2
MASM2
Programming
Machine-Level and Systems Programming
Dr. Rahul Raman
Mr Sukesh Babu V S
• These instructions compare or match bits of the operands and set the CF, OF, PF, SF and
ZF flags.
• The AND instruction is used for supporting logical expressions by performing bitwise
AND operation.
• The bitwise AND operation returns 1, if the matching bits from both the operands are 1,
otherwise it returns 0.
• The AND operation can be used for clearing one or more bits.
Example:
• The processor instruction set includes a group of loop instructions for implementing
iteration.
Syntax:
Loop Label
• Where, label is the target label that identifies the target instruction as in the jump
instructions.
• The LOOP instruction assumes that the ECX register contains the loop count.
• When the loop instruction is executed, the ECX register is decremented and the control
jumps to the target label, until the ECX register value, i.e., the counter reaches the value
zero.
Dept of CSE, IIITDM 22
Program to count from 0 to 9
.model small loop1:
.stack 100h add dl,30h ; to ascci for display
.data mov ah, 02h
msg db "The counting from 0 to 9 is $" int 21h
sub dl,30h ; to binary for increment
.code inc dl
mov ax, @data dec cx
mov ds,ax jnz loop1
mov ah, 09h
lea dx, msg ; for printing the result
int 21h ; should be in dx or dl mov ax, 4c00h
mov cx,10h int 21h
mov dl,0h end
mov eax,'3’
sub eax, ‘0’ ; convert ASCII form to binary
mov ebx, '4’
sub ebx, ‘0’ ; convert ASCII form to binary
add eax, ebx
add eax, ‘0’ ; convert binary to ASCII for display
• Where, 31H is ASCII value for 1, 32H is ASCII value for 2, and so on.
• There are four instructions for processing numbers in ASCII representation:
• AAA - ASCII Adjust After Addition • AAM - ASCII Adjust After Multiplication
• AAS - ASCII Adjust After Subtraction • AAD - ASCII Adjust Before Division
Dept of CSE, IIITDM 25
mov al, ‘9’ ; first operand
sub al,’0’ ; can be avoided
sub al, ‘3’ ; al=9-3
or al, 30h ; or al with 0
mov [res], ax
• The data definition directives can be used for defining a one dimensional array.
• The above definition declares an array of six words each initialized with the numbers 34,
45, 56, 67, 75, 89.
Multiple initializations
• The DUP assembler directive allows multiple initializations to the same value
Syntax:
marks DW 8 DUP (0)
• The called procedure returns the control to the calling procedure by using the RET
instruction.