Professional Documents
Culture Documents
Jimp
Jimp
Jimp
CMP AX,4372H
JB label 1
Label1: __________
Branch Instructions
Jump Instructions are used for changing the flow of execution
of instructions in the processor. If we want jump to any
instruction in between the code, then this can be achieved by
these instructions. There are two types of Jump instructions:
• FAR - In this procedure, the target is outside the segment and the size of the
pointer is double word. (Inter-segment)
CMP BX,DX
JE DONE ; if true ZF=1
SUB BX,AX
INC CX
DONE: MOV AX,CX
JNZ/JNE(Branch on Non Zero/Branch on
Not EQUAL)
JNZ OPR
MOV BX,2374H
NXT : ADD AX,0002H
DEC BX
JNZ NXT
JS(Branch on Sign Bit)
ADD BL,DH
JS print ;SF=1
PRINT: ________
JO (Branch on overflow) OF =1
ADD BL,BL
JO Error
MOV SUM,AL
• Error: ________
JNO OPR(Branch on NO OVERFLOW) OF=0
JPE/JP (Branch on Parity/Branch on even parity) PF=1
JP OPR
IN AL,F8H
OR AL,AL
JPE Error
Error:_________
• +127
• +127 using 8 bit register =254
• 1111(binary)- 2 ( in 2’scomplement)
• Negative result out of positive operand is overflow
128 64 32 16 8 4 2 1
1 1 1 1 1 1 0
1s complement 0 0 0 0 0 0 1
2s complement 1
0 0 0 00 010
JB/JNAE/JC(Branch on below/not above/not EQUAL)
• CF=1
JB OPR
• CMP CX,BX
• CF ZF SF
• CX=BX 0 1 0
• CX>BX 0 0 0
• CX<BX 1 0 1
• CMP AX,4372H
• JB label 1
• Label1: __________
JNB/JAE/JNC (CF=0)
JNLE/JG
• CF=OF
LOOP instruction
• Number of count loaded in CX
• CX automatically decremented
• If CX != 0 execution jump to label
• If CX= 0 next instruction executed
• MOV BX,OFFSET ARRAY
• MOV CX,04
• NEXT : MOV AL,[BX]
• ADD AL,07H
• DAA
• MOV [BX},AL
• INC BX
• LOOP NEXT
LOOPZ/LOOPE(LOOP WHILE ZERO OR EQUAL)
• LOOPZ
• Repeat until ZERO FLAG =0
• If CX !=0 & ZF =1 execution jump to label
specified
• IF CX = 0 or ZF=0 execution go to next instruction
• MOV BX,OFFSET ARRAY
• MOV CX,08
• NEXT: INC BX
• CMP[BX],0FFH
• LOOPE NEXT
LOOPNZ/LOOPNE(LOOP WHILE NON ZERO
OR NOT EQUAL
• ZF=0 & CX !=0 🡪 EXECUTION GOES TO LABEL
• JCXZ SKIP_LOOP
• NEXT : SUB[BX],07H
• INC BX
• LOOP NEXT
• SKIP_LOOP:________
NOP(NO OPERATION PERFORMED)
• It is used to insert delay
• Uses 3 clock cyles
• No flags affected
• Delay can be incremented
• Ex : MOV CX,N ;4
Back : NOP ;3
• NOP ;3
• Loop Back
Memory Organization
• The assembler uses two basic formats for
developing software:
– one method uses models; the other uses full-
segment definitions
• Memory models are unique to MASM.
• The models are easier to use for simple tasks.
• The full-segment definitions offer better
control over the assembly language task and
are recommended for complex programs
Full-Segment Definitions
• Full-segment definitions are also used with
the Borland and Microsoft environments for
procedures developed in assembly language.
• The names of the segments in this program
can be changed to any name.
• Always include the group name ‘DATA’, so the
Microsoft program CodeView can be used to
symbolically debug this software.
• data segment
• a dw 9A88h
• b dw 8765h
• c dw ?
• data ends
• code segment
• assume cs:code,ds:data
• start:
• mov ax,data
• mov ds,ax
• mov ax,a
• mov bx,b
• sub ax,bx
• mov c,ax
• Mov ah,4ch
• Int 21h
• code ends
• end start
Models
• There are many models available to the MASM
assembler, ranging from tiny to huge.
• Special directives such as @DATA are used to identify
various segments.
• Models are important with both Microsoft Visual and
Borland development systems if assembly language is
included with programs
.TINY - Code & data segment <=64K
.SMALL – Code<=64k, Data <=64K
.MEDIUM- Data <=64k, Code any size
.Model small ; is used when DS<=64 K, S<=64K
.Data
Msg db “be good$”
.Code
Mov ax,@data
Mov ds,ax
Lea dx, msg
Mov ah,9 ; display a message
Int 21h
Mov ah,4ch; exit
Int 21h
END