0% found this document useful (0 votes)
25 views7 pages

Micro CH 6 Ex

The document contains exercises and solutions related to data transfer, arithmetic, and logical operations in assembly language programming. It provides examples of exchanging values between memory locations, performing arithmetic operations without using multiplication or division instructions, and manipulating logical operations. Each example is accompanied by code segments demonstrating the solutions.
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)
25 views7 pages

Micro CH 6 Ex

The document contains exercises and solutions related to data transfer, arithmetic, and logical operations in assembly language programming. It provides examples of exchanging values between memory locations, performing arithmetic operations without using multiplication or division instructions, and manipulating logical operations. Each example is accompanied by code segments demonstrating the solutions.
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/ 7

Exercises on Chapter 6

1- Data Transfer Group:


Example 1: What Two memory locations R1 and R2 store 07H and 3FH respectively.
Exchange the values in these memory locations without using the exchange instruction.

Solution

DATA SEGMENT
R1 DB 07H
R2 DB 3FH
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA ; Initialize the Data Segment
register
MOV DS, AX
MOV AL, R1 ; (AL)  07H
MOV BL, R2 ; (BL)  3FH
MOV R1, BL ; (R1)  (BL)
MOV R2, AL ; (RL)  (AL)
CODE ENDS

• If one uses the exchange instruction, the code segments will be:

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, R1
XCHG AL, R2
MOV R1, AL
CODE ENDS

Example 2: Two memory locations R1 and R2 store 07H and 3FH respectively. Exchange
the values in these memory locations using indirect addressing.

Solution

1
DATA SEGMENT
R1 DB 07H
R2 DB 3FH
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA ; Initialize the Data Segment
register
MOV DS, AX
LEA SI, R1 ; Offset address of R1 in SI
LEA DI, R2 ; Offset address of R2 in DI
MOV AL, (SI) ; (AL)  (R1)
MOV BL, (DI) ; (BL)  (R2)
MOV (SI), BL ; (R1)  (BL)
MOV (DI), AL ; (R2)  (AL)
CODE ENDS

Exercise 1: What will be the values in K1, K2, K3 memory locations at the end of following
program?

DATA SEGMENT
K1 DW 3F99H
K2 DW 7FFFH
K3 DB 02H
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AX, K1 ; (AX)  3F99H
MOV BX, K2 ; (BX)  7FFFH
MOV CL, K3 ; (CL)  02H
MOV AL, BL ; (AL)  FFH
MOV BL, CL ; (BL)  02H
MOV CL, AL ; (CL)  FFH
MOV K1, AX ; (K1)  3FFFH
MOV K2, BX ; (K2)  7F02H
MOV K3, CL ; (K3)  FFH

2
CODE ENDS

2- Arithmetic Group:
Example 4: Multiply two 8-bit numbers stored in P1 and P2 and store the result in P3, using
both direct and indirect addressing.

Solution

(a) Using Direct addressing:

DATA SEGMENT
P1 DB 7FH
P2 DB 05H
P3 DW 0000H
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, P1
MUL BYTE PTR P2 ; Result is in AX
MOV P3, AX
CODE ENDS

(b) Using Indirect addressing:


In case we use indirect addressing, the code segment will change to:

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
LEA SI, P1
LEA DI, P2
MOV AL, (SI)
MUL BYTE PTR (DI)
LEA DI, P3
MOV (DI), AX
CODE ENDS

3
Example 5: Two 8-bit numbers X and Y are stored in memory. Calculate Z based on the
following equation and store it in memory as a 16-bit number. Discard the remainder in
division operation.
Z = (X2 + Y2)/ (X2 – Y2)

Solution

DATA SEGMENT
X DB 05H
Y DB 07H
Z DW 0000H
SUM-SQ DW 0000H
DIF-SQ DW 0000H
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, X
MUL X
MOV BX, AX ; (BX)  X2
MOV AL, Y
MUL Y
MOV CX, AX ; (CX)  Y2
MOV AX, BX ; (AX)  X2
ADD AX, CX ; (AX)  X2 + Y2
MOV SUM-SQ, AX
MOV AX, BX
SUB AX, CX ; (AX)  X2 – Y2
MOV DIF-SQ, AX
MOV DX, 0000H
MOV AX, SUM-SQ ; (AX)  X2 + Y2
DIV DIF-SQ
MOV Z, AX
CODE ENDS

Exercise 1: What will be the value in S3 at the end of the following program?

DATA SEGMENT
S1 DW 0735H

4
S2 DW 0826H
S3 DB 05H
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AX, S1 ; (AX)  0735H
ADD AX, S2 ; (AX)  0F5BH
MOV S1, AX ; (0735H)  0F5BH
SUB AX, 00FFH ; (AX)  0E5CH
DIV S3 ; (AL) = (AX) / S3 = 2DFH, (AH) = 1
MOV S3, AL ; (S3)  2DFH
CODE ENDS

3- Logical Group:
Example 6: Two numbers X1 and X2 are stored in memory. Perform the following
operations and store the results in X3.
(X3) = ((X1) AND 0FH) XOR (X2)

Solution
DATA SEGMENT
X1 DB 9AH
X2 DB F7H
X3 DB 00H
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, X1
LEA SI, X2
AND AL, 0FH
XOR AL, (SI)
MOV X3, AL
CODE ENDS

5
Exercise 1: What will be the values of X1 and X2 at the end of following program?

DATA SEGMENT
X1 DB 07H
X2 DB F0H
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, X1 ; (AL)  07H
XOR AL, 9FH ; (AL)  9FH
MOV CL, 02 ; (CL)  02
ROR AL, CL ; (AL)  26H
MOV X1, AL ; (X1)  26H
AND AL, X2 ; (AL)  20H
MOV CL, 03 ; (CL)  03H
SHL AL, CL ; (AL)  98H
MOV X2, AL ; (X2)  98H
CODE ENDS

Exercise 2: Two numbers N1 and N2 are stored in memory. Develop a program to perform
the following operations and store the results back in N1 and N2.
N1 = (N1*64) AND 0FH
N2 = (N2/16) XOR 0FH
Do not use multiplication or division instruction.
Solution

DATA SEGMENT
N1 DB 21H
N2 DB 34H
DATA ENDS

CODE SEGMENT
ASSUME CS: CODE, DS: DATA
START: MOV AX, DATA
MOV DS, AX
MOV AL, N1
MOV CL, 06
SHL AL, CL

6
AND AL, 0FH
MOV N1, AL

MOV AL, N2
MOV CL, 04
SHR AL, CL
XOR AL, 0FH
MOV N2, AL
CODE ENDS

You might also like