You are on page 1of 52

Activity No.

1
Debug
Course Code: CPE 005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to demonstrate how Debug can be used as an assembler and disassembler.

2. Intended Learning Outcomes (ILOs):


After completion of this activity the students should be able to:
2.1 Write a short assembly language sequence using Debug
2.2 Execute an assembler instruction in Debug
2.3 Examine the contents memory
3. Discussion :

The DEBUG program

To create a program in assembly options are to use an assembler or a debugger. The


debugger that comes with both Windows and DOS is debug.exe or DEBUG program.

DEBUG allows users to:


 control and monitor execution of programs
 interactively display, examine memory contents, and view registers and variables as they change.
 alter and selectively load COM, EXE and other file types
 access specific sectors, I/O ports and memory addresses

The Debug Commands

Debug commands are issued at command prompt, denoted by a hyphen (-), either as a single
letter, in uppercase or lowercase, or with a combination of parameter. Table 1.1 shows the summary of the
Debug commands. The “?” is used to show the long name of each command.

Command Description
Program Creation and Debugging
A Assemble a program using instruction mnemonics
G Execute the program currently in memory
R Display the contents of register
P Proceed past an instruction, procedure or loop
T Trace a single instruction
U Disassemble memory into assembler mnemonics
Memory Manipulation
C Compare one memory range with another
D Dump (display) the contents of memory
E Enter bytes into memory
F Fill a memory range with a single value

1
M Move bytes from one memory range to another
S Search a memory range for specific values
Miscellaneous
H Perform Hexadecimal addition and subtraction
Q Quit Debug and return to DOS
Input-Output
I Input a byte from a port
L Load data from disk
O Send a byte to a port
N Create a filename for use by the L and W commands
W Write data from memory to disk

Table 1.1 Summary of the Debug Commands

Once a Debug command has been issued, the <Enter> key must be pressed so that the command
becomes effective.

4. Resources:
Computer with 32-bit Operating System
Debug.exe
5. Procedure:
Sample Problem A.
1. Open Debug.exe. Type the following at the DOS command prompt of your computer:
C:/>Debug <Enter>
2. Issue the command E when prompted by hyphen ( - ), to place bytes in the memory,
- E CS:100 “Welcome to Assembly Programming!”
3. Use the D command to view contents at CS:0100
-D 100
Describe how your data are stored in the memory of the computer. In what number system are
they stored?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Record all results in Table 1.2.
4. Display the contents of a range, type
-D 110 11F
Describe what happened to the display.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
5. Type Q to quit from Debug.
-Q

2
Sample Problem B.
1. Open Debug.exe.
2. Assemble the following program at address CS:0100. Type,
-A 100
138C:0100 mov ah,02
138C:0102 mov dl,49
138C:0104 int 21
138C:0106 mov dl,20
138C:0108 int 21
138C:010A mov dl,03
138C:010C int 21
138C:010E mov dl,20
138C:0110 int 21
138C:0112 mov dl,54
138C:0114 int 21
138C:0116 mov dl,49
138C:0118 int 21
138C:011A mov dl,50
138C:011C int 21
138C:011E int 20
138C:0120 [Enter]
-
3. Execute the program, type G at the debug prompt.
-G
4. Analyze the output and record all results in Table 1.3
5. Unassemble the program at address 100 to 11e, type
- U 100 11E
6. Observe the output and record all results in Table 1.4.
7. Edit the values of address 107 and 10f, type
-E CS:107
20.0A
-E CS:10F
20.0A
8. Unassemble the program at address 100
-U 100
Observe what happened to the output and record all results in Table 1.5.
What changes have you observed in the values of the memory?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
9. Execute the program. Type,
-G
10. Save the program as Prog1.com, type
-N c:\CompOrg\Prog1.com <Enter>
Note: You should have had created CompOrg directory in C: drive.

3
11. Use H command to get the sum and difference of the addresses 0120 and 0100. Type,
–H 0120 0100
0220 0020
12. Change the value of the CX register to 0020. Type,
-R CX <Enter>
CX 0000
:0020
13. Type W to write the file Prog1.com,
-W <Enter>
The computer should display “Writing 00020” bytes.
14. Exit from Debug.

Sample Problem C..


1. Check the created Prog1.com file. Open the DOS command prompt. Click START-type CMD-press
ENTER.
2. Change directory to CompOrg.
c:\cd CompOrg> <Enter>
3. Execute Prog1.com.
c:\CompOrg>Prog1.com <Enter>
4. Record your output in Table 1.6.

Sample Problem D.
1. Open Debug.exe
2. Type ?
-?
Describe what happened after you typed “?” at the prompt.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Which of the commands does not have a parameter?


______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Use Table 1.7 to write the long names of the commands and given the examples, give the function
of each of the commands used in this activity.

4
6. DATA ANALYSIS:

Table 1.2- Sample Problem A.3

138C:0100 ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ Welcome to Assem
138C:0110 ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ bly Programming!
138C:0120 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
138C:0130 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
138C:0140 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
138C:0150 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
138C:0160 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
138C:0170 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
--

Table 1.3- Output of Sample Problem B.3

Table 1.4 -Result of Sample Problem B.4

Address Contents (Hex) Mnemonics


: 0100 MOV AH,02
: 0102 MOV DL,49
:0104 INT 21
:0106 MOV DL,20
:0108 INT 21
:010A MOV DL,03
:010C INT 21
:010E MOV DL,20
:0110 INT 21
:0112 MOV DL,54
:0114 INT 21
:0116 MOV DL,49
:0118 INT 21
:011A MOV DL,50
:011C INT 21
:011E INT 20

5
Table 1.5 -Result of Sample Problem B.6

Address Contents (Hex) Mnemonics


: 0100 B4 02 MOV AH,02
: 0102 MOV DL,49
:0104 INT 21
:0106
:0108 INT 21
:010A MOV DL,03
:010C INT 21
:010E
:0110 INT 21
:0112 MOV DL,54
:0114 INT 21
:0116 MOV DL,49
:0118 INT 21
:011A MOV DL,50
:011C INT 21
:011E INT 20

Table 1.6- Output of Procedure C.4

6
Table 1.7- Debug Commands

Command Syntax Function Example


A [Starting Address] A 100

D [Start Addr] [End Addr] D 100


D 110 11F

