Professional Documents
Culture Documents
Lesson plan
Review
Program logic and control
Practice exercise
Assembling, Linking and Executing Programs
Practice exercise
Review
IMUL register/memory
If operand is a byte
AX
AX=
= AL * operand
Review
MOV CX, 10
BEGINLOOP :
.
DEC CX
JNZ BEGINLOOP
OR
MOV CX, 10
BEGINLOOP :
LOOP BEGINLOOP
Far: distance over 32K for the same segment address or in another
segment
Transfer operations
JMP
short/near/far address
Transfer operations
Backward jump
BEGINLOOP:
BEGINLOOP:
.
JMP BEGINLOOP
Forward jump
JMP STARTLOOP
STARTLOOP:
STARTLOOP:
.
Loop instruction
Loops a specified number of times
CMP Instruction
[label:] CMP register/memory,
register/memory/immediate
[label:] JE/JZ
short
short--address
[label:] JNE/JNZ
shortshort-address
Flag:: ZF
Flag
Example
MOV AL, 5
CMP AL, 5
JE label1
label1
JMP exit
label1
label
1: MOV CX, BX
exit:
..
shortshort-address
Example
MOV AL, 5
CMP AL, -5
JG label1
label1
JMP exit
label1
label
1: MOV CX, -5 ; in this case AL > -5
exit::
exit
instruction). Signed.
Example
MOV AL, -2
CMP AL, 5
JL label1
label1
JMP exit
label1
label
1: MOV CX, 5
exit::
exit
Flag:: ZF
Flag
e.g. Write a program to compute sum of even integers from 1 to 100 using LOOP
[label:] JBE/JNA
short
short--address
Flag: AF, ZF
e.g. Write a program that adds each value defined in BYTE_TBL and store
the sum in BYTE_TOTAL
BYTE_TBL
DB
BYTE_TOTAL DB
0,5,6,4,9,7
0
Executing Programs
Create *.asm
Editor
Assembler
Assemble *.asm
And create *.obj
Linker
Link
And create *.exe
Assembling
*.asm
program
NAME CLASS
00000H
00000
H 0003FH
0003FH 0040H
0040H
STACK STACK
00040H
00040
H 00045H
00045H 0006H
0006H
DATASEG DATA
00050H
00050
H 00063H
00063H 0014H
0014H
CODESEGCODE
Procedures
Procedure is a part of code that can be called from your
understand.
Returns to the same point from where it was called.
Syntax:
name PROC
; the code of the procedure ...
RET
name ENDP
Procedure Call
CALL instruction is used to call a procedure
CALL is used to transfer controls
RET is used to end execution of procedure
Syntax:
Example
CALL m1
m1
MOV AX, 2
RET ; return to operating system.
m1
PROC
MOV BX, 5
CALL m2
m2
RET ; return to caller.
m1
ENDP
m2
PROC
MOV CX, 10
RET; return to caller
m2
ENDP