0% found this document useful (0 votes)
19 views19 pages

Experiment 4 Mi Crop

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

Experiment 4 Mi Crop

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

Experiment 4

OTHER ASSEMBLY
LANGUAGE
INSTRUCTIONS
DATE: NOVEMBER 4,2024
PROGRAM/YEAR: BSCpE-3A
SUBJECT: MICROPROCESSOR

MEMBERS:
CLIFFORD BANIEL
LEMUEL JEFFERSON CASTILLO
XERXES CODINA
RODNEY ALDEN ROSARIO

ENGR.BERNARD BISUECOS
INSTRUCTOR
Objectives:

➢ To understand how ASCII encoding represents characters and why it’s important to perform

arithmetic operations—like addition, subtraction, and multiplication—on ASCII values.

➢ To familiarize oneself with logical operations such as AND, OR, XOR, and NOT, as well as

arithmetic operations. Understanding these operations is essential for manipulating binary data, as

they allow for the alteration of specific bits within a byte.

➢ To explore various string manipulation techniques, particularly how to copy, reverse, and adjust

strings in memory.
PROGRAM 1:
DATA SEGMENT
BYTES EQU 08H
NUM2 DB 05H, 5AH, 6CH, 55H, 66H, 77H, 34H, 12H
NUMI DB 04H, 56H, 04H, 57H, 32H, 12H, 19H, 13H
NUM3 DB 0AH DUP(00)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, DATA
MOV DS, AX
MOV CX, BYTES
LEA SI, NUMI
LEA DI, NUM2
LEA BX, NUM3

NEXT:
MOV AX, 00
MOV AL, [SI]
MOV DL, [DI]
MUL DL
MOV [BX], AL
MOV [BX+1], AH
INC SI
INC DI
INC BX
INC BX
DEC CX
JNZ NEXT
INT 3H
CODE ENDS
END START

The program performs element-wise multiplication of two arrays (NUM2 and NUMI), with each product
stored as a 16-bit value in a third array (NUM3). Specifically, for each corresponding pair of elements
from NUM2 and NUMI, it multiplies them and stores the result in NUM3 using two bytes (one for the
lower byte and one for the upper byte). The program iterates through all elements, performing the
multiplication and storage for each pair, then terminates. This process results in NUM3 containing the
products of each element pair from NUM2 and NUMI.

PROGRAM 2:

CODE SEGMENT

ASSUME CS:CODE

START:

MOV AL, '5'

MOV BL, '9'

MOV AX, 0FFFFH

ADD AL, BL

AAA

OR AX, 3030H

INT 3H
CODE ENDS

END START

This assembly program begins by adding the ASCII values of the characters '5' and '9'. It then adjusts the
result to ensure that it is a valid ASCII character using the AAA (ASCII Adjust AX after Addition)
instruction. Following this adjustment, the program converts the result into a displayable format with the
OR AX, 3030H instruction, which modifies the value in AX for proper representation as ASCII.

Finally, the program halts execution with the INT 3H instruction, which is typically used for debugging
purposes. Overall, this program illustrates basic arithmetic operations on ASCII values and prepares the
result for output, although it does not actually display the result on the screen.

PROGRAM 3:

CODE SEGMENT

ASSUME CS:CODE

START:

MOV AL, '9'

MOV BL, '5'

SUB AL, BL

AAS

OR AX, 3030H

INT 3H

CODE ENDS

END START
This assembly program begins by loading the ASCII values of the characters '9' and '5' into the registers
AL and BL, respectively. It then performs a subtraction, subtracting the ASCII value of '5' (stored in BL)
from the ASCII value of '9' (in AL). The result in AL represents the difference between these two ASCII
values.

To ensure that the result reflects a valid ASCII representation for decimal digits, the program uses the
AAS (ASCII Adjust AX after Subtraction) instruction. This adjustment is necessary after performing a
subtraction on ASCII characters. Following this, the program converts the numerical result into its
corresponding ASCII representation by executing the OR AX, 3030H instruction. This modification
prepares the value in AX for output.