E [Address] [Data] E CS:107


E CS:100 “Welcome to
Assembly Programming!”

G [Starting Addr] [Breakpoint Addr] G


G=CS:100 11F

H value1 value2 H 0120 0100

N [C:] [filename] [.ext] N c:\CompOrg\Prog1.com

Q Q

Register R [Register name] Examine or modify the R


contents of internal CPU R CX
register.
U [Starting Addr] U 100
U 100 11E

W W

7
PROBLEMS:

1. Make a DEBUG program that will display your name, program, and course, on the computer
screen. Save you program as Prog2.com.
Sample Output:
Juan dela Cruz
BS CpE
CPE005

8. Assessment (Rubric for Laboratory Performance):

8
Activity No. 2
Registers
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to demonstrate how the CPU registers are used for addition, subtraction,
multiplication and division operations and how the flag register are affected by these operations

2. Intended Learning Outcomes (ILOs):

After completion of this activity the students should be able to:

1.1 Examine the contents internal CPU registers


1.2 Modify internal CPU register contents
1.3 Demonstrate addition, subtraction, multiplication and division operations
3. Discussion :
The Registers
Every computer contains registers or small areas that can store data temporarily. These registers are too
small to store files instead they are used to store information while the program is running. These registers
are specific for every computer manufacturer. Before one can program in assembly language one should
be familiar with the registers inside their computer and the width of these registers because assembly
language is machine-dependent or machine-specific programming language.

The 8088 CPU for example, has fourteen 16 bit registers to process the data in a computer.

Four are for data: AX,BX,CX,DX


Four are for segment addresses: ES,DS,SS,CS
Four are for index addressing: SP,BP,SI,DI
One is the instruction pointer:- IP
One is the flag register : Flag
The 8086, 8088 and 80286 computers are characterized by a 16-bit architecture. The computers from
the 80386 to the Pentium use the complete 32-bit architecture.

The registers are divided in three categories namely:


 General-purpose registers
 Segment Registers
 Other Registers

The general-purpose registers are primarily used for arithmetic and data movement. Each register can
be addressed as either a single 32-bit value or two 16-bit values. Portions of some registers can be

9
addressed as 8-bit values.
For example, the 32-bit EAX register has a 16-bit lower half named AX. The AX register, in turn, has
an 8-bit upper half named AH (A-High) and an 8-bit lower half named AL(A-Low).

The same overlapping relationship exists for the EAX, EBX, ECX, and EDX registers.

The remaining general-purpose registers only have specific names for their lower 16 bits, these are
used when writing real-address mode programs.

THE FLAGS
The EFLAGS (or just Flags) register consists of individual binary bits that control the operation of the
CPU or reflect the result of arithmetic and logical instructions. Some instructions test and manipulate
individual processor flags.

A flag is set when it equals 1; it is clear (or reset) when it equals 0. Figure 2-1 shows how each flag is
represented by DEBUG.

Table 2.1- The Flag Register bit representation in DEBUG


Set Clear
OV= Overflow NV=No Overflow
DN= Direction Down UP=Direction Up
EI= Enable Interrupt DI=Disable Interrupt
NG= Sign Flag Negative PL=Sign Flag Positive
ZR=Zero NZ=Not Zero
AC=Auxiliary Carry NA=No Auxiliary Carry
PO=Parity Odd PE=Parity Even
CY=Carry NC=No Carry

The ARITHMETIC OPERATORS


The four basic arithmetic operators are the ADD, SUB, MUL, DIV.
The ADD is used for addition.
Syntax:
ADD destination, source ;dest operand = dest operand + source operand
The destination operand can be a register or in memory. The source operand can be a register, in memory
or immediate data.
ADC, which means to add the two operands plus the carry.
Syntax
ADC destination, source ;dest = dest + source + CF (carry flag)
The SUB is used for subtraction.
The form of the two equivalent subtraction operations (subtract and subtract with borrow) are:
Syntax :
SUB dest, souce ;dest = dest - source
SBB dest, source ;dest = dest - source – CF
If the Carry Flag is set after the operation, then a larger number was subtracted from a smaller number, and
a 'borrow' occurred which sets the carry flag.
The MUL is used for multiplication.

10
The DIV is used for division.
In multiplication and division operations, the x86 microprocessor use the registers AX, AL, AH, EAX, DX
and EDX as used as shown in Table 2.1 and Table 2.2
Table 2.2- Default Operands for Multiplication
No. of Bits Multiplicand Multiplier Product
8 bits x 8 AL register or memory AX (16 bits)
16 bits x 16 AX register or memory DX:AX (32 bits)
32 bits x 32 EAX register or memory EDX:EAX (64 bits)

Table 2.3- Default Operands for Division


No. of BIts Dividend Divisor Quotient Remainder
16 bits / 8 AX register, memory (8-bit) AL AH
32 bits / 16 DX:AX register, memory (16-bit) AX DX
64 bits / 32 EDX:EAX register, memory (32-bit) EAX EDX

The operands can be considered as signed numbers or unsigned numbers. The unsigned multiplication
and division operations are MUL, DIV.

The signed multiplication/division operations are IMUL, IDIV.


For signed multiplication, if the two numbers have the same sign the result is always positive. If the
operands are different signs then the result will be negative.
For signed division, if the signs of the dividend and divisor are the same, then the quotient sign is positive.
If the signs of the dividend and divisor are different, then quotient sign is negative. The remainder sign is
always the same sign as the dividend. You can always check your work via quotient*divisor + remainder =
dividend)
4. Resources:
Computer with 32-bit Operating System
Debug.exe
5. Procedure:
Sample Problem A.
1. Run DEBUG.EXE.
2. Examine the register contents, type
-R
Observe the output and record all results in Table 2.4.
What did you observed as the default values of the flags? Why?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
3. Modify the value of the AX register, type
-R AX
AX 0000
:1234_ <Enter>
4. Trace if the contents of register AX changed. Type,
-T

11
What happened to the value of AX register?
______________________________________________________________________________
5. Change the value of the Parity flag, from Parity Odd (default) to Parity Even. Type
-R F
NV UP EI PL NZ NA PO NC -PE <Enter>
6. Check if the value of the Parity flag changed. Type,
-R F <Enter>
What is now the new value in of the flag register?
______________________________________________________________________________
7. Reset the values of the registers. Type,
-Q

