0% found this document useful (0 votes)
90 views11 pages

MP - Lec 05 - Program Control Instructions

This document provides an overview of program control instructions in assembly language. It discusses procedures which allow code reuse through functions called subroutines. Loop and jump instructions are also covered, including unconditional jumps, conditional jumps, and the loop instruction for repeating code a set number of times. Procedures use CALL and RET instructions and can be nested. Conditional jumps test flag bits set by comparison instructions to change program flow.

Uploaded by

uabdulgwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views11 pages

MP - Lec 05 - Program Control Instructions

This document provides an overview of program control instructions in assembly language. It discusses procedures which allow code reuse through functions called subroutines. Loop and jump instructions are also covered, including unconditional jumps, conditional jumps, and the loop instruction for repeating code a set number of times. Procedures use CALL and RET instructions and can be nested. Conditional jumps test flag bits set by comparison instructions to change program flow.

Uploaded by

uabdulgwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Microprocessor Course

LECTURE(05)

Program Control Instructions

1
Chapter Contents
❑ Procedures
❑ Loop instruction
❑ Unconditional jump instruction
❑ Conditional jump instructions

2
Procedures
❑ In assembly language functions are called procedures or subroutines.
❑ The CALL instruction links to a procedure and the RET instruction returns from a
procedure.
❑ Procedures use a PROC directive (followed by the type of the procedure: near or
far) to start and the ENDP directive to end the construct.
❑ CALL pushes the return address onto the stack and RET retrieves the return
address from the stack. The stack allows procedures to be nested.
❑ The USES statement allows any number of registers to be automatically pushed
into the stack.
GETIT PROC NEAR USES EAX
MOV EAX,99H
RET
GETIT ENDP

3
Procedures (cont’d)
❑ Write an assembly near procedure named display that prints a character
passed to it through DL into the screen. Then, use this procedure to
print OK onto the screen.
❑ Note:
▪ You could use function 6 to print the letters from DL to the screen

4
Procedures (cont’d)
.MODEL tiny ; Single tiny code segment
.CODE ; Start of code segment
.STARTUP ; Start of program
MOV DL, ‘O’ ; Copy letter ‘O’ to the DL
CALL display ; Call the procedure
MOV DL, ‘K’ ; Copy letter ‘K’ to the DL
CALL display ; Call the procedure
.EXIT ; Exit to DOS

display PROC NEAR ; Procedure to display the ASCI character in DL


MOV AH, 6 ; Select DOS function 6
INT 21h ; DOS function call
RET ; Return to the calling program
display ENDP ; End of procedure
END ; End of program
5
Loop Instruction
❑ Similar to the high level for loop in which the number of iteration is known apriori
❑ Before the beginning of the loop, the number of iterations should be stored in CX

MOV SI, OFFSET ARR1 ; Copy 1st address in the source to SI


MOV DI, OFFSET ARR2 ; Copy 1st address in the destination to DI
MOV CX, 5 ; Load counter register with 5 (5 iterations)
Again: MOV AL, [SI] ; Copy element from the source, addressed by SI to AL
MOV [DI], AL ; Copy AL to the destination element, addressed by DI
INC SI ; Increment SI (to next element)
INC DI ; Increment DI (to next element)
LOOP Again ; Repeat 5 times

6
Unconditional jump (JMP)
❑ The JMP instruction is a GOTO that is found in all computer languages.
JMP passes program flow to another part of the program.
❑ The JMP instruction comes in 3 forms, short, near, and far.
❑ Short and near are intra-segment jumps, whereas far is an intersegment
jump
❑ Usually, labels are used as jump targets. These labels should be
followed by colons

7
Unconditional jump (Cont’d)
❑ JMP has direct and indirect addressing modes
❑ Direct jumps use labels
JMP Again
❑ Indirect jumps take two forms. One jumps to the offset location
addressed by a register and the other jumps to the location addressed
by a memory pointer.
JMP CX
JMP EDX
JMP NEAR PTR [BX] ;16 bit
JMP FAR PTR [ECX] ;32 bit

8
Conditional Jumps
❑ Conditional jump instructions are always short jumps.
❑ Conditional jump instructions, for the most part, test the flag bits.
❑ Some check a single flag bit, while some check multiple flag bits.
❑ One set of conditional jumps test unsigned numbers (JZ, JNZ, JA, JB,
JAE, or JBE).
❑ One set of conditional jumps test signed number (JZ, JNZ, JG, JL, JGE,
and JLE).
❑ Conditional jumps usually follow a CMP or TEST instructions

9
Jump commands
❑ JZ: Jump if the result is zero
❑ JNZ: Jump if the result is not zero
❑ JC: Jump if there is a carry
❑ JS: Jump if result is negative
❑ JO: jump if there is Overflow
❑ JA: Jump if above (CF = 0 and ZF = 0)
❑ JAE: Jump if above or equal (CF = 0) Unsigned Numbers (CF)
❑ JB: Jump if below (CF = 1)
❑ JBE: Jump if below or equal (CF = 1 or ZF = 1)
❑ JG: Jump if greater than (ZF = 0 and SF = OF)
❑ JGE: Jump if greater than or equal (SF = OF) Signed Numbers (SF)
❑ JL: Jump if less than (SF ≠ OF)
❑ JLE: Jump if less than or equal (ZF = 0 and SF ≠ OF)

10
Thank you
for
your attention
11

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy