0% found this document useful (0 votes)
9 views15 pages

Problem Set-1

Uploaded by

mayankagra000
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)
9 views15 pages

Problem Set-1

Uploaded by

mayankagra000
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/ 15

PROBLEM SET-1

EC-373 Microprocessor
Engineering Lab
PROBLEM NO. 1 :
Write an assembly-level code to perform multiplication and division of two given
numbers, and store the result in two consecutive external memory locations
pointed by a base address present in the Destination Index Register.

PROPOSED SOLUTION :

SOLUTION :

ADDRESS OPCODE MNEMONIC COMMENTS

Load the data segment address


7210H B8 20 07 mov ax, @data
into AX .

PROBLEM SET-1 1
Move AX into DS to set data
7213H 8E D8 mov ds, ax
segment.

Move the byte at address [SI]


7215H 8A 1C 8B mov bl, [si]
to BL .

7218H 3E 02 00 mov di, baseadd Load 2000h into DI .

721BH 46 inc si Increment SI by 1.

Move the byte at address [SI]


721CH 8A 04 mov al, [si]
to AL .

721E H F6 E3 mul bl Multiply AL by BL , result in AX .

7220H 88 05 mov [di], al Store the result of AL at [DI] .

7222H 83 C7 01 add di, 1 Increment DI by 1.

7225H 8A 1E 00 00 mov bl, num1 Move 3 (num1) into BL .

7229H A0 01 00 mov al, num2 Move 9 (num2) into AL .

Divide AX by BL . Result:
722CH F6 F3 div bl
quotient in AL , remainder in AH .

722EH 89 05 mov [di], ax Store the result of AX at [DI] .

7230H B4 4C mov ah, 4Ch Prepare for program termination.

Interrupt to terminate the


7232H CD 21 int 21h
program.

FINAL OUTPUT :

Register Address Hexadecimal value Decimal value

0720:2000 1B 27

0720:2001 03 003

Problem No. 2 :
The following infinite series in termed as a Fibonacci series in Mathematics,
where every number in the series is a sum of the preceding two numbers in the
infinite series:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,........

PROBLEM SET-1 2
Write an Assembly-level code for an 8086-CPU, to generate a Fibonacci
series upto 20-terms. You are required to store the 20-terms as hexadecimal
numbers in consecutive locations within the data-segment of the external
memory.

Proposed Solution :

SOLUTION :

Address Opcode Mnemonic Comment

Load the data segment address into


7210H B8 20 07 mov ax, @data
AX .

Load AX into DS to set data


7213H 8E D8 mov ds, ax
segment.

7215H 8A 1C mov bl, [si] Move the byte from address [SI]

PROBLEM SET-1 3
into BL .
mov di,
7217H 8B 3E 02 00 baseadd
Load 2000h into DI .

721B H 46 inc si Increment SI by 1.

Move the byte from address [SI]


721CH 8A 04 mov al, [si]
into AL .

Store the content of BL at address


721EH 88 1D mov [di], bl
[DI] .

7220H 47 inc di Increment DI by 1.

Store the content of AL at address


7221H 88 05 mov [di], al
[DI] .

7223H 47 inc di Increment DI by 1.

7224H B9 14 00 mov cx, 20 Load 20 into CX (for loop count).

7227H 8A E0 mov ah, al Copy AL to AH .


lop: add al,
7229H 02 C3 Add BL to AL (Fibonacci step).
bl

722BH 8A DC mov bl, ah Move AH to BL .

722DH 8A E0 mov ah, al Move AL to AH for next iteration.

722FH 88 05 mov [di], al Store the result of AL at [DI] .

Increment DI to point to next


7231H 47 inc di
memory.

Loop back if CX != 0 (to continue


7232H E2 F5 loop lop
sequence).

7234H B4 4C mov ah, 4Ch Terminate program (DOS interrupt).

Call interrupt 21h to terminate


7236H CD 21 int 21h
program.