Sample Problem B:
1. Open Debug.exe
2. Assemble the following program:
-A 100
mov ax,ffff
add ax,01
int 21
3. Trace the values of the registers starting at address 0100
-T=100 2
4. Observe the output.
What did you observe in the output? Why?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
5. Record all results in Table 2.5.
6. Reset the values of the registers.

Sample Problem C.
1. Open Debug.exe.
2. Assemble the following program:
-A 100
mov al,00
sub al,01
int 21
2. Trace the values of the registers.
3. Observe the output.
Which flag/flags was/were affected by the given? Why?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
4. Record all results in Table 2.6.
5. Reset the values of the registers.

12
Sample Problem D.
1. Open Debug.exe.
2. Assemble the following program:
-A 100
mov al,0a
mov bl,05
mul bl
int 21
3. Trace the values of the registers.
4. Observe the output.
What did you observe in the output? Why?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
5. Record all results in Table 2.7.
6. Reset the values of the registers.

Sample Problem E.

1. Open Debug.exe.
2. Assemble the following program:
-A 100
mov dx,0
mov ax,8003
mov cx,100
div cx
int 21
3. Trace the values of the registers.
4. Observe the output.
What did you observe in the output? Why?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
5. Record all results in Table 2.8.
6. Reset the values of the registers.

13
6. DATA ANALYSIS:
Table 2.4- Result of Sample Problem A.2

AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000


DS=_______ ES=_______ SS=_______ CS=_______ IP=0100 NV UP EI PL NZ NA PO NC

Table 2.5 -Result of Sample Problem B.5

Instruction Register Content Flag Register

AX BX CX DX IP

MOV AX,FFFF

ADD AX,01

INT 21h

Table 2.5 -Result of Sample Problem C.5


Instruction Register Content Flag Register

AX BX CX DX IP

MOV AL,00

SUB AL,01

INT 21h

14
Table 2.5 -Result of Sample Problem C.5
Instruction Register Content Flag Register

AX BX CX DX IP

MOV AL,0a

MOV BL,05

MUL BL

INT 21h

Table 2.5 -Result of Sample Problem D.5

Instruction Register Content Flag Register

AX BX CX DX IP

MOV DX,00

MOV AX,8003

MOV CX, 100

DIV CX

INT 21h

15
PROBLEMS:
1. Determine two 8-bit numbers that will cause the following flag conditions to occur after the
addition. Verify that your numbers cause the specified flag conditions by modifying your program
with your new numbers, executing it, and recording the flag values. Use HEX numbers.
a. Carry = 0, Overflow = 0, Zero = 0, Sign = 0: ___________ + ___________ = ___________
b. Carry = 0, Overflow = 0, Zero = 0, Sign = 1: ___________ + ___________ = ___________
c. Carry = 1, Overflow = 1, Zero = 0, Sign = 0: ___________ + ___________ = ___________
d. Carry = 0, Overflow = 1, Zero = 0, Sign = 1: ___________ + ___________ = ___________
e. Carry = 1, Overflow = 0, Zero = 0, Sign = 1 : ___________ + ___________ = ___________
f. Carry = 1, Overflow = 0, Zero = 0, Sign = 0 : ___________ + ___________ = ___________
g. Carry = 0, Overflow = 0, Zero = 1, Sign = 0 : ___________ + ___________ = ___________

2. Make a program that shows a division overflow.


3. Make a program that would implement the expression : var4 = (var1 * -5) / (-var2 + var3);

8. Assessment (Rubric for Laboratory Performance):

16
Activity No. 3
DATA DEFINITION AND TRANSFER
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to demonstrate how characters and string of characters move from one location
to another.

2. Intended Learning Outcomes (ILOs):

After completion of this activity the students should be able to:


2.1 Show how to define data in Assembly
2.2 Declare a group of characters
2.3 Write programs applying Service 09 , Int 21
3. Discussion :
Data Definition
The basic storage unit for data in a computer is a byte, containing 8 bits(1 byte), other storage
sizes are word (2 bytes), doubleword (4 bytes) , and quadword (8 bytes).
String is stored in memory as a succession of bytes containing ASCII codes. They must be
defined in the computer through directives. Table 3-1 shows how they are defined using directives.
Table 3-1-Data Directives
Term Number of bits Directive
Byte 8 DB (Define Byte)
Word 16 DW (Define Word)
Doubleword 32 DD (Define Double Word)
Quadword 64 DQ ( Define Quadword)

DISPLAYING A STRING
There are two ways to display a string:
 Using Service 09H
Required:
1. The string must be defined in DATA segment.
2. The string must be terminated by '$'.
3. AH = 09h
4. DX = Offset address of the beginning of the string
Example:
.DATA
STRING_NAME DB 'THE STRING TO BE DISPLAYED$'
.CODE
MOV AH , 09H
MOV DX , OFFSET STRING_NAME
INT 21H

17
Note:

 If the terminating $ is omitted after the string, the operation displays characters in the
memory, until it finds a $ character, if any.
 To move the cursor to the beginning of the next output line, put 0Dh and 0Ah after the string
and before the terminating $.

Example:
PROMPT DB 'PLEASE, ENTER YOUR NAME: ' , 0Dh , 0Ah , '$'
 Another way of moving the cursor to the beginning of the next output line is to display ,
using DOS function 09H, a string of the form:
STRING1 DB 0Dh , 0Ah , '$'
 Using Service 40H
Required:
1. Set AH = 40h
2. BX = 1
3. CX = string length
4. DX = offset address of the beginning of the string

Example:
.DATA
STRING_NAME DB 'THE STRING TO BE DISPLAYED'
STRINGLEN EQU $ – STRING_NAME
.CODE
MOV AH , 40H
MOV BX , 01H
MOV CX , STRINGLEN ; string length
MOV DX , OFFSET STRING_NAME
INT 21H
 The EQU directive defines a value that the assembler can use to substitute in other
instructions.
 An operand containing a dollar symbol, $, refers to the current value in the location
counter. Thus, in the above example $ - STRING_NAME evaluates to the number of bytes
between STRING_NAME and STRINGLEN which is the number of bytes (i.e., characters) in ‘THE
STRING TO BE DISPLAYED’

READING A STRING (SERVICE 0Ah)


