Sunteți pe pagina 1din 54

Activity No.

1
Debug
Course Code:Cp413L1
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
Examine memory contents
2.2
Execute program in Debug
2.3
Write short assembly language sequence using Debug
3. Discussion :
The DEBUG program
To create a program in assembler two options exist: the first one is to use an assembler, and
the second one is to use the debugger. The debugger that comes with both Windows and DOS is
debug.exe or DEBUG program.
The DEBUG program can allow 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 its command prompt, the 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 ?can be used to show the long name of each command.

Table 1.1 -The Summary of the Debug Commands


ACDEFGHILMNOPQRSTUW?
Depending on the command, the debug can display an assembly code in either in mnemonic form and
machine code form as shown in Table1-2.
Table 1.2- Assembly code in mnemonic and machine code formats
Mnemonic form
Machine code
MOV AX,0009
B80900
ADD [SI],DH
0034
INT 21
CD21
1

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>
Note: The BOLDtexts are user inputs and non-Bold texts are computer response.
2. Type E at the Debug command prompt ( - ) 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.3.
4. Display the contents of a range, type
-D 110 11F
What does it mean by 110 11f in the command?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
5. Type Q to quit from Debug.
-Q
Sample Problem B.
1. Open Debug.exe.
2. Assemble the following program at address CS:0100. Type the given program, note that in the xxxx
in the given is whatever value of the CS ( code segment ) register.
-A 100
xxxx:0100
xxxx:0102
xxxx:0104
xxxx:0106
xxxx:0108
xxxx:010A
xxxx:010C

mov ah,02
mov dl,49
int 21
mov dl,20
int 21
mov dl,03
int 21

; use service 02 to display a single character


; dl register is used to hold the value 49 character
; interrupt used for service 02

xxxx:010E mov dl,20


xxxx:0110 int 21
xxxx:0112 mov dl,54
xxxx:0114 int 21
xxxx:0116 mov dl,49
xxxx:0118 int 21
xxxx:011A mov dl,50
xxxx:011C int 21
xxxx:011E int 20
; terminates the program
xxxx:0120 [Enter]
3. Execute the program, type Gat the debug prompt.
-G
4. Analyze the output and record all results in Table 1.4
5. Unassemble the program at address 100 to 11e, type
- U 100 11E
6. Observe the output and record all results in Table 1.5.
7. Edit the values of address 107 and 10f, type
-E CS:107
20.0A
-E CS:10F
20.0A
8. Unassemblethe program at address 100
-U 100
Observe what happened to the output and record all results in Table 1.6.
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.
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.
3

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.7.
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.8 to write the long names of the commands and given the examples,give the function of each
of the commands used in this activity.
6. DATA AND RESULTS:
Table 1.3-Sample Problem A.3
xxxx:0100
xxxx:0110
xxxx:0120
xxxx:0130
xxxx:0140
xxxx:0150
xxxx:0160
xxxx:0170
--

___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ Welcome to Assem
___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ bly Programming!
00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................

Table 1.4- Output of Sample Problem B.3

Table 1.5 -Result of Sample Problem B.4


Address
: 0100
: 0102
:0104
:0106
:0108
:010A
:010C
:010E
:0110
:0112
:0114
:0116
:0118
:011A
:011C
:011E

Contents (Hex)
MOV
MOV
INT
MOV
INT
MOV
INT
MOV
INT
MOV
INT
MOV
INT
MOV
INT
INT

Mnemonics
AH,02
DL,49
21
DL,20
21
DL,03
21
DL,20
21
DL,54
21
DL,49
21
DL,50
21
20

Address
: 0100
: 0102
:0104
:0106
:0108
:010A
:010C
:010E
:0110
:0112
:0114
:0116
:0118
:011A
:011C
:011E

Table 1.6 -Result of Sample Problem B.6


Contents (Hex)
Mnemonics
B4 02
MOV AH,02
MOV DL,49
INT 21
INT 21
MOV DL,03
INT 21
INT
MOV
INT
MOV
INT
MOV
INT
INT

21
DL,54
21
DL,49
21
DL,50
21
20

Table 1.7- Output of Procedure C.4

Command

Register

Syntax
A [Starting Address]

Table 1.8- Debug Commands


Function

Example
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

R [Register name]

Examine or modify the


contents of internal CPU
register.

R
R CX

U [Starting Addr]

U 100
U 100 11E

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
Cp413L1
2. Using the ASCII table as a reference,create a screen design of your choice. Save the program as
Prog3.com
8. Assessment (Rubric for Laboratory Performance):

Activity No. 2
Registers
Course Code: Cp413L1
Course Title: Computer Systems Organization with Assembly Language
Section:
Name:
1. Objective:
This activity aims to demonstrate how the CPU registers are