FINAL OUTPUT :

Register Address Hexadecimal Value Decimal Value

0720:2000 00 000

0720:2001 1 1

PROBLEM SET-1 4
0720:2003 1 1

0720:2005 2 2

0720:2007 3 3

0720:2009 5 5

0720:200B 8 8

0720:200D D 13

0720:200F 15 21

0720:2011 22 34

0720:2013 37 55

0720:2015 59 89

0720:2017 90 144

0720:2019 E9 233

0720:201B 79 121

0720:201C 1 1

0720:201D 62 98

0720:201E 02 2

0720:201F DB 219

0720:2020 2 2

0720:2021 3D 61

0720:2022 3 3

0720:2023 18 24

0720:2024 4 4

0720:2025 55 85

0720:2026 4 4

0720:2027 6D 109

0720:2028 4 4

0720:2029 C2 194

0720:202A 4 4

PROBLEM SET-1 5
Problem No. 3 :

Write an assembly-language program for 8086-CPU, to compute the factorial


values of the following eight numbers: 1, 2, 3, 4, 5, 6, 7, 8.
Store the eight computed factorial values in successive RAM memory locations,
by alloting atleast two bytes for each computed factorial value.

Proposed Solution :

SOLUTION :

Memory
Machine Code Mnemonic Comment
Location

Initialize AX with the address of


7210H B8 20 07 MOV AX, @data
data segment

Load data segment register DS


7213H 8E D8 MOV DS, AX
with the value in AX

7215H 8B 3E 00 00 MOV DI, Load DI with base address 2000H

PROBLEM SET-1 6
baseadd

Store the value 1 at memory


7219H C6 05 01 MOV [DI], 1
address 2000H

721CH B8 02 00 MOV AX, 2 Load the value 2 into AX

721FH BB 02 00 MOV BX, 2 Load the value 2 into BX

Load the value 8 into CX (loop


7222H B9 08 00 MOV CX, 8
counter)

Multiply AX by the value at


7225H F6 25 MUL [DI]
memory location 2000H

Increment DI by 2 to point to the


7227H 83 C7 02 ADD DI, 2
next memory location

Store the result of the multiplication


722AH 89 05 MOV [DI], AX
at the new DI address

722CH 43 INC BX Increment BX by 1

722DH 8B C3 MOV AX, BX Move the value of BX into AX

Decrement CX and jump to lop if


722FH E2 F4 LOOP lop
CX != 0

7231H B4 4C MOV AH, 4Ch Prepare for program termination

7233H CD 21 INT 21h Interrupt to return control to DOS

RESULTS :

Register Address Hexadecimal Value Decimal Value

0720:2000 01 001

0720:2001 00 000

0720:2002 02 002

0720:2003 00 000

0720:2004 06 006

0720:2005 00 000

0720:2006 18 024

0720:2007 00 000

PROBLEM SET-1 7
0720:2008 78 120

0720:2009 00 000

0720:200A D0 208

0720:200B 02 002

0720:200C B0 176

0720:200D 05 005

0720:200E 80 128

0720:200F 05 005

0720:2010 80 128

0720:2011 04 004

Problem No. 4 :
Consider the following equation from Classical Mechanics, referred to as
the Second-equation of Motion, which is used to calculate the displacement
(s) of an object:
s = u.t + (1/2) at2
where, u is the initial velocity of the object, t is time taken and a is the
acceleration. Write a program in EMU-8086 emulator to receive inputs
from the user for the parameters, namely: Initial Velocity, Time and
Acceleration. Use the 8086 microprocessor to help you compute the
Displacement (s) value, based on the user inputs. Display the computed
Displacement value in the output terminal of the EMU-8086 emulator.

PROPOSED SOLUTION :

PROBLEM SET-1 8
SOLUTION :

Address Opcode Mnemonic Comment

Load the data segment


07210h B8 0000 mov ax, @data
address into AX.

Set up DS register with data