To read a string, we have to do two steps:
a. Define an array to store that string in DATA segment.
b. Invoke DOS function 0AH in CODE segment.
One way of defining the array is:
BUFFER_NAME DB Num1 , Num2 DUP(?)

18
where:
a. Num1 = the maximum number of string characters to be read + 1
b. Num2 = Num1 + 1
c. The maximum value for Num1 is FFh i.e., 255
d. The last string character is the Carriage Return (0Dh).
The program will wait for the input. The user must press "Enter" key to end the inputting process. inp
Example:
Define an array called STRING to store a string of maximum length 50 characters to be used by the service
0Ah of INT 21h.
Actual string length is stored in this byte
To read a string from the keyboard into an array called BUFFER as defined above, we invoke DOS function
0AH as:
MOV AH , 0AH
MOV DX , OFFSET STRING
INT 21H
The operation echoes the entered characters on the screen and advances the cursor.
To display the above array generally by using DOS function 40H:
MOV AH, 40H
MOV BX, 01H ; file handle for the screen
MOVZX CX, STRING[1] ; Initialize CX with the string length
MOV DX, OFFSET STRING[2]
INT 21H
4. Resources:
Computer with 32-bit Operating System
TASM
5. Procedure:
Sample Program A.
1. Type the following program using Notepad.
dosseg
.model small
.stack
.data
prompt1 db 13,10,"Enter a character:$"
prompt2 db 13,10,"The character you entered is:$"
.code
main proc
mov ax,@data
mov ds,ax

lea dx,prompt1
mov ah,09h
int 21h

mov ah,01h

19
int 21h
mov bl,al
lea dx,prompt2
mov ah,09h
int 21h

mov dl,bl
mov ah,02h
int 21h
mov ax,4c00h
int 21h

main endp
end

2. Save the file inside the TASM directory as progA.asm.


3. Open the DOS command prompt.
4. Change directory to TASM. Type,
C:\> cd TASM <Enter>
5. Assemble Proga.asm. Type,
C:\tasm> tasm progA.asm<Enter>
The following message will appear if you assembled your program successfully.
Turbo Assembler Version 2.0 Copyright (c) 1988, 1990 Borland International
Assembling file: proga.ASM
Error messages: None
Warning messages: None
Passes: 1
Remaining memory: 442k
6. Use tlink to link all files created from assembling. Type,
C:\tasm> tlink ProgA.obj<Enter>
Turbo Link Version 3.0 Copyright (c) 1987, 1990 Borland International
7. Execute the program created. Type,
C:\tasm> ProgA<Enter>
8. Analyze and record the output in Table 3.2.
Sample Program B.
1. Type the following program using Notepad.
.model small
.stack 100h
.data
byte1 db 1
byte2 db 0
word1 dw 1234h
word2 dw 0
string db "Stressed!", 0dh, 0ah,"$"
;---- this is a comment
.code

20
MAIN PROC
Mov ax, @data
Mov ds, ax

Mov dx, offset string


Mov ah, 9
Int 21h
Mov bx, offset string
Mov al, [bx]
Mov ah, [bx+1]
Mov [bx], ah
Mov [bx+1],al
Mov ah,9
Mov dx, offset string
Int 21h
Mov ax, 4c00h
Int 21h
Main endp
End main

2. Save the program as ProgB.asm.


3. Assemble, link and execute the program.
4. Analyze and record the output in Table 3.3

6. DATA ANALYSIS:

Table 3.2- Output of Sample Program A Table 3.3- Output of Sample Program B

PROBLEMS:
1. How many bytes are allocated for each of the following data definitions?
a. BYTE 20 DUP(0) = _____________ bytes
b. BYTE 20 DUP (?) = _____________ bytes
c. BYTE 4 DUP(“East”) = _____________ bytes
d. WORD3 WORD ? = _____________ bytes
e. Array WORD 5 DUP(?) = _____________ bytes
2. Write a program that prompts and reads a user’s name USERNAME (of maximum length 30
characters). The program should display a message of the form:

OUTPUT:
Hello, What's your name? JM

21
Hello, JM
Congratulations! Your first program is working!
3. Modify ProgB such that the second string is printed “!dessertS” (“Stressed!” backwards).

4. Create a program that will display a given string two times.


SAMPLE OUTPUT:
Enter a String: love
lovelove
8. Assessment (Rubric for Laboratory Performance):

22
Activity No. 4
C TRANSLATION TO ASSEMBLY LANGUAGE
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to show the relationship of C programming language to assembly language

2. Intended Learning Outcomes (ILOs):

After completion of this activity the students should be able to:


2.1 Compare C programming and Assembly programming
2.2 Convert a C program to Assembly program
3. Discussion :
ASSEMBLY LANGUAGE AND THE C LANGUAGE
Assembly language is the basis of the C programming language it is the reason why a program in
C can be easily translated in assembly language.
For example, conditional statement of C language of the form:
if (expression)
{
statement1;
statement2;
:
statementn;
}
else
{
statement1;
statement2;
:
statementn;
}

Can be implemented in Assembly language as:

CMP_ instruction
Conditional_loop instruction <label>
Instruction1
Instruction2
:
Instruction
JMP_instruction <label>

23
The WHILE statement in C language of the form:
do
{
Statement1;
Statement2;
:
statementn
} while (expression);
Can be implemented in Assembly language as:
label:
Instruction1
Instruction2:
Instruction
CMP instruction
Conditional_jump instruction
Label
The DO WHILE statement in C language of the form:
While
{
Statement1;
Statement2;
:
statementn
}
Can be implemented in Assembly language as:
Label1:
CMP instruction
Conditional jmp instruction label
Instruction1:
Instruction2
:
instructionn
JMP label
Conditional_jump instruction
Label2:
Instruction1:
Instruction2
:
Instruction
Label
Acts as an identifier that acts as a place marker for instructions and data. When placed just before
an instruction implies the instruction’s address. If placed just before a variable implies the variable’s
address.
Loops
Loops or repetition allow a set of instructions to be repeated until certain condition is reached is also
used in Assembly using the LOOP command.

