Documente Academic
Documente Profesional
Documente Cultură
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:
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.
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
___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ 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 ................
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
21
DL,54
21
DL,49
21
DL,50
21
20
Command
Register
Syntax
A [Starting Address]
Example
A 100
D 100
D 110 11F
E [Address] [Data]
E CS:107
E CS:100 Welcome to
Assembly Programming!
G
G=CS:100 11F
H value1 value2
H 0120 0100
N c:\CompOrg\Prog1.com
R [Register name]
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
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
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
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
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.
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
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
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
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
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
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
2.
Convert the each of the following C codes into its equivalent assembly code:
a. if ( ebx<=ecx) { eax=5;edx=6;}
3. Show a program that multiples 50 (decimal) and 10 (decimal) without using the MUL and IMUL
instructions.
29
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
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
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
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
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
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.
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.
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
3. Make an assembly program that will display the figure shown below. Save your file as Football.asm
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:
49
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
_________________________________________________________________________________
_________________________________________________________________________________
_________________________________________________________________________________
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