Laboratory 4
Laboratory 4
ASSEMBLY LANGUAGE
INSTRUCTIONS
1|Page
EXPERIMENT 4
OTHER ASSEMBLY LANGUAGE INSTRUCTIONS
GENERAL OBJECTIVE
• TO BE FAMILIAR WITH THE COMMONLY USED INSTRUCTIONS IN ASSEMBLY
SPECIFIC OBJECTIVE
• To assemble, link, and simulate all the program in part1 of this experiment.
• To better understand the usage of the different Logical operators in Assembly Language.
• To understand how assembly language can reverse a string and compare two strings
together.
PROCEDURES
Part1
• ENCODE THE FOLLOWING PROGRAMS
PROGRAM 1:
DATA SEGMENT
BYTES EQU 08H
NUM2 DB 05H, 5AH, 6CH, 55H, 66H, 77H, 34H, 12H
NUM1 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, NUM1
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
2|Page
INC BX
INC BX
DEC CX
JNZ NEXT
INT 3H
CODE ENDS
END START
PROGRAM 2:
CODE SEGMENT
ASSUME CS: CODE
START:MOV AL, '5'
MOV BL, '9'
ADD AL, BL
AAA
OR AX, 3030H
INT 3H
CODE ENDS
END START
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
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
3|Page
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
PROGRAM 6:
CODE SEGMENT
ASSUME CS: CODE
START: MOV AL, 85H
MOV BL, 99H
AND AL, BL
INT 3H
CODE ENDS
END START
PROGRAM 7:
CODE SEGMENT
ASSUME CS: CODE
START: MOV AL, 85H
MOV BL, 99H
OR AL, BL
INT 3H
CODE ENDS
END START
PROGRAM 8:
CODE SEGMENT
ASSUME CS: CODE
START: MOV AL, 85H
MOV BL, 99H
XOR AL, BL
INT 3H
CODE ENDS
END START
4|Page
Logic Operation 8086 Assembly Language Program 12: NOT OPERATION:
CODE SEGMENT
ASSUME CS: CODE
START: MOV AL, 85H
NOT AL
INT 3H
CODE ENDS
END START
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
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
5|Page
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
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
6|Page
8086 Assembly Language program 17: String reversal
DATA SEGMENT
ORG 2000H
SRC DB 'MICROPROCESSOR$'
COUNT EQU ($-SRC)
DEST DB ?
DATA ENDS
CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV 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
7|Page
MOV ES, AX
LEA SI, STR1
LEA DI, STR2
MOV CX, LEN
CLD
REPE CMPSB
JNE FAIL
PRINTSTRING M1
INT 3H
FAIL: PRINTSTRING M2
INT 3H
CODE ENDS
END START
Part 2
Simulate and Briefly Discuss the Task Accomplished by each program.
Program 1:
The program multiplies the defined bytes of NUM1 to the defined bytes of NUM2 then
store their product on NUM3. But with every Iteration, the AX register is cleared to zero, that
means the program is only capable to store the product of num1 and num2 on a specified
iterations.
Program 2:
The program number 2 can add two numbers. With the defined characters in the
program, ‘5’ means 35H, and ‘9’ is equivalent to 39H with this data inputted the addition of 35H
and 39H is equal to 6EH. The AAA in the program will unpacked the BCD (Binary Coded Decimal)
and store the values in AX. After the AAA in the program is executed, the AX register now contains
0104H that is the same with the addition of 5 and 9 which is equal to 14, 01H in AH and 04H in
AL. after the AAA command the value of AX now is 0104H and it will be OR by 3030H and after
this command is executed the value AX will become 3134H.
8|Page
Program 3:
The program number 3 can subtract two numbers. With the defined characters in the
program, ‘9’ means 39H, and ‘5’ is equivalent to 35H with this data inputted the difference of
39H and 35H is equal to 4H. The AAS in the program will unpacked the BCD (Binary Coded
Decimal) and store the values in AX. After the AAS in the program is executed, the AX register
now contains 4H that is the same with the difference of 9 and 5 which is equal to 4, 00H in AH
and 04H in AL. After the AAS command is executed the value of AX now is 0004H and it will be
OR by 3030H and after this command is executed the value AX will become 3034H.
Program 4:
The program number 4 can multiply two numbers. With the defined characters in the
program, ‘5’ means 35H, and ‘9’ is equivalent to 39H with this data inputted the product of 35H
and 39H is equal to 0BCDH. The AAM in the program will unpacked the BCD (Binary Coded
Decimal) and store the values in AX. After the AAM in the program is executed, the AX register
now contains 0405H that is the same with the product of 9 and 5 which is equal to 45, 04H in AH
and 05H in AL. After the AAM command is executed the value of AX now is 0405H and it will be
OR by 3030H and after this command is executed the value AX will become 3435H.
Program 5:
The program number 5 can divide two numbers. The first step in the program will be the
0607H will be move to the AX register and move the 09H to CH register. The AAD in the program
will unpacked the BCD (Binary Coded Decimal) and store the values in AX, the 0607H is equal to
#67 in decimal in ASCII code and the #67 in decimal is equal to 43H that’s why after executing the
AAD the AX register will now contain 0043H. After the Div CH is executed, the program will now
divide the 67 to 9 the quotient will be stored to AL which is 07H and the remainder will be stored
to AH which is 04H, now the AX register will now contain 0407H.
9|Page
Program 6:
The program 6 can execute the logical operation called “AND”. The 85H will be first move
to AL register and the 99H will be move to the BL register, then after the command “AND AL, BL”
is executed the AX register will now be contained 0081H. The BL register is ANDed to the AL
register and the result is stored to the AL register.
Program 7:
The program 7 can execute the logical operation called “OR”. The 85H will be first move
to AL register and the 99H will be move to the BL register, then after the command “OR AL, BL”
is executed the AX register will now be contained 009DH. The BL register is OR’ed to the AL
register and the result is stored to the AL register.
Program 8:
The program 8 can execute the logical operation called “XOR”. The 85H will be first move
to AL register and the 99H will be move to the BL register, then after the command “XOR AL, BL”
is executed the AX register will now be contained 001CH. The BL register is XOR’ed to the AL
register and the result is stored to the AL register.
Program 9:
The program 9 can execute the logical operator “AND” and “NOT”. The 85H will be first
move to AL register and the 99H will be move to the BL register, then after the command “AND
AL, BL” is executed the AX register will now be contained 0081H, then after the command “NOT
AL” is executed the program will now use the logical operation not to the AL register, the AX
register will now contain 007EH.
10 | P a g e
Program 10:
In the program #10, the command SHR and the logical operator “AND” is included first
define NUM equal to 45H, then mov the 45H to AX which will be stored to AL register, the next
command “MOV AH, AL” will copy the contents of AL register to AH register and now the AX
register will now contain 4545H, then move 4 to CL register. The command “SHR AH, CL” The SHR
(shift right) instruction performs a logical right shift on the AH register., the AX register now
contains 0445H, and then it will be AND’ed by 0F0FH, after this command is executed the AX
register will now contain 0405H.
Program 11:
The program 11 is running like the program 10, the only difference is that the program 11
uses the logical operation “OR” at the end of the program. After executing the command “AND
AX, 0F0FH” is executed and get the result of AX register to 0405H the AX register will now be
OR’ed to 3030H, after the command is executed the AX register will now contains 3435H
Program 12:
The program 12 used the CLD to clear the direction flag and the “REP MOVSB” the REP
indicates repeat while equal while the MOVSB tells the assembler to move data as bytes. On the
program the Register SI is set to 0000H while the DI register is set to 0018H and the CX register
to 20 which is equal to 0014H. After the CLD is executed the direction flag is cleared, and with
the REP MOVSB command the program will keep its loop until CX is decremented to 0000H, while
the loop is ongoing the SI and DI register is Incremented by 0001H on every loop. After breaking
the loop the SI register contains 0014H while DI register contains 002CH.
11 | P a g e
8086 Assembly Language program 18: Comparison of two strings
In program 18 the program can be able to compare two strings and display “STRING R
EQUALS” if the two string being compared is equal otherwise it will display “STRING R NOT
EQUALS”. By the use “CMPSB” the program can be able to Compares byte at address DS:(E)SI
with byte at address ES:(E)DI and sets the status flags accordingly.
Part3
Submit a final report that contains the following:
SUMMARY
All in all simulating all the program in num1 had a great impact to my understanding about
assembly language especially on using the Arithmetic operations with the logical operations in
the program. The usage of AAA, AAS, AAM, and AAD makes my understanding about unpacking
BCD (Binary Coded Decimal) expand more. I also discover and learned how to reverse a string
using assembly language and specially on how to compare two strings and also display if the two
strings are equal or not equal.
12 | P a g e
CONCLUSION
With this experiment I was able to successfully assemble, connect, and replicate every
program in this experiment's first portion. Every program in Part 1 serves a unique purpose, and
because of this, I learned more about how to use logical operations in Assembly Language. The
use of AAA, AAS, AAM, and AAD has helped me comprehend BCD (Binary Coded Decimal) more
thoroughly. I also discovered and learned how to compare two strings using assembly language,
as well as how to show whether the two strings are equivalent or not.
13 | P a g e