24
4. Resources:
Computer with 32-bit Operating System
TASM
5. Procedure:
Sample Problem 1:
1. Type the following programs in Notepad.
TITLE prog4_1.asm TITLE prog4_2.asm
Dosseg .model small
.model small .stack
.stack 0100h .data
.data .code
.code mov ax,@data
mov ax,@data mov ds, ax
mov ds, ax mov cx,001Eh
mov cx,001Eh mov ah,02h ;request display character
mov ah,02h ;request display character mov dl,'A' ;character to display
mov dl,'*' ;character to display B: int 21h ;call interrupt service
A: int 21h ;call interrupt service inc dl
loop A loop B
mov ax, 4c00h ;end mov ax, 4c00h ;end
int 21h int 21h
end end
2. Assemble and execute these programs.
3. Analyze the outputs.
What did you observe about the outputs?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
4. Record the outputs in Table 4.1 and Table 4.2 respectively.

Sample Problem 2:
1. Type the following programs in Notepad.
TITLE Equal.asm // Equal.c
MAIN SEGMENT #include<stdio.h>
ASSUME #include<conio.h>
CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN main()
ORG 100h {
START: int DH,DL;
MOV DL,41h DL = 41;
MOV DH,41h DH = 41;
CMP DH,DL if (DH == DL)
JE TheyAreEqual printf("Y");
JMP TheyAreNotEqual else
TheyAreNotEqual: printf("N");
MOV AH,02h getch();
MOV DL,4Eh return 0;

25
INT 21h }
INT 20h
TheyAreEqual:
MOV AH,02h
MOV DL,59h
INT 21h
INT 20h
MAIN ENDS
END START
TITLE Triangle //Triangle.c
.model small #include<stdio.h>
.code #include<conio.h>
org 100h main()
start: {
int z=1;int x=0;int y=4;
mov cl,1
mov bl,0
mov ch,4
while (y>0)
looprow:cmp ch,0 {
jg loopcol
jmp quit
while(x<z)
loopcol: {
cmp bl,cl
jl dsplay
jmp next
printf("*");
dsplay:mov ah,2h x++;
mov dl,'*' ;display asterisk }
int 21h
inc bl
jmp loopcol
printf("\n");;
next:mov dl,0Ah x=0;y--;z++;
int 21h ;next line }
mov dl,0Dh
int 21h

mov bl,0
dec ch
inc cl
jmp looprow
quit:int 20h getch();
end start return 0;}
2. Assemble and execute each program.

26
3. Observe the output.
What did you observe about the output?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
4. Record the output in Table 4.3 and Table 4.4
6. DATA ANALYSIS:

Table 4.1- Output of prog4_1.asm Table 4.2- Output of prog4_2.asm

Table 4.3 Output of Program Equal Table 4.4 Output of Program Triangle

PROBLEMS:
1. Translate the following C program to their equivalent assembly codes. Use the space provided.
//Prog4_1.c ; ;Prog2_2.asm

#include<stdio.h> MAIN SEGMENT


#include<conio.h> ASSUME CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN
main() ORG 100h
{ start:
int cx; MOV CX,5 ;set CX equal to 5
for (cx=0;cx<5; cx++) LOOP_LABEL:
printf("*"); MOV AH,02h ;writes on screen
getch(); MOV DL,2Ah ;prints the character
return 0; INT 21h
} LOOP LOOP_LABEL
INT 20h
MAIN ENDS
END START

//Prog4_2.c ;Prog2_3.asm

27
#include<stdio.h> MAIN SEGMENT
#include<conio.h> ASSUME CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN
main() ORG 100h
{ start:
void print(); MOV CX, 5
print(); loop_label:
getch(); MOV AH,02h
return 0; MOV DL,2Ah
} INT 21h
DEC CX ;decrement CX
void print() CMP CX,0 ;check if CX is zero
{ JNZ loop_label ;
int cx=1; INT 20h
while (cx<=5){ MAIN ENDS
printf("*"); END START
cx++;}
}

//Prog4_3.c ;Prog2_4.asm

#include<stdio.h> MAIN SEGMENT


#include<conio.h> ASSUME CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN
main() ORG 100h
{ START:
char message[]="Hello World!"; message DB "Hello World!$"
printf("%s",message); MOV AH,09h
getch(); MOV DX,OFFSET message
return 0; INT 21h
} INT 20h
MAIN ENDS
END START

28
2. Convert the each of the following C codes into its equivalent assembly code:
a. if ( ebx<=ecx) { eax=5;edx=6;}

b. if ( var1<=var2) var3=15; else var3=10;var4=20;

c. if ( al>bl) && (bl=cl) x=1;

d. if (al > bl) || (bl > cl) x=1;

e. while ( eax < ebx) eax =eax +1;

3. Show a program that multiples 50 (decimal) and 10 (decimal) without using the MUL and IMUL
instructions.

8. Assessment (Rubric for Laboratory Performance):

29
Activity No. 5
LOGICAL INSTRUCTIONS
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to demonstrate the logical instructions AND, OR XOR, and NOT.

2. Intended Learning Outcomes (ILOs):

After completion of this activity the students should be able to:


2.1 Compare the different logical instructions
2.2 Create programs applying logical instructions
3. Discussion :
Logical Instructions
Logical instructions are used for performing Boolean Algebra. Boolean Algebra is the algebra that
defines a set of operations on the values TRUE and FALSE. It be used to describe the design of digital
circuits . At the same time, boolean expressions are used in programming to express logical operations.

Boolean Expression
A boolean expression involves a boolean operator and one or more operands. Each boolean expression
implies a value of true or false. The set of operators includes: AND,OR, XOR and NOT.

The AND
AND syntax:
AND REGISTER1, REGISTER2
AND REGISTER, VALUE
AND returns 1 (TRUE) only if BOTH operands are 1 (TRUE)
The AND operation is useful for CLEARING particular bits in an operand ('0' AND anything ='0'). For
example, the operation: AND AL, 0Fh will set bits B7-B4 to '0', and leave bits B3-B0 unaffected.

The OR
OR syntax:
OR REGISTER1, REGISTER2
OR REGISTER, VALUE
OR returns 1 (TRUE) if either operand is 1 (TRUE)
The OR operation is useful for SETTING particular bits in an operand ('1' OR anything = '1'). For example,
the operation: OR AL, 0Fh will set bits B3-B0 to '1', and leave bits B7-B4 unaffected.

The XOR
XOR syntax:
XOR REGISTER1, REGISTER2
XOR REGISTER, VALUE
XOR returns 1 (TRUE) if one or the other operand is 1 (TRUE), but not both