07212h 8E D8 mov ds, ax
segment from AX.

Load the base address


07214h BF 2000 mov di, baseadd
(2000h) into DI register.
print 'Value of
Print prompt for initial
07217h B4 09 initial velocity is
:' velocity.

Prepare for character input


07219h B4 01 mov ah, 1h
(Function 1h in AH).

Interrupt 21h to read input


0721Bh CD 21 int 21h
character for initial velocity.

PROBLEM SET-1 9
Convert ASCII to numeric by
0721Dh 2C 30 sub al, 48
subtracting 48.

Store the initial velocity ( u )


0721Fh 88 C3 mov bl, al
in BL.

Load carriage return (13) in


07221h BA 000D mov dx, 13
DX.

Prepare for character output


07224h B4 02 mov ah, 2h
(Function 2h in AH).

Interrupt 21h to output


07226h CD 21 int 21h
carriage return.

07228h BA 000A mov dx, 10 Load line feed (10) in DX.

Prepare for character output


0722Bh B4 02 mov ah, 2h
(Function 2h in AH).

Interrupt 21h to output line


0722Dh CD 21 int 21h
feed.
print 'Value of time
0722Fh B4 09 is :' Print prompt for time input.

Prepare for character input


07231h B4 01 mov ah, 1h
(Function 1h in AH).

Interrupt 21h to read input


07233h CD 21 int 21h
character for time.

Convert ASCII to numeric by


07235h 2C 30 sub al, 48
subtracting 48.

07237h 88 C7 mov bh, al Store time ( t ) in BH.

Load carriage return (13) in


07239h BA 000D mov dx, 13
DX.

Prepare for character output


0723Ch B4 02 mov ah, 2h
(Function 2h in AH).

Interrupt 21h to output


0723Eh CD 21 int 21h
carriage return.

07240h BA 000A mov dx, 10 Load line feed (10) in DX.

Prepare for character output


07243h B4 02 mov ah, 2h
(Function 2h in AH).

PROBLEM SET-1 10
Interrupt 21h to output line
07245h CD 21 int 21h
feed.
print 'Value of Print prompt for acceleration
07247h B4 09 acceleration is :' input.

Prepare for character input


07249h B4 01 mov ah, 1h
(Function 1h in AH).

Interrupt 21h to read input


0724Bh CD 21 int 21h
character for acceleration.

Convert ASCII to numeric by


0724Dh 2C 30 sub al, 48
subtracting 48.

0724Fh 88 C1 mov cl, al Store acceleration ( a ) in CL.

Load carriage return (13) in


07251h BA 000D mov dx, 13
DX.

Prepare for character output


07254h B4 02 mov ah, 2h
(Function 2h in AH).

Interrupt 21h to output


07256h CD 21 int 21h
carriage return.

07258h BA 000A mov dx, 10 Load line feed (10) in DX.

Prepare for character output


0725Bh B4 02 mov ah, 2h
(Function 2h in AH).

Interrupt 21h to output line


0725Dh CD 21 int 21h
feed.
print 'Value of Print prompt before
0725Fh B4 09 displacement is :' displacement output.

Move initial velocity ( u )


07261h 88 D8 mov al, bl
from BL to AL.

Multiply u (BL) by t (BH)


07263h F6 E3 mul bh
— result stored in AX.

07265h 88 E9 mov ch, al Store the result ut in CH.

Move time ( t ) from BH to


07267h 88 D8 mov al, bh
AL.

Multiply t (BH) by a (CL)


07269h F6 E1 mul cl
— result stored in AX.

PROBLEM SET-1 11
Multiply t again to get t^2
0726Bh F6 E3 mul bh
(AX).

Load divisor (2) into DL for


0726Dh B2 02 mov dl, 2
division.

Divide result of a * t^2 by


0726Fh F6 F2 div dl
2 for (1/2)at^2 .

Add ut (in CH) and


07271h 00 C4 add al, ch (1/2)at^2 (in AL) for total
displacement.

