0% found this document useful (0 votes)
54 views16 pages

Problem Set-2

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)
54 views16 pages

Problem Set-2

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

PROBLEM SET-2

Problem no. 6

Write an assembly language program to perform the following:


1. Store a 8-bit number in the RAM location 1000
2. Check if the stored 8-bit number is an odd number or an even
number
3. If the stored number is odd, then indicate the same by loading
0000 H in CX-register
4. If the stored number is even, then indicate the same by loading
FFFF H in CX-register

Address Opcode Mnemonic Comments

7210H B8 20 07 mov AX, Load data segment


@data address into AX

7213H 8E D8 mov DS, AX Move AX to DS

7215H BE 00 10 mov SI, Store memory address


1000H 1000H in SI

7218H A0 00 00 mov AL, num Move the 8-bit number to


AL register

721BH 88 04 mov [SI], AL Store the number from AL


to memory location
[1000H]
721DH 8A 04 mov AL, [SI] Load the number from
memory 1000H into AL

721FH A8 01 test AL, 01H Perform AND operation to


check the LSB

7221H 75 05 jnz ODD If LSB is 1, it's odd, so


jump to ODD

7223H B9 FF FF mov CX, If even, load FFFFH into


0FFFFH CX register

7226H EB 03 jmp STORE_ Jump to store result


RESULT

7228H B9 00 00 mov CX, If odd, load 0000H into CX


0000H register

722BH 89 0E 01 00 mov result, Store the value of CX in


CX the result variable

722FH B4 4C mov AH, 4CH Terminate the program


using DOS interrupt

7231H CD 21 int 21H Terminate program


Problem no. 7

Write an assembly language program in EMU-8086 to perform 1’s


complement
on the contents of the Flag-register of the 8086-Microprocessor (ie., to
flip all 1s
in Flag register to 0s, and flip all 0s in flag register to 1s).
Perform the above operation as a series of following three steps:
i. Copy the contents of Flag register to two successive memory
locations
in the RAM memory (Hint: Use PUSHF instruction learnt during
the lectures).
ii. Now, perform 1’s complement on these 16-bits present in the two
consecutive memory locations, by using suitable instructions
iii. Finally, copy the 1’s complement value in memory-location back
into
the flag-register. (Hint: Use POPF instruction learnt during the
lectures).

Address Opcode Mnemonic Comments

7210H 9C PUSHF Push the contents of the flag


register onto the stack