30
The XOR operation is useful complementing bits in an operand ('1' XOR anything =not(anything)). For
example, the operand XOR AL, 0Fh will complement bits B3-B0 and leave bits B7-B4 unaffected. The XOR
operation can also be used to clear a register to zero – the operation XOR AX, AX will set AX to zero (this
requires less machine code than MOV AX,0000).

The NOT
NOT syntax:
NOT REGISTER
NOT VALUE
The NOT reverses or complements the value it follows.

4. Resources:
Computer with 32-bit Operating System
TASM
5. Procedure:
Sample Problem 1:
1. Type the following program in Notepad.

ogic.asm
TITLE logic.asm
.model small
.stack 100h
.data
myString db "Proud to be TIPians","$"
.code
main proc
mov ax,@data
mov ds,ax
mov bx,offset myString
LP1: mov dl,[bx]
Cmp dl, '$'
Je exit
Inc bx
;insert code here
mov ah,02
int 21h
jmp lp1
Exit: Mov ax, 4c00h
Int 21h
Main endp
End main
2. Save the program as logic.asm
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 5.1

31
Sample Problem 2:
1. Modify program logic.asm.
2. Replace the line “ ; insert code here ”, with " and dl, 11011111B " .
3. Save the program as and.asm.
4. Assemble and execute the program.
5. Observe and record the output in Table 5.2
6. How is your output different from before? Why?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

Sample Problem 3:
1. Modify logic.asm again, this time replace the line “;insert code here ”, with “ xor dl, 00100000B ".
2. Save the program as xor.asm.
3. Assemble and execute the program.
4. Observe and record the output in Table 5.2.
How is your output different from before? Why?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

Sample Problem 4:
1. Modify logic.asm once again, this time place the line “;insert code here”, with "or dl, 00100000B".
2. Save the program as or.asm.
3. Assemble and execute the program.
4. Observe and record the output in Table 5.3.
5. How is your output different from before? Why?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

6. DATA ANALYSIS:

Table 5.1-Output of logic.asm Table 5.2- Output of and.asm

Table 5.1-Output of xor.asm Table 5.2- Output of or.asm

32
PROBLEMS:

1. Write an assembly program that will simulate the given Boolean expression using assembly
programming.
AL = (AH∙ BH + AL∙ BL)’ xor (CL+(CH∙ DH)’ ∙ DL)’

2. Give a sample problem where the logical instructions can be applied.

8. Assessment (Rubric for Laboratory Performance):

33
Activity No. 6
BIT MANIPULATION
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to demonstrate bit manipulation in Assembly Language.

2. Intended Learning Outcomes (ILOs):

After completion of this activity the students should be able to:

2.1 Manipulate bits of data


2.2 Compare the different bit manipulation instructions
2.3 Create a program using the bit manipulation instructions
3. Discussion :

Bit Manipulation

Bit manipulation allows for shifting or rotating bits in an operand. It is one of the advantages of
assembly language over high level languages. The computer can perform arithmetic and logical shifts.
Arithmetic shift fills the newly created bit position with a copy of the number’s sign bit. Logical Shift fills the
newly created bit position with zero.
The SHL (shift left) instruction performs a logical shift on the destination operand, filling the lowest
bit with 0. When a bit is shifted to the left once, the number is multiplied by 2. For example if we have MOV
DL,6 SHL DL,1 the value 0000 0110 becomes 00001100, therefore SHL is used as fast multiplication
instruction.
SHR (Shift Right) instruction performs a logical right shift on the destination operand. The highest
bit position is filled with a zero.
SAL (Shift Arithmetic Left) is identical to SHL
SAR (Shift Arithmetic Right) performs a right arithmetic shift on the destination operand.
ROL (Rotate) shifts each bit to the left. The highest bit is copied into both the Carry flag and into
the lowest.
ROR (Rotate Right) shifts each bit to the right, the lowest bit is copied into both the carry flag and
into the highest bit. No bits are lost in the ROR operation.
RCL (Rotate Carry Left) shifts each bit to the left. It copies the flag to the least significant bit and
the most significant bit to the carry flag.
RCR (Rotate Carry Right) shifts each bit to the right. It copies the most significant bit to the flag and
least significant bit to the flag.

4. Resources:
Computer with 32-bit Operating System
TASM

34
5. Procedure:

Sample Problem A.
1. Type the following program in a Notepad.
TITLE bit.asm
.model small
.stack 100h
.data
num db 03Dh
.code
main proc
mov ax,@data
mov ds,ax
mov bl,num
mov cx,8
here: shr bl,1
Jc is_one
Mov dl,30h
Jmp print
Is_one:
Mov dl,31h
Print:
Mov ah,2
int 21h
loop here
Exit: Mov ax, 4c00h
Int 21h
Main endp
End main
2. Save the program as bit.asm.
3. Assemble and execute the program.
4. Analyze and record the output in Table 6.1.

Sample Problem B.
1. Modify program bit.asm, replace line number 5 with “ num db 0ah “.
2. Save the program as bit1.asm.
3. Assemble and execute the program.
4. Analyze and record the output in Table 6.2.
Did you get the expected output? Why or Why not?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

35
Sample Problem D.
1. Modify program bit.asm, replace line number 12 with “here: shr bl,1”.
2. Save the program as bit2.asm.
3. Assemble and execute the program.
4. Analyze and record the output in Table 6.2.
Did you get the expected output? Why or Why not?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Sample Problem C.
1. Modify program bit.asm, replace line number 12 with “here: rcr bl,1”.
2. Save the program as bit3.asm.
3. Assemble and execute the program.
4. Analyze and record the output in Table 6.2.
Did you get the expected output? Why or Why not?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

6. DATA ANALYSIS:

Table 6.1- Output of bit.asm Table 6.2- Output of bit1.asm

Table 6.3- Output of bit2.asm Table 6.4- Output of bit4.asm

PROBLEMS:
1. Modify bit.asm so that it uses 64-bit value stored at NUM. The 64-bit number should be printed
from the most significant bit to the least significant bit.
2. Write an assembly program that will clear the most significant nibble, set the least significant nibble
and retain the values of the rest of the bits of AX.
3. Make a program that will implement the following 10*ax = 8*ax + 2*ax using shift or rotate
instructions.
8. Assessment (Rubric for Laboratory Performance):

