Lecture Notes # 8 Outline of The Lecture: Control Transfer Instructions CALL Statement Subroutines
Lecture Notes # 8 Outline of The Lecture: Control Transfer Instructions CALL Statement Subroutines
Lecture Notes # 8
short near
Instruction Description Flags jump jump
opcodes opcodes
JO Jump if overflow OF = 1 70 0F 80
JNO Jump if not OF = 0 71 0F 81
overflow
JS Jump if sign SF = 1 78 0F 88
JNS Jump if not sign SF = 0 79 0F 89
JE Jump if equal ZF = 1 74 0F 84
JZ Jump if zero
JB Jump if below CF = 1 72 0F 82
JNAE Jump if not
JC above or equal
Jump if carry
1
short near
Instruction Description Flags jump jump
opcodes opcodes
JNB Jump if not CF = 0 73 0F 83
JAE below
JNC Jump if above or
equal
Jump if not carry
JA Jump if above CF = 0 77 0F 87
JNBE Jump if not
and ZF
below or equal
=0
JL Jump if less SF <> 7C 0F 8C
JNGE Jump if not
OF
greater or equal
JG Jump if greater ZF = 0 7F 0F 8F
JNLE Jump if not less
and SF
or equal
= OF
JP Jump if parity PF = 1 7A 0F 8A
JPE Jump if parity
even
2
CALL STATEMENTS
Another control transfer instruction is the CALL instruction, which is
used to call a procedure
The target address can be in the current segment, hence a NEAR call
(IP is changed CS is not)
The target address can be outside the current segment, hence FAR call
(IP and CS are changed)
To make sure that after the execution of the called subroutine the
microprocessor knows where to come back, the microprocessor
automatically saves the address of the instruction following the call on
the stack.
The last instruction of the called subroutine must be RET (return)
instruction, which directs CPU to pop the address of the next
instruction before the called subroutine to be restored.
SUBROUTINES
In Assembly Language there can be one main program and many
subroutions called from the main program. Subroutines are organized as
procedures. PROC can be FAR or NEAR. If not mentioned, by default a
PROC is NEAR
Shell of the Assembly Language Subroutines
;-------------------------------------------------------
CODSEG SEGMENT
MAIN PROC FAR
ASSUME .
MOV AX,
MOV DA,AX
CALL SUBR1
CALL SUBR2
CALL SUBR3
MOV AH,4CH
INT 21H
MAIN ENDP
;----------------------------------------------------
SUBR1 PROC
RET
SUBR1 ENDP
;----------------------------------------------------
SUBR2 PROC
RET
3
SUBR2 ENDP
;----------------------------------------------------
SUBR3 PROC
RET
SUBR3 ENDP
;----------------------------------------------------
CODSEG ENDS
END MAIN
4
Assembly language programs examples
.MODEL SMALL
.STACK 100H
.DATA
PROMPT DB 'The counting from 0 to 9 is : $'
.CODE
MAIN PROC
MOV AX, @DATA ; initialize DS
MOV DS, AX
5
INT 21H
MAIN ENDP
END MAIN
;------
;OUTPUT
;------
; 0123456789
Note
MOV DL, 48 is equivalent to MOV DL, 0. 48 is the ASCII code to 0.
6
Output a string
MOV DX, ...
MOV AH, 09h
INT 21h
Load the address of a '$'-terminated string into DX, then call the interrupt
with function code 9 in AH.