7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
1/12
SUBROUTINES AND PARALLEL PORT
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
2/12
Objectives of the Lab Learn how to make subroutines
Function of call and return statement
Writing Data on Parallel Port Pins
Writing a Delay Procedure
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
3/12
Making Subroutines in P The keywords proc and endp used in subroutine are like
brackets in C++. The syntax to write a subroutine is:
procedure_nameproc
Coding done here
.
.
ret
procedure_name endp
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
4/12
Using Subroutines in P
.startup
coding statements
call subroutine1
call subroutine2
.exit
subroutine1proc
coding statements
ret
subroutine1 endp
subroutine2proc
coding statements
ret
subroutine2 endp
end
To use a subroutine, we just use the call statement with the
procedure_name. Below is the structure to write a code using
subroutines.
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
5/12
Use of CALL and RET The call and ret statements have a control over how the
instruction pointer works. The sequence is given below:
1. When the call statement is invoked, the address to the next
instruction (in main routine) is saved on the stack.
2. IP gets the offset address of the first instruction of the procedure
which transfers the control to procedure.
3. When ret statement is found in the subroutine, the control is
transferred back to the main routine.
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
6/12
Parallel Port Pins
Status Register
Data Register
Control Register
Pins 18-25: Ground
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
7/12
Writing data to parallel port pins First of all, to write the data on any register (data register), one
must have the address of the register.
And then a command that is able to write the data on the
specific register.
The address of data register is 378h, and the command to write
data is out reg,data.
The data can be put by a simple 3 line instruction sequence,
mov ax,data => mov dx,378h => out dx,ax
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
8/12
Instructions used in this Lab1. CALL (Call a subroutine)
2. RET (out of the subroutine)
3. OUT (write data to a register)
4. ROL reg, no. of rotates (rotate bits left)
5. ROR reg, no. of rotates (rotate bits right)
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
9/12
Writing a delay procedure.startup
code calling delay
.exit
delayproc
mov dx,15000
l1:dec dx
mov bx,0ffffh
l2:
dec bx
cmp bx,0
jne l2
cmp dx,0
jne l1
retdelay endp
end
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
10/12
Code for led pattern moving right.startup
mov al, feh
mov ah,al
start:
mov dx, 378h
out dx,ax
ror ax,1
calldelay
jmp start
.exit
delay proc
delay endp
end
LEDs will beattached toPP to generate
patterns.
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
11/12
Code for led blinking.startup
Start:
mov ax, 0ffffh
mov dx, 378h
out dx,ax
calldelay
mov ax, 0h
mov dx, 378h
out dx,ax
jmp start
.exit
delay proc
delay endp
end
?
7/23/2019 MicroP-Lab4(Subroutines & Parallel Port)
12/12
Lab Tasks1. Move LED pattern towards right on parallel port.
2. Blink LEDs on parallel port. (Quiz next time, expect
subroutines also with all previous commands)