Finally, the program halts execution using INT 3H, which is typically employed for debugging purposes.
This structure of the program effectively demonstrates how to manipulate ASCII values through
arithmetic operations in assembly language.

PROGRAM 4:

CODE SEGMENT

ASSUME CS:CODE

START:

MOV AL,5

MOV BL,9

MUL BL

AAM

OR AX,3030H

INT 3H

CODE ENDS

END START
This assembly program starts by loading the numbers 5 and 9 into two registers, AL and BL. It then
multiplies these numbers using the MUL instruction, which stores the result in the AX register.

After the multiplication, the program adjusts the result to ensure its formatted correctly as an ASCII value.
This is done with the AAM (ASCII Adjust AX after Multiply) instruction, which prepares the result for
representation as characters, making it suitable for display.

To convert the numeric result into a displayable format, the program adds 3030H to the AX register. This
step changes the raw number into its corresponding ASCII characters, which is what you would want if
you were displaying it on the screen.

Finally, the program ends its execution with the INT 3H instruction, a common practice in debugging to
pause the program. Overall, this program illustrates how to multiply numbers and prepare the result in a
way that makes it easy to display as characters, even though it doesn't show the result directly.

PROGRAM 5:

CODE SEGMENT

ASSUME CS:CODE

START:

MOV AX, 0607H

MOV CH, 09H

AAD

DIV CH

OR AX, 3030H

INT 3H

CODE ENDS

END START
This assembly program starts by loading the hexadecimal value 0607H into the AX register, where 06
represents the tens and 07 the units. The AAD (ASCII Adjust AX before Division) instruction then
converts this "packed" decimal format into a simple binary number, which results in the decimal value 67
(since 6 * 10 + 7 = 67).

Next, it divides this number by 9, placing the result (the quotient) in AL and the remainder in AH. After
this, the program uses OR AX, 3030H to prepare the result for display by converting it to an ASCII-
compatible format. Finally, it halts with INT 3H, a command often used to stop the program during
debugging.

PROGRAM 6:

CODE SEGMENT

ASSUME CS:CODE

START:

MOV AL, 85H

MOV BL, 99H

AND AL, BL

INT 3H

CODE ENDS

END START

This assembly program is designed to perform a bitwise AND operation between two hexadecimal values.
It starts by loading the value 85H into the AL register and the value 99H into the BL register. The key
action happens with the AND AL, BL instruction, which compares each corresponding bit of the two
registers.

In a bitwise AND operation, a bit in the result is set to 1 only if both bits being compared are also 1. So,
after executing this instruction, AL will contain the result of the AND operation.
The program concludes with INT 3H, which is typically used for debugging and stops the program's
execution. Overall, this program effectively demonstrates how to perform a fundamental bitwise
operation in assembly language.

PROGRAM 7:

CODE SEGMENT

ASSUME CS:CODE

START:

MOV AL, 85H

MOV BL, 99H

OR AL, BL

INT 3H

CODE ENDS

END START

This assembly program is designed to perform a bitwise OR operation on two hexadecimal values. It
begins by loading the value 85H into the AL register and 99H into the BL register. The key operation
takes place when the program executes the OR AL, BL instruction.

During this operation, each bit of AL and BL is compared. The resulting bit will be set to 1 if either of the
bits being compared is 1. Consequently, after the operation is completed, the AL register will contain the
result of the OR operation between 85H and 99H.

The program then ends with the INT 3H instruction, which is commonly used for debugging and
effectively halts execution. In summary, this code showcases how to perform a basic bitwise operation in
assembly language, specifically the OR function to combine two values.
PROGRAM 8:

CODE SEGMENT

ASSUME CS: CODE

START:

MOV AL, 85H

MOV BL, 99H

XOR AL, BL

INT 3H

CODE ENDS

END START