Program:
Date Performed:
Date Submitted:
Instructor:
used for addition, subtraction,

multiplication and division operations and how the flags are affected by these operations
2. Intended Learning Outcomes (ILOs):
After completion of this activity the students should be able to:
2.1 Examine the contents internal CPU registers
2.2 Modify internal CPU register contents
2.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
10

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
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 FLAG (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. Table 2-1 shows how each flag is
represented by DEBUG.
Table 2.1- The Flag Register bit representation in DEBUG
Set ( 1 )
Clear ( 0 )
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
PE=Parity Even
PO=Parity Odd
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
11

a 'borrow' occurred which sets the carry flag.


The MUL is used for multiplication.
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
No. of Bits
8 bits x 8
16 bits x 16
32 bits x 32

Table 2.2- Default Operands for Multiplication


Multiplicand
Multiplier
Product
AL
register or memory
AX (16 bits)
AX
register or memory
DX:AX (32 bits)
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. Ifthe
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 ispositive. If
the signs of the dividend and divisor are different, then quotient sign is negative. Theremainder sign is
always the same sign as the dividend. You can always check your work viaquotient*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 observe 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
12

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
movax,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
3. Trace the values of the registers.
4. Observe the output.
Which flag/flags was/were affected by the given? Why?
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
5. Record all results in Table 2.6.
6. Reset the values of the registers.

13

Sample Problem D.
1. Open Debug.exe.
2. Assemble the following program:
-A 100
mov al,0a
mov bl,05
mulbl
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.

14

Table 2.5 -Result of Sample Problem C.5


B.5
Register Content
Flag Register
Table
2.4- Result
of Sample Problem A.2 Flag Register
Register
Content
AX
BX
CX DX
IP
AX=0000 BX=0000 CX=0000
DX=0000
BP=0000 SI=0000 DI=0000
AX
BX
CXSP=FFEE
DX
IP
DS=_______
MOV AL,0a ES=_______ SS=_______ CS=_______ IP=0100 NV UP EI PL NZ NA PO NC
MOV AX,FFFF
MOV BL,05
Table 2.5 -Result of Sample Problem D.5
ADD AX,01
MUL BL
Instruction
Register Content
Flag Register
INT 21h
INT 21h
AX
BX
CX DX
IP
Table 2.5 -Result of Sample Problem C.5
MOVInstruction
DX,00
Register Content
Flag Register

6. DATA AND
RESULTS:
Instruction
Instruction

MOV AX,8003

AX

BX

CX

DX

IP

MOV
CX, 100
MOV AL,00
DIV
SUBCX
AL,01
INT
INT 21h
21h

PROBLEMS:
1. Determine two 8-bit numbers that will cause the following flag conditions to occur after the addition.
Verify that your numbers cause thespecified flag conditions by modifying your program with your
new numbers, executing it, andrecording 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.
15

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

Activity No. 3
DATA DEFINITION AND TRANSFER
Course Code: Cp413L1
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 charactersmove from one location to
another.

16

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.
Term
Byte
Word
Doubleword
Quadword

Table 3-1-Data Directives


Number of bits
Directive
8
DB (Define Byte)
16
DW (Define Word)
32
DD (Define Double Word)
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
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
17

function 09H, a string of the form:


STRING1 DB 0Dh , 0Ah , '$'
Using Service 40H
Required:
1.
2.
3.
4.

Set AH = 40h
BX = 1
CX = string length
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(?)

where:
a.
b.
c.
d.

Num1 = the maximum number of string characters to be read + 1


Num2 = Num1 + 1
The maximum value for Num1 is FFh i.e., 255
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
18

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
movax,@data
movds,ax
lea dx,prompt1
mov ah,09h
int 21h
mov ah,01h
int 21h
movbl,al
lea dx,prompt2
mov ah,09h
int 21h
movdl,bl
mov ah,02h

19

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>tasmprogA.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.
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
MAIN PROC
Mov ax, @data
Mov ds, ax
Mov dx, offset string
20

Mov ah, 9
Int 21h
Movbx, 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
Save the program as ProgB.asm.
Assemble, link and execute the program.
Analyze and record the output in Table 3.3
6. DATA AND RESULTS:
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 users name USERNAME (of maximum length 30
characters). The program should display a message of the form:
OUTPUT:
Hello, What's your name? JM
Hello, JM
Congratulations! Your first program is working!
3. Modify ProgB such that the second string is printed !dessertS (Stressed! backwards).
21

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):

Activity No. 4
C TRANSLATION TO ASSEMBLY LANGUAGE
Course Code: Cp413L1
Program:
Course Title: Computer Systems Organization with Assembly Language
Date Performed:
Section:
22

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>
The WHILE statement in C language of the form:
23

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