Move the displacement result


07273h 88 C2 mov dl, al
to DL for output.

Convert the result to ASCII by


07275h 04 30 add dl, 48
adding 48.

Prepare for character output


07277h B4 02 mov ah, 02h
(Function 2h in AH).

Output the displacement


07279h CD 21 int 21h
result.

Prepare for program


0727Bh B4 4C mov ah, 4Ch termination (Function 4Ch in
AH).

Interrupt 21h to terminate the


0727Dh CD 21 int 21h
program.

RESULTS :

Register Address Hexadecimal Value Decimal Value Comments

input value of
BL 1H 1
initial velocity

input value of
BH 2H 2
time

input value of
CL 2H 2
acceleration

calculated
CH 2H 2
value of u.t

PROBLEM SET-1 12
54(54 in ASCII = 6 in answer(in
DL 36H
decimal) ASCII)

Problem No. 5 :

The following table indicates the average temperature recorded at Varanasi (in
degree celsius) during various days of a year:

Jan-23 200 C

Jan-31 240 C

Feb-21 320 C

Feb-28 340 C

Mar-23 380 C

May-24 420 C

May-31 450 C

Jul-24 360 C

Aug-24 330 C

Dec-13 230 C

Write a Assembly level program for an 8086-CPU, where the temperature


numbers for various days are fed to consecutive memory locations using
simple Immediate-addressing-mode based instructions. Develop your
program so as to let the 8086-CPU find out the maximum temperature
value from the given data.

PROPOSED SOLUTION :

PROBLEM SET-1 13
SOLUTION :

Address Opcode Mnemonic Comment

Load the data segment address into


0721:0000 B8 20 07 mov ax, @data
AX .

Load AX into DS to set data


0721:0003 8E D8 mov ds, ax
segment.
mov di,
0721:0005 8B 3E 02 00 baseadd
Load 2000h into DI .

0721:0009 C7 05 14 00 mov [di], 20 Store 20 at address in DI

0721:000C C7 05 18 00 mov [di], 24 Store 24 at next address

0721:000D 47 inc di Store 24 at next address

0721:0010 C7 05 20 00 mov [di], 32 Store 32 at next address

0721:0011 47 inc di Increment DI

PROBLEM SET-1 14
0721:0014 C7 05 22 00 mov [di], 34 Store 34 at next address

0721:0015 47 inc di Increment DI

0721:0018 C7 05 26 00 mov [di], 38 Store 38 at next address

0721:0019 47 inc di Increment DI

0721:001C C7 05 2A 00 mov [di], 42 Store 42 at next address

0721:001D 47 inc di Increment DI

0721:0020 C7 05 2D 00 mov [di], 45 Store 45 at next address

0721:0021 47 inc di Increment DI

0721:0024 C7 05 24 00 mov [di], 36 Store 36 at next address

0721:0025 47 inc di Increment DI

0721:0028 C7 05 21 00 mov [di], 33 Store 33 at next address

0721:0029 47 inc di Increment DI

0721:002C C7 05 17 00 mov [di], 23 Store 23 at next address

0721:002D B0 30 mov al, 48 Load 48 into AL

0721:0030 83 EF 09 sub di, 9 Subtract 9 from DI

0721:0032 9 0A 00 mov cx, 10 Set counter to 10

0721:0035 8A 05 mov al, [di] Load value at [DI] into AL

0721:0038 47 inc di Increment DI

0721:003A 3A 05 cmp al, [di] Compare AL with value at [DI]

0721:003B 77 F9 ja cop Jump to ' cop ' if AL > [DI]

0721:003D E2 F9 loop lop Decrement CX and loop if not zero

0721:003F B4 4C mov ah, 4Ch Prepare to exit program

0721:00413 CD 21 int 21h Call DOS interrupt to terminate

RESULTS :

Register Address Hexadecimal Value Decimal Value

AL 2D 45

PROBLEM SET-1 15

You might also like