This assembly program is designed to perform a bitwise XOR operation between two hexadecimal values.
It starts by loading the value 85H into the AL register and 99H into the BL register. The primary action
occurs with the XOR AL, BL instruction, which compares the bits in both registers.

In a bitwise XOR operation, a bit in the result is set to 1 only if the corresponding bits in the two registers
are different (i.e., one is 1 and the other is 0). As a result, after executing this instruction, the AL register
will contain the result of the XOR operation between 85H and 99H.

The program concludes with INT 3H, a command typically used for debugging that stops execution.
Overall, this program effectively demonstrates how to perform a basic bitwise operation in assembly
language, specifically the XOR operation.
NOT OPERATION:

CODE SEGMENT

ASSUME CS:CODE

START:

MOV AL, 85H

NOT AL

INT 3H

CODE ENDS

END START

This assembly program performs a bitwise NOT operation on the hexadecimal value 85H. It begins by
loading 85H into the AL register. The NOT AL instruction then flips each bit in AL, transforming
10000101 (which is 85H in binary) into 01111010, corresponding to 7AH. Finally, the program halts
execution with INT 3H, which is typically used for debugging purposes. In essence, this program
demonstrates how to invert the bits of a value using assembly language, changing 85H to 7AH.

PROGRAM 9:

CODE SEGMENT

ASSUME CS:CODE

START:

MOV AL, 85H

MOV BL, 99H

AND AL, BL
NOT AL

INT 3H

CODE ENDS

END START

This assembly program carries out a sequence of bitwise operations using the hexadecimal values 85H
and 99H. It begins by loading 85H into the AL register and 99H into the BL register. The program then
performs a bitwise AND operation with the instruction AND AL, BL, which compares the bits of these
two values and results in 81H being stored in AL.

Following that, the program executes a bitwise NOT operation with NOT AL, which flips all the bits in
AL, transforming the value from 81H to 7EH. Finally, the program ends with the INT 3H instruction, a
common way to halt execution and facilitate debugging.

In summary, this program takes the values 85H and 99H, computes their bitwise AND to yield 81H, and
then inverts that result to produce 7EH. This process illustrates how assembly language can manipulate
binary data through bitwise operations.

PROGRAM 10:

DATA SEGMENT

NUM DB 45H

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

START:
MOV AX, DATA

MOV DS, AX

MOV AX, NUM

MOV AH, AL

MOV CL, 4

SHR AH, CL

AND AX, 0F0FH

INT 3H

CODE ENDS

END START

This assembly program manipulates the hexadecimal value 45H. It starts by loading this value into the
AX register and then copies it to the AH register. The program performs a logical right shift on AH by 4
bits, resulting in 04H, effectively isolating the upper half of the original value. It then executes a bitwise
AND operation with 0F0FH, which clears certain bits in the AX register while preserving others. Finally,
the program halts with an interrupt for debugging, allowing the programmer to inspect the register state.
Overall, it demonstrates basic data manipulation techniques in assembly language.

PROGRAM 11:

DATA SEGMENT

NUM DB 45H

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA


START:

MOV AX, DATA

MOV DS, AX

MOV AX, NUM

MOV AH, AL

MOV CL, 4

SHR AH, CL

AND AX, 0F0FH

OR AX, 3030H

INT 3H

CODE ENDS

END START

This assembly program manipulates the hexadecimal value 45H, defined as NUM. It begins by setting up
the data segment and loading 45H into the AX register. The program then copies this value to both bytes
of AX, effectively making it 4545H.

Next, it shifts the upper byte (AH) to the right by 4 bits, resulting in 04H, and clears specific bits in AX
using a bitwise AND with 0F0FH. The program then converts the result to ASCII by adding 3030H to
AX, preparing it for display. Finally, it halts execution for debugging with an interrupt instruction,
allowing inspection of the register state after the operations. Overall, the program demonstrates basic data
manipulation and conversion techniques in assembly language.
PROGRAM 12:

DATA SEGMENT

