0% found this document useful (0 votes)
8 views

EC373 Assignment 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

EC373 Assignment 1

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

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.

Problem No. 1 1
Problem No. 1 2
Assembly Language Code and Description
Address Opcode Mnemonic Comments

MOV AX,
7210H B8 20 07 Initialise data segment address in AX
@DATA

Move AX (data segment address) into


7213H 8E D8 MOV DS, AX
DS

Load the effective address of result


7215H BF 04 00 LEA DI, result
into DI

7218H A1 00 00 MOV AX, num1 Load num1 into AX

721BH 8B 1E 02 00 MOV BX, num2 Load num2 into BX

Multiply AX by BX , result is stored


721FH F7 E3 MUL BX
in AX

Store the multiplication result from


7221H 89 05 MOV [DI], AX
AX into memory (result)

7223H A1 00 00 MOV AX, num1 Load num1 again into AX

7226H 33 D2 XOR DX, DX Clear DX (necessary for division)

7228H F7 F3 DIV BX Divide AX by BX , quotient in AX

Store the division result (quotient) into


722AH 89 45 01 MOV [DI+1], AX
memory (next address)

Prepare for DOS interrupt to terminate


722DH B4 4C MOV AH, 4CH
program

Terminate the program using DOS


722FH CD 21 INT 21H
interrupt

Output

Problem No. 1 3
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,……..
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.

Problem No. 1 4
Problem No. 1 5
Assembly Language Code and Description
Address Opcode Mnemonic Comments

MOV AX,
7250H B8 20 07 Initialize data segment address in AX
@DATA

Move AX (data segment address) into


7253H 8E D8 MOV DS, AX
DS

Load the effective address of fib into


7255H BF 00 00 LEA DI, fib
DI

Store the first Fibonacci number (0)


7258H C6 05 00 MOV [DI], 0
into the first fib location

Store the second Fibonacci number (1)


725BH C6 45 02 01 MOV [DI+2], 1
into the second fib location

Load 18 into CX (number of iterations


725FH B9 12 00 MOV CX, 18
for the Fibonacci loop)

Move DI to the next Fibonacci


7262H 83 C7 04 ADD DI, 4
number location

Problem No. 1 6
Address Opcode Mnemonic Comments

Initialize AX with 0 (for the first


7265H B8 00 00 MOV AX, 0
Fibonacci value)

Initialize BX with 1 (for the second


7268H BB 01 00 MOV BX, 1
Fibonacci value)

726BH 8B D3 MOV DX, BX Copy BX (current Fibonacci) to DX

Add AX (previous Fibonacci) to DX


726DH 13 D0 ADC DX, AX
(current Fibonacci)

Store the new Fibonacci value in


726FH 89 15 MOV [DI], DX
memory

7271H 83 C7 02 ADD DI, 2 Move DI to the next memory location

Move BX (current Fibonacci) to AX


7274H 8B C3 MOV AX, BX
(previous Fibonacci)

Move DX (new Fibonacci) to BX


7276H 8B DA MOV BX, DX
(current Fibonacci)

Decrement CX and loop back to


7278H E2 F1 LOOP loop_start
loop_start

Prepare for DOS interrupt to terminate


727AH B4 4C MOV AH, 4CH
the program

Terminate the program using DOS


727CH CD 21 INT 21H
interrupt

Output

Problem No. 1 7
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.

Problem No. 1 8
Problem No. 1 9
Assembly Language Code and Description
Address Opcode Mnemonic Comments

MOV AX,
7220H B8 20 07 Initialize data segment address in AX
@DATA

Move AX (data segment address) into


7223H 8E D8 MOV DS, AX
DS

Load the effective address of


7225H BF 00 00 LEA DI, factorial
factorial into DI

Store the initial factorial value (1) into


7228H C6 05 01 MOV [DI], 1
the first factorial location

Load 7 into CX (number of iterations


722BH B9 07 00 MOV CX, 7 for obtaining the next 7 factorial
values)

Move DI to the next memory location


722EH 83 C7 02 ADD DI, 2
for storing the next factorial

Initialise AX with 1 (initial factorial


7231H B8 01 00 MOV AX, 1
value)

Initialise BX with 2 (for the second


7234H BB 02 00 MOV BX, 2
second value)

7237H F7 E3 MUL BX Multiply AX by BX (AX = AX * BX)

Store the current factorial result in