24

Acts as an identifier that acts as a place marker for instructions and data. When placed just before
an instruction implies the instructions address. If placed just before a variable implies the variables
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.
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
movax,@data
movax,@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
movdl,'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:
Type the following programs in Notepad.
TITLE Equal.asm
MAIN SEGMENT
ASSUME
CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN

// Equal.c
#include<stdio.h>
#include<conio.h>
main()
{
25

ORG 100h
START:
MOV DL,41h
MOV DH,41h
CMP DH,DL
JE TheyAreEqual
JMP TheyAreNotEqual
TheyAreNotEqual:
MOV AH,02h
MOV DL,4Eh
INT 21h
INT 20h
TheyAreEqual:
MOV AH,02h
MOV DL,59h
INT 21h
INT 20h
MAIN ENDS
END START
TITLE Triangle
.model small
.code
org 100h
start:

int DH,DL;
DL = 41;
DH = 41;
if (DH == DL)
printf("Y");
else
printf("N");
getch();
return 0;
}

//Triangle.c
#include<stdio.h>
#include<conio.h>
main()
{
int z=1;int x=0;int y=4;

mov cl,1
mov bl,0
mov ch,4
looprow:cmp ch,0
jgloopcol
jmp quit
loopcol:
cmpbl,cl
jldsplay
jmp next
dsplay:mov ah,2h
mov dl,'*' ;display asterisk
int 21h

while (y>0)
{

while(x<z)
{

printf("*");
x++;
}
26

incbl
Table 4.1- Output jmploopcol
of prog4_1.asm
next:mov dl,0Ah
int 21h
;next line
mov dl,0Dh
int 21h

Table 4.2- Output of prog4_2.asm


printf("\n");;
x=0;y--;z++;
}

mov bl,0
decch
inc cl
jmplooprow
quit:int 20h
getch();
end start
return 0;}
2. Assemble and execute each program.
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 AND RESULTS:
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>
#include<conio.h>
main()
{
int cx;
for (cx=0;cx<5; cx++)
printf("*");
getch();
return 0;

MAIN SEGMENT
ASSUME CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN
ORG 100h
start:
MOV CX,5
;set CX equal to 5
LOOP_LABEL:
MOV AH,02h
;writes on screen
MOV DL,2Ah ;prints the character
INT 21h
27

LOOP LOOP_LABEL
INT 20h
MAIN ENDS
END START

//Prog4_2.c

;Prog2_3.asm

#include<stdio.h>
#include<conio.h>
main()
{
void print();
print();
getch();
return 0;
}

MAIN SEGMENT
ASSUME CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN
ORG 100h
start:
MOV CX, 5
loop_label:
MOV AH,02h
MOV DL,2Ah
INT 21h
DEC CX
;decrement CX
CMP CX,0
;check if CX is zero
JNZ loop_label ;
INT 20h
MAIN ENDS
END START

void print()
{
int cx=1;
while (cx<=5){
printf("*");
cx++;}
}

//Prog4_3.c

;Prog2_4.asm

#include<stdio.h>
#include<conio.h>
main()
{

MAIN SEGMENT
ASSUME CS:MAIN,DS:MAIN,ES:MAIN,SS:MAIN
ORG 100h
START:
28

char message[]="Hello World!";


printf("%s",message);
getch();
return 0;
}

2.

message DB "Hello World!$"


MOV AH,09h
MOV DX,OFFSET message
INT 21h
INT 20h
MAIN ENDS
END START

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.

29

8. Assessment (Rubric for Laboratory Performance):


Activity No. 5
LOGICAL INSTRUCTIONS
Course Code: Cp413L1
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 TRUEand 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.
30

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
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 leavebits B7-B4 unaffected. The XOR
operation can also be used to clear a register to zero theoperation XOR AX, AX will set AX to zero (this
requires less machine code than MOVAX,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:
Type the following program in Notepad.
TITLE logic.asm
.model small
.stack 100h
.data
myStringdb "Proud to be TIPians","$"
.code
31

main proc
movax,@data
movds,ax
movbx,offsetmyString
LP1: mov dl,[bx]
Cmp dl, '$'
Je exit
Incbx
;insert code here
mov ah,02
int 21h
jmp lp1
Exit: Mov ax, 4c00h
Int 21h
Main endp
End main
Save the program as logic.asm
Assemble and execute the program.
Analyze the output and record the output in Table 5.1
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 timeplace the line ;insert code here, with "or dl, 00100000B".
2. Save the program as or.asm.
3. Assemble and execute the program.
32

4. Observe and record the output in Table 5.3.


5. How is your output different from before? Why?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

6. DATA AND RESULTS:


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

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: Cp413L1
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 numbers sign bit.Logical Shift fills the
34

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
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
movax,@data
movds,ax
movbl,num
mov cx,8
here: shr bl,1
Jcis_one
Mov dl,30h
Jmp print
Is_one:
Mov dl,31h
Print:
Mov ah,2
int 21h
loop here
35

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?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

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?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

36

6. DATA AND RESULTS:


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):

37

Activity No.7
PROCEDURE
Course Code: Cp413L1
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 addressesand 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 PUSHinstruction is used to place
values on the stack and the POPinstruction 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:
38

.stack 100h
Procedure
Aprocedure or subroutine is a special part of the program that can be called forexecution from any
point in the program. The procedure is written toprovide a function that must be performed frequently at
various points inthe main program. Whenever the function must be performed, a singleinstruction is
inserted into the main body of the program to CALLthe procedure. The RETinstruction 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

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
PROCEDURE1endp
PROCEDURE2 proc
:
ret
PROCEDURE2endp
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
39

main proc
movax,@data
movds,ax
xoral,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
Ja ischar
Add al,30h
Jmpprintit
Ischar: add al,37h
Printit: Movdl,al
Mov ah,2
Int 21h
Ret
Out1hex endp
Pcrlfproc
Mov dl,0ah
Mov ah,2
Int 21h
Mov dl,0dh
Mov ah,2
Int 21h
Ret
Pcrlfendp
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 Pcrlfdo?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

40

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?
___________________________________________________________________________
___________________________________________________________________________
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
movax,@data
movds,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
41

mov ah,01h
int 21h
sub al,'0'
add al,num1
movsum,al
lea dx,msg3
mov ah,09h
int 21h
movsi,offset res
mov ax,00
moval,sum
call addition
lea dx,res
mov ah,09h
int 21h
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
incsi
42

mov [si],al
loop rpt2
incsi
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.
6. DATA AND RESULTS:
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 passwordformed from 10
characters. The program prints the password as stars on thescreen. 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
43

octal.
8. Assessment (Rubric for Laboratory Performance):

Activity No. 8
SCREEN ATTRIBUTES
Course Code: Cp413L1
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
44

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
movbh, 00eh
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
2.
3.
4.

Save the program as


Assemble and execute the
Analyze and record the
Sample Problem B.
1. Modify program
number 15 with mov
2. Analyze and record the
3. How is your output

mov ah,02
mov dl, 'I'
int 21h
mov ah,02
mov dl, 'P'
int 21h
mov ah, 4ch
int 21h
end start

screen1.asm.
program.
output in Table 8.1.
screen1.asm, replace line
bh,0ch.
output in Table 8.2.
different from before? Why?

45

_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
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?
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________

Sample Problem D.
1. Type the following

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

program in Notepad.

mov ah, 06h


mov cl, 18h
movch, 00h
mov dl, 36h
mov dh, 18h
movbh, 40h
int 10h
mov ah, 06h
mov cl, 36h
movch, 00h
mov dl, 4fh
mov dh, 18h
movbh, 10h
int 10h
46
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.

6. DATA AND RESULTS:


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:

47

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

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

8. Assessment (Rubric for Laboratory Performance):

48

Activity No. 9
Parallel Port Interfacing
Course Code: Cp413L1
Course Title: Computer Systems Organization with Assembly Language
Section:
Name:
1. Objective:
This activity aims to interface a circuit using a parallel port.

Program:
Date Performed:
Date Submitted:
Instructor:

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.

49

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:
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 1s to the DATA port pins and test the program.
This program when executed must satisfy the following conditions:
When user presses 1 on the keyboard , the LEDs light from left to right
When user presses 2 on the keyboard , the LEDs light from right to left
When user presses 0 on the keyboard ,the LEDs light will turn OFF.
When user presses ESC the program exits.
!
dosseg
.model small
.code
start: call test
jmp start
test:
push cx
push ax
50

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
call test
call delay
jmp lop
right: mov al,01h
mov dx,378h
loop:outdx,al
ror al,1
call test
call delay
jmp loop
off: mov al,0
mov dx,378h
out dx,al
51

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.

52

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?
53

_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
13. Record the output in Table 9.1.
6. DATA AND RESULTS:
Table 9.1- Result of Sample Problem A
Key Pressed
LEDs ( 0-OFF) (1-ON)
D7 D6 D5 D4 D3 D2 D1
0
1
2
Esc

D0

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 youre a classmate and design a circuit that will let you apply parallel port
interfacing.
8. Assessment (Rubric for Laboratory Performance):

54

S-ar putea să vă placă și