7211H 58 POP AX Pop the flags into AX (AX


holds the flag register now

7212H A3 0000 mov flag_mem, AX Move AX (flag register) to


memory

7215H F7 D0 NOT AX Perform 1's complement on


the flags (AX holds the flags
from Step 1)

7217A A3 0000 MOV flag_mem, AX Store the 1's complement


result back into memory
721AH A1 0000 MOV AX, flag_mem Load the 1's complemented
flag value into AX

721DH 50 PUSH AX Push the complemented flags


onto the stack

721EH 9D POPF Pop the complemented flags


back into the flag register

721FH BC 4C MOV AH, 4CH Terminate the program

7221H CD 21 INT 21H DOS interrupt to return


control to operating system
Problem No. 8
Write an assembly-language program to perform the following:
1. Load the memory-address 1000 in Source Index Register
2. Now using this memory base-address in Source Index Register,
store the following given five hex-numbers in memory locations
1000 to 1009 (taking 2 bytes for every given hex-number) :
F3F5 H, FFF2 H, 0104 H, 0842 H, 8468 H
3. Sort the five numbers in the ascending order and store these
sorted numbers in memory locations 2000 to 2009 , taking two
bytes for every sorted hex-number
4. Sort the five numbers in the descending order and store these
sorted numbers in memory locations 3000 to 3009 , taking two
bytes for every sorted hex-number

Address Opcode Mnemonic Comments


Load data segment address into
7210H B8 20 07 mov AX, @data AX
7213H 8E D8 mov DS, AX Move AX to DS
Load memory address 1000H into
7215H BE 00 10 mov SI, 1000H SI (Source Index)
Load the address of numbers into
7218H 8D 3D lea DI, numbers DI
721AH B9 05 00 mov CX, 5 Counter for 5 numbers
721DH A1 mov AX, [DI] Load number into AX
Store number at memory location
721FH A3 mov [SI], AX [SI]
Move to next 2-byte memory
7221H 83 C6 02 add SI, 2 location
7224H 83 C7 02 add DI, 2 Move to next number in the array
7227H E2 F4 loop store_loop Repeat the loop for all 5 numbers
Load the address of the array into
7229H 8D 35 lea SI, numbers SI
Load base address for sorted
722BH BF 00 20 mov DI, 2000H numbers into DI (2000H)
call
722EH E8 00 01 sort_ascending Call the sort_ascending subroutine
Load the address of the array into
7231H 8D 35 lea SI, numbers SI
Load base address for sorted
7234H BF 00 30 mov DI, 3000H numbers into DI (3000H)
call
sort_descendin Call the sort_descending
7237H E8 00 04 g subroutine
DOS interrupt to terminate the
723AH B4 4C mov AH, 4CH program
723CH CD 21 int 21H Terminate program
723EH B9 05 00 mov CX, 5 Outer loop counter for sorting
7241H 8D 3D lea DI, numbers Start of the number array
7244H A1 mov AX, [DI] Load current number into AX
Compare AX with next number in
7246H 3B 46 02 cmp AX, [DI+2] the array
7249H 76 05 jbe no_swap If current number <= next, no swap
724BH 87 46 02 xchg AX, [DI+2] Swap current and next number
Store swapped number back into
724EH A3 mov [DI], AX the array
7250H 83 C7 02 add DI, 2 Move to the next pair of numbers
7253H 4B dec BX Decrement inner loop counter
7254H 83 F3 01 cmp BX, 1 Compare BX to 1
7257H 7F E5 jg sort_inner If BX > 1, continue sorting
7259H 4E dec CX Decrement outer loop counter
725AH 83 F9 01 cmp CX, 1 Compare CX to 1
725DH 7F DD jg sort_outer If CX > 1, continue sorting
725FH 8D 35 lea DI, numbers Start of the number array
Load base address for sorted
7261H BE 00 20 mov SI, 2000H numbers into SI (2000H)
7264H A1 mov AX, [DI] Load number into AX
Store number at memory location
7266H A3 mov [SI], AX 2000H onwards
7268H 83 C6 02 add SI, 2 Move to the next memory location
Move to the next number in the
726BH 83 C7 02 add DI, 2 array
726EH E2 F6 loop store_asc Repeat for all numbers
Outer loop counter for descending
7270H B9 05 00 mov CX, 5 sort
7273H 8D 3D lea DI, numbers Start of the number array
7276H A1 mov AX, [DI] Load current number into AX
7278H 3B 46 02 cmp AX, [DI+2] Compare AX with next number
jae
727BH 73 05 no_swap_desc If current number >= next, no swap
727DH 87 46 02 xchg AX, [DI+2] Swap current and next number
7280H A3 mov [DI], AX Store swapped number back into
the array
7282H 83 C7 02 add DI, 2 Move to the next pair of numbers
7285H 4B dec BX Decrement inner loop counter
7286H 83 F3 01 cmp BX, 1 Compare BX to 1
jg
7289H 7F EB sort_inner_desc If BX > 1, continue sorting
728BH 4E dec CX Decrement outer loop counter
728CH 83 F9 01 cmp CX, 1 Compare CX to 1
jg
728FH 7F E1 sort_outer_desc If CX > 1, continue sorting
7291H 8D 35 lea DI, numbers Start of the number array
Load base address for sorted
7293H BE 00 30 mov SI, 3000H numbers into SI (3000H)
7296H A1 mov AX, [DI] Load number into AX
Store number at memory location
7298H A3 mov [SI], AX 3000H onwards
729AH 83 C6 02 add SI, 2 Move to the next memory location
Move to the next number in the
729DH 83 C7 02 add DI, 2 array
72A0H E2 F6 loop store_desc Repeat for all numbers
Return from the sort_descending
72A2H C3 ret subroutine
Problem No. 9

Write an assembly language program in EMU-8086 emulator, to


increment the values of ten numbers stored in the memory locations
3000 H to 3009 H , by a count of 1. The incremented values of each of
these numbers are to be stored in the respective same memory
locations.

Address Opcode Mnemonic Comments

7200H BE 0030 MOV SI, 3000H Load starting address (3000H)


into SI register

7203H B9 00A0 MOV CX, 10 Set counter to 10 (for 10


numbers)

7206H 8A04 MOV AL, [SI] Load the value from memory
location SI into AL

7208H FEC0 INC AL Increment the value in AL by 1

720AH 8804 MOV [SI], AL Store the incremented value


back into memory at SI

720CH 46 INC SI Move to the next memory


location

720DH E2F7 LOOP Repeat until CX = 0 (all 10


NEXT_NUMBER numbers processed)

720FH B44C MOV AH, 4CH Terminate the program

7211H CD INT 21H DOS interrupt to return control


to operating system
Problem No. 10

Write an assembly-level code for an 8086-Microprocessor to detect


if a given point with coordinates P (x,y) lies on the circle / inside the circle /
outside the circle.
Write the program code so as to store different values accordingly in
the lower-byte of the BX register in 8086-Microprocessor as follows: Store BL
= 11 H (if given point P lies inside the circle) ; Store BL = 00 H (if given point
P lies on the circle) ; Store BL = FF H (if given point P lies outside the circle)
( Hint: For a point outside circle: (x-3)2 + (y-3)2 > r2 ; For a point inside circle:
(x-3)2 + (y-3)2 < r2
)

Show your outputs for at least any three different coordinate points as follows :

- P1 (inside the circle)


- P2 (on the circle)
- P3 (outside the circle).

Address Opcode Mnemonic Comments

7210H A1 0000 MOV AX, x Load x-coordinate into AX

7213H 2D0300 SUB AX, 3 Subtract 3 (AX = x - 3)

7216H F7E8 IMUL AX Compute (x - 3)^2, store


result in AX

7218H 8BC8 MOV CX, AX Save (x - 3)^2 in CX for


later use

721AH A10200 MOV AX, y Load y-coordinate into AX

721DH 2D0300 SUB AX, 3 Subtract 3 (AX = y - 3)

7220H F7E8 IMUL AX Compute (y - 3)^2, store


result in AX
7222H 03C1 ADD AX, CX Add (x - 3)^2 + (y - 3)^2

7224H 8B1E MOV BX, r Load r (radius) into BX

7228H 3BC3 CMP AX, BX Compare the result (x -


3)^2 + (y - 3)^2 with r^2

722AH 7F0A JG OUTSIDE Jump to OUTSIDE if AX >


BX (outside the circle)

722CH 7C04 JL INSIDE Jump to INSIDE if AX < BX


(inside the circle)

722EH B300 MOV BL, 00H BL = 00H for point on the


circle

7230H EB08 JMP DONE Return to done and halt

7232H B311 MOV BL, 11H BL = 11H for point inside


the circle

7234H EB04 JMP DONE Return to done and halt

7236H B3FF MOV BL, 0FFH BL = FFH for point outside


the circle

7238h EB00 JMP DONE Return to done and halt

723AH B44C MOV AH, 4C Terminate program

723CH CD21 INT 21H DOS interrupt to return


control to operating system

You might also like