7239H 89 05 MOV [DI], AX
memory

723BH 83 C7 02 ADD DI, 2 Move DI to the next memory location

Problem No. 1 10
Address Opcode Mnemonic Comments

Increment BX to use the next


723EH 83 C3 01 ADD BX, 1
multiplier in the next iteration

Decrement CX and repeat until all


7241H E2 F4 LOOP loop_start
factorials are calculated

Prepare for DOS interrupt to terminate


7243H B4 4C MOV AH, 4CH
the program

Terminate the program using DOS


7245H CD 21 INT 21H
interrupt

Output

Problem No. 1 11
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.

Problem No. 1 12
Problem No. 1 13
Problem No. 1 14
Problem No. 1 15
Problem No. 1 16
Problem No. 1 17
Problem No. 1 18
Assembly Language Code and Description
Address Opcode Mnemonic Comments

Jump to read_u label to read u from


0100 EB 0A JMP read_u
user input

Set divisor for converting ASCII to


0102 B2 0A MOV DL, 10
decimal ( DL = 10 )

Clear BL (used to store intermediate


0104 B3 00 MOV BL, 0
values for u )

0106 B4 01 MOV AH, 01h Prepare to read character from input

0108 CD 21 INT 21h Read a character from user input

Compare input with ENTER key


010A 3C 13 CMP AL, 13
( 13h )

Move value of BL (input for u )


010C 88 DD MOV BH, BL
to BH

010E 74 08 JE read_t Jump to read_t if ENTER is pressed

0110 30 C0 XOR AL, AL Clear AL

0112 2C 30 SUB AL, 48 Convert ASCII input to number

0114 88 C1 MOV CL, AL Move result to CL (temporary storage)

0116 88 D8 MOV AL, BL Move BL to AL for multiplication

0118 F6 E2 MUL DL Multiply BL by 10

011A 00 C8 ADD AL, CL Add the converted number to AL

011C 88 C3 MOV BL, AL Store the result back in BL

Problem No. 1 19
Address Opcode Mnemonic Comments

011E EB E6 JMP scanNum_u Jump back to read the next character

Set divisor for converting ASCII to


0120 B2 0A MOV DL, 10
decimal (for t )

Clear BL (used to store intermediate


0122 B3 00 MOV BL, 0
values for t )

0124 B4 01 MOV AH, 01h Prepare to read character for t

0126 CD 21 INT 21h Read a character from user input

Compare input with ENTER key


0128 3C 13 CMP AL, 13
( 13h )

Move value of CL (input for t )


012A 88 CD MOV CH, CL
to CH

012C 74 08 JE read_a Jump to read_a if ENTER is pressed

012E 30 C0 XOR AL, AL Clear AL

0130 2C 30 SUB AL, 48 Convert ASCII input to number

0132 88 C1 MOV CL, AL Move result to CL

0134 88 D8 MOV AL, BL Move BL to AL for multiplication

0136 F6 E2 MUL DL Multiply BL by 10

0138 00 C8 ADD AL, CL Add the converted number to AL

013A 88 C3 MOV BL, AL Store the result back in BL

013C EB E6 JMP scanNum_t Jump back to read the next character

Set divisor for converting ASCII to


013E B2 0A MOV DL, 10
decimal (for a )

Clear BL (used to store intermediate


0140 B3 00 MOV BL, 0
values for a )

0142 B4 01 MOV AH, 01h Prepare to read character for a

0144 CD 21 INT 21h Read a character from user input

Compare input with ENTER key


0146 3C 13 CMP AL, 13
( 13h )

Move value of BL (input for a )


0148 88 DE MOV DH, BL
to DH

014A 74 08 JE comp Jump to comp if ENTER is pressed

014C 30 C0 XOR AL, AL Clear AL

Problem No. 1 20
Address Opcode Mnemonic Comments

014E 2C 30 SUB AL, 48 Convert ASCII input to number

0150 88 C1 MOV CL, AL Move result to CL

0152 88 D8 MOV AL, BL Move BL to AL for multiplication

0154 F6 E2 MUL DL Multiply BL by 10

0156 00 C8 ADD AL, CL Add the converted number to AL

0158 88 C3 MOV BL, AL Store the result back in BL

015A EB E6 JMP scanNum_a Jump back to read the next character

Set divisor for division by 2 (for 1/2 a


015C B3 02 MOV BL, 2
* t^2 )