36
Activity No.7
PROCEDURE
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to demonstrate how stack works in Assembly Language

2. Intended Learning Outcomes (ILOs):

After completion of the activity the students should be able to:

3.1 Create a procedure in Assembly


3.2 Demonstrate push and pop operations
3. Discussion :
Stack
The stack is part of the memory that is used as a temporary storage of return addresses and data.
There are two most common types of stack: the FIFO (First-In, First-Out), also called queue and LIFO
(Last-In, Last-Out). The names of which are implied by the way data are stored and retrieved from them.
The two operations on the stack are the PUSH and POP. The PUSH instruction is used to place
values on the stack and the POP instruction is used to remove values from the stack.
The Stack Pointer (SP) register points to the top of the stack at any given time as the Instruction
Pointer (IP) holds the address of the next instruction to be fetched and executed. The POP instruction
decrements the value of the SP by two and the POP instruction increments the SP by 2.
Since the stack is part of the memory we should specify the size of the stack. We specify the size
of the stack in our program as follows:
.stack 100h
Procedure
A procedure or subroutine is a special part of the program that can be called for execution from any
point in the program. The procedure is written to provide a function that must be performed frequently at
various points in the main program. Whenever the function must be performed, a single instruction is
inserted into the main body of the program to CALL the procedure. The RET instruction must be included at
the end of the procedure to return to the main program.
Whenever there is a CALL to the procedure the value of the IP is automatically push to the stack,
and the RET instruction later will pop the value from the stack to the IP.
In Assembly, a procedure is in the form:
<procedure name> PROC
<instruction 1>
<instruction 2>
<procedure name> ENDP

37
Calling a Procedure has the form:
CALL <procedure name>
Returning from a Procedure has the form:
BODY proc
call <procedure1>
call <procedure2>
BODY endp
PROCEDURE1 proc
:
ret
PROCEDURE1 endp
PROCEDURE2 proc
:
ret
PROCEDURE2 endp

4. Resources:
Computer with 32-bit Operating System
TASM
5. Procedure:
Sample Program A.
1. Type the following in Notepad.
TITLE proc1.asm
.model small
.stack 100h
.data
.code
main proc
mov ax,@data
mov ds,ax
xor al,al
mov cx,16
lp1: push ax
call out1hex
call pcrlf
pop ax
inc al
loop lp1
Mov ax, 4c00h
Int 21h
Main endp

Out1hex proc
And al,0fh
Cmp al,9

38
Ja ischar
Add al,30h
Jmp printit
Ischar: add al,37h
Printit: Mov dl,al
Mov ah,2
Int 21h
Ret
Out1hex endp

Pcrlf proc
Mov dl,0ah
Mov ah,2
Int 21h
Mov dl,0dh
Mov ah,2
Int 21h
Ret
Pcrlf endp
End main
2. Save the program as proc1.asm.
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 7.1.
What does the procedure Pcrlf do?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

Sample Program B.
1. Modify proc1.asm, interchange the placement of procedure Out1hex with Pcrlf.
2. Save the program as proc2.asm.
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 7.2.
How is your output different from before? Why?
___________________________________________________________________________
___________________________________________________________________________
______________________________________________________________________________

Sample Program C.
1. Modify proc1.asm, change line number 15 with “inc al”.
2. Save the program as proc3.asm.
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 7.3.
How is your output different from before? Why?
___________________________________________________________________________
___________________________________________________________________________

39
Sample Program B.
1. Type the following in a Notepad.
dosseg
.model small
.stack
.data
msg1 db 13,10,"Enter first number:$"
msg2 db 13,10,"Enter second number:$"
msg3 db 13,10,"Sum in decimal number:$"
num1 db ?
sum db ?
res db 20 DUP('$')
.code
main proc
mov ax,@data
mov ds,ax

lea dx,msg1
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,'0'
mov num1,al

lea dx,msg2
mov ah,09h
int 21h
mov ah,01h
int 21h
sub al,'0'
add al,num1
mov sum,al

lea dx,msg3
mov ah,09h
int 21h

mov si,offset res


mov ax,00
mov al,sum
call addition

lea dx,res
mov ah,09h
int 21h

40
mov ax,4c00h
int 21h

main endp
addition proc near
push ax
push bx
push cx
push dx
push si
mov cx,00h
mov bx,0Ah

rpt1: mov dx,00


div bx

add dl,'0'
push dx

inc cx
cmp ax,0Ah
jge rpt1

add al,'0'
mov [si],al
rpt2: pop ax
inc si
mov [si],al
loop rpt2

inc si
mov al,'$'
mov [si],al

pop si
pop dx
pop cx
pop bx
pop ax
ret
addition endp
end
2. Save the program as proc4.asm.
3. Assemble and execute the program.
4. Analyze the output and record the output in Table 7.4.

41
6. DATA ANALYSIS:

Table 7.1 – Output of proc1.asm Table 7.3- Output of proc3.asm

Table 7.2 – Output of proc2.asm Table 7.4- Output of proc4.asm

PROBLEMS:
1. Create an assembly language program asks the user to enter a password formed from 10
characters. The program prints the password as stars on the screen. If the password is correct, the
program should print “Password is CORRECT!” otherwise, “Password is INCORRECT!”

2. Create a program that will accept number in decimal and convert it to hexadecimal, binary and
octal.
8. Assessment (Rubric for Laboratory Performance):

42
Activity No. 8
ATTRIBUTES
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to demonstrate cursor positioning and text-based attributes in Assembly.

2. Intended Learning Outcomes (ILOs):

After completion of this activity the students should be able to:

2.1 Display a text based on a specified position on a monitor screen


2.2 Create a program that involves text-based attributes.
3. Discussion :
The Screen

The screen is typically has 80(0-79) columns x 25 (0-24). The columns and rows provide a grid of
addressable locations at any one of which the cursor can be set. INT 10h and Service 06h handles the
process of clearing the screen.
It is required to determine the position of X and Y coordinates where the next character is to be
displayed. INT 10H Service 02H sets the cursor position.

The attribute byte in text mode determines the characteristics of each displayed character. When a
program set an attribute, it remains set; that is , all subsequent displayed character have the same attribute
until one operation changes it. You can use INT 10H functions to generate a screen attribute and perform
such actions as scroll up or down, read attribute or character, or print / display attribute or character.