SRC DB 'MICROPROCESSOR'

DB 10 DUP(?)

DST DB 20 DUP(0)

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA, ES:DATA

START:

MOV AX, DATA

MOV DS, AX

MOV ES, AX

LEA SI, SRC

LEA DI, DST

MOV CX, 20

CLD

REP MOVSB

INT 3H

CODE ENDS

END START
This assembly program is designed to copy the string 'MICROPROCESSOR' from the SRC memory
location to the DST memory location. It initializes the data segment registers to point to the appropriate
memory locations and uses the LEA instruction to load the addresses of the source and destination into
the SI and DI registers, respectively.

The program sets a counter (CX) to 20 for the number of bytes to copy and clears the Direction Flag with
CLD to ensure data moves from the source to the destination correctly. The REP MOVSB instruction is
then used to repeatedly copy bytes from SRC to DST until the counter reaches zero. Finally, it halts
execution with INT 3H, which is typically used for debugging. Overall, the program effectively
demonstrates basic string copying in assembly language.

PROGRAM 17: STRING REVERSAL:

DATA SEGMENT

ORG 2000H

SRC DB 'MICROPROCESSORS'

COUNT EQU ($-SRC) DEST

DB?

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

START:

MOV AX, DATA

MOV DS, AX

MOVE CX, COUNT


LEA SI, SRC

LEA DI, DEST

ADD SI, CX

DEC CX

BACK:

MOV AL, [SI]

MOV [DI], AL

DEC SI

INC DI

DEC CX

JNZ BACK

INT 3H

CODE ENDS

END START

The assembly program starts by setting up a data segment that contains the string
'MICROPROCESSORS', specifying that it begins at memory address 2000H. It calculates the length of
this string using a directive that determines how many bytes it occupies.

Once in the code segment, the program prepares the data segment register to point to the location where
the string and its destination are stored. It then uses the LEA instruction to load the addresses of both the
source string and the destination into two registers: SI for the source index and DI for the destination
index.

To copy the string in reverse, the program adjusts the SI register to point to the end of the string. It enters
a loop labeled BACK, where it takes one character at a time from the source. It reads the character from
the memory location that SI points to, stores it temporarily, and then writes that character to the location
indicated by DI. As it copies, SI is decremented to move backward through the string while DI increments
to fill the destination buffer. This continues until every character has been copied.

Finally, the program concludes with an interrupt command that allows for debugging, making it possible
to check the values in the registers and memory after the program has run. In essence, this program
showcases how to manipulate strings in assembly language by reversing the order of characters during the
copy process.

Summary

The assembly language programs we've explored provide a fascinating look into the core concepts of data

manipulation at a fundamental level. They highlight how ASCII encoding represents characters and

illustrate the importance of performing arithmetic operations—like addition, subtraction, and

multiplication—on ASCII values while ensuring the results are adjusted to reflect valid characters.

Additionally, these programs showcase various logical operations, including AND, OR, XOR, and NOT,

emphasizing their role in manipulating binary data and changing specific bits within bytes. We also

delved into string manipulation techniques, learning how to copy, reverse, and adjust strings in memory,

which is essential for handling character data effectively.

These examples illustrate the power of assembly language in performing precise operations on data,

enabling efficient programming practices. By combining arithmetic and logical operations with string

manipulation, we gain a clearer understanding of how low-level programming directly interacts with

computer architecture and memory.


Conclusion

In conclusion, the assembly programs we've examined are not just practical exercises; they reinforce

crucial concepts that are relevant across many areas of computing. By achieving our objectives—such as

grasping ASCII operations, familiarizing ourselves with logical and arithmetic functions, and mastering

string manipulation techniques—we can build a strong foundation in assembly language programming.

This knowledge is invaluable for anyone looking to deepen their understanding of computer systems,

improve performance, and tackle more complex programming challenges. As technology continues to

advance, these foundational skills remain essential for effective programming and data processing in a

wide range of applications.

You might also like