015E 88 F8 MOV AL, DH Move a to AL for calculation

0160 F6 E1 MUL CH Multiply a by t (result in AX )

0162 F6 F3 DIV BL Divide result by 2 (for 1/2 a * t^2 )

0164 00 F8 ADD AL, BH Add u to the result

0166 F6 E1 MUL CH Multiply result by t

0168 30 C0 XOR AH, AH Clear AH

016A 31 C9 XOR CX, CX Clear CX

016C 31 D2 XOR DX, DX Clear DX

016E EB 0A JMP label1 Jump to label1 for printing

0170 39 C0 CMP AX, 0 Check if the result is 0

0172 74 06 JE print1 Jump to print1 if result is 0

Set divisor for converting result to


0174 BB 000A MOV BX, 10
ASCII (decimal)

0177 F7 FB DIV BX Divide result by 10

0179 52 PUSH DX Push remainder onto stack

017A 41 INC CX Increment CX

017B 31 D2 XOR DX, DX Clear DX

017D EB F1 JMP label1 Jump to continue conversion

017F 39 C9 CMP CX, 0 Check if any digits remain

0181 74 0A JE exit Jump to exit if no digits remain

0183 5A POP DX Pop digit from stack

0184 80 C2 30 ADD DL, 48 Convert to ASCII character

Problem No. 1 21
Address Opcode Mnemonic Comments

0187 B4 02 MOV AH, 02h Prepare to display character

0189 CD 21 INT 21h Display the character

018B 49 DEC CX Decrement CX

018C EB F5 JMP print1 Jump back to continue printing

018E C3 RET Return from procedure (exit)

Output

Problem No. 1 22
Problem No. 5
The following table indicates the average temperature recorded at Varanasi (in
degree Celsius) during various days of a year. Write an 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.

Problem No. 1 23
Problem No. 1 24
Assembly Language Code and Description
Address Opcode Mnemonic Comments

7100H BF 40 00 MOV DI, 40H Set DI to point at memory address 40h

Problem No. 1 25
Address Opcode Mnemonic Comments

Store the value 20 at memory location


7103H C6 05 14 MOV [DI], 20
40H

Store the value 24 at memory location


7106H C6 45 01 18 MOV 1[DI], 24
41H

Store the value 32 at memory location


710AH C6 45 02 20 MOV 2[DI], 32
42H

Store the value 34 at memory location


710EH C6 45 03 22 MOV 3[DI], 34
43H

Store the value 38 at memory location


7112H C6 45 04 26 MOV 4[DI], 38
44H

Store the value 42 at memory location


7116H C6 45 05 2A MOV 5[DI], 42
45H

Store the value 45 at memory location


711AH C6 45 06 2D MOV 6[DI], 45
46H

Store the value 36 at memory location


711EH C6 45 07 24 MOV 7[DI], 36
47H

Store the value 33 at memory location


7122H C6 45 08 21 MOV 8[DI], 33
48H

Store the value 23 at memory location


7126H C6 45 09 17 MOV 9[DI], 23
49H

712AH B1 00 MOV CL, 0 Initialize the counter CL to 0

712CH B2 14 MOV DL, 20 Set DL to 20 (maximum value)

Load the first value (20) from memory


712EH 8A 1D MOV BL, [DI]
into BL

7130H 8A 2D MOV CH, [DI] Load value at address 40h into CH

7132H 8A 75 01 MOV DH, 1[DI] Load the value at 41h into DH

Compare DH (next value) with CH


7135H 3A F5 CMP DH, CH
(current value)

If next value is greater than or equal,


7137H 73 0F JAE update
jump to update

7139H EB 0 JMP next Else, jump to next iteration

Increment DI to point to next memory


713BH 83 C7 01 ADD DI, 1
location

713EH 80 C1 01 ADD CL, 1 Increment counter CL

Problem No. 1 26
Address Opcode Mnemonic Comments

Compare CL with 10 (limit of


7141H 80 F9 0A CMP CL, 10
iterations)

7144H 74 07 JE exit If CL is 10, exit the loop

Jump back to check the next pair of


7146H EB E8 JMP check
values

Update DL with the current largest


7148H 8A 55 01 MOV DL, 1[DI]
value

714BH EB EE JMP next Jump to next iteration

Move the maximum value found into


714DH 8A C2 MOV AL, DL
AL

714FH C3 RET Return from the program

Output

Problem No. 1 27

You might also like