4. Resources:
Computer with 32-bit Operating System
TASM
5. Procedure:
Sample Problem A.
1. Type the following program in Notepad.
TITLE screen1.asm
.model small
.stack
.data
.code
start:

mov ax, 0600h


mov bh, 00eh

43
mov cx,0
mov dx, 0184fh
int 10h

mov ah, 02
mov bh,0
mov dh, 10
mov dl,34
int 10h

mov ah,02
mov dl, 'T'
int 21h

mov ah,02
mov dl, 'I'
int 21h

mov ah,02
mov dl, 'P'
int 21h

mov ah, 4ch


int 21h
end start
2. Save the program as screen1.asm.
3. Assemble and execute the program.
4. Analyze and record the output in Table 8.1.
Sample Problem B.
1. Modify program screen1.asm, replace line number 15 with “mov bh,0ch”.
2. Analyze and record the output in Table 8.2.
3. How is your output different from before? Why?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

Sample Problem C.
1. Modify program screen1.asm, replace line number 2 with “mov bh,1bh”.
2. Analyze and record the output in Table 8.3.
3. How is your output different from before? Why?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

44
Sample Problem D.
1. Type the following program in Notepad.

TITLE screen2.asm
dosseg
.model small
.stack
.code
start:
mov ax, 0b800h
mov es, ax
mov ah, 06h
mov cl, 00h
mov ch, 00h
mov dl, 18h
mov dh, 18h
mov bh, 20h
int 10h

mov ah, 06h


mov cl, 18h
mov ch, 00h
mov dl, 36h
mov dh, 18h
mov bh, 40h
int 10h

mov ah, 06h


mov cl, 36h
mov ch, 00h
mov dl, 4fh
mov dh, 18h
mov bh, 10h
int 10h

mov ah, 4ch


int 21h
end start

2. Save the program as screen2.asm.


3. Assemble and execute the program.
4. Analyze and record the output in Table 8.2.

45
6. DATA ANALYSIS:
Table 8.1- Output of screen1.asm Table 8.2- Output of screen2.asm

PROBLEMS:
1. Modify screen2.asm. Change the background into four-color vertical “Light blue, yellow, magenta
and Cyan” and write down the name of the color on the space provided for every color.
Sample Output:

2. Modify program screen2.asm so that it will display the figure below:

46
3. Make an assembly program that will display the figure shown below. Save your file as Football.asm

8. Assessment (Rubric for Laboratory Performance):

47
Activity No. 9
Parallel Port Interfacing
Course Code: CPE005 Program:
Course Title: Computer Systems Organization with Assembly Language Date Performed:
Section: Date Submitted:
Name: Instructor:
1. Objective:
This activity aims to interface a circuit using a parallel port.

2. Intended Learning Outcomes (ILOs):

After completion of this activity the students should be able to:

2.1 Test the parallel port connectivity to a device


2.2 Design a circuit that can be interfaced using a parallel port
3. Discussion :
The Parallel Port

The parallel port is 25-pin, D-shaped socket found on personal computers. It is also called the
printer port because it is primary used to connect printers to computer. It is a simple and inexpensive tool
for building computer controlled devices and projects. Figure 9.1 shows the parallel port pin configuration.

Figure 9.1 – The Parallel Port

The parallel port has three types of port namely: data port, status port and control port. The data
port is also called the output port which comprises pins 2 to 9. The status port is also called the input port
which comprises pins 10, 11, 12, 13, and 15. The control port is also called the input/ output (I/O) port
which comprises pins 1,14,16, and 17. Pins 18 through 25 are the ground pins.

The data port, status port and control port have address designations which are 378h, 379h ( 379h
(Base + 1) and 37Ah (Base + 2) respectively.

4. Resources:

48
Computer with 32-bit Operating System
TASM
5. Procedure:
1. Type the following in Notepad.
TITLE int1.asm
COMMENT !
A program that used to send logic 1’s to the DATA port pins and test the program.
This program when executed must satisfy the following conditions:
a. When user presses ‘1’ on the keyboard , the LEDs light from left to right
b. When user presses ‘2’ on the keyboard , the LEDs light from right to left
c. When user presses ‘0’ on the keyboard , the LEDs light will turn OFF.
d. When user presses ESC the program exits.
!
dosseg
.model small
.code
start: call test
jmp start
test:
push cx
push ax
push dx
mov ah,06
mov dl,0ffh
int 21h

cmp al,27
je exit
cmp al,'1'
je left

cmp al,'2'
je right

cmp al,'0'

je off
pop dx
pop ax
pop cx
ret

left: mov al,80h


mov dx,378h
lop : out dx,al
rol al,1

49
call test
call delay
jmp lop

right: mov al,01h


mov dx,378h
loop:out dx,al
ror al,1
call test
call delay
jmp loop

off: mov al,0


mov dx,378h
out dx,al
jmp start

delay: push cx
push ax
push dx
mov cx, 10h
mov dx,0
mov ah,86h
int 15h
pop dx
pop ax
pop cx
ret

exit: mov ah,4ch


int 21h
end

2. Save the program as int1.asm.


3. Assemble the program.

4. Connect 8 LEDs to the data port of the parallel port as shown in the Figure 9.2.

50
Figure 9.2- Parallel Port Connection

5. Execute the program.


What happened to the LEDs?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
6. Press 1 from the keyboard.
What happened to the LEDs?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
7. Record the output in Table 9.1.
8. Press 2 from the keyboard.
What happened to the LEDs?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

9. Record the output in Table 9.1.


10. Press 0 from the keyboard.
What happened to the LEDs?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
11. Record the output in Table 9.1.
12. Press ESC from the keyboard.
What happened to the LEDs?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
13. Record the output in Table 9.1.

6. DATA ANALYSIS:

51
Table 9.1- Result of Sample Problem A
Key Pressed LEDs ( 0-OFF) (1-ON)
D7 D6 D5 D4 D3 D2 D1 D0
0
1
2
Esc

PROBLEMS:
1. Connect a switch to any pin in the status port. Create a program that will light the LEDs “ON” if
the switch is ON , otherwise “OFF”.
2. Work with you’re a classmate and design a circuit that will let you apply parallel port
interfacing.

8. Assessment (Rubric for Laboratory Performance):

52

You might also like