Você está na página 1de 7

BSCE - 6th Semester Assignment # 1 (Solution) Spring 2017

EC-331 Microprocessor and Interfacing Techniques


Assignment # 1 (Solution)

Q - 1 Consider the following assembly program written in 8086 emulator which


add two byte numbers (DATA1 AND DATA2) and store the result in SUM
located at offset 0010H.

.MODEL SMALL
.STACK 64

.DATA
DATA1 DB 52H
DATA2 DB 29H
SUM DB ?

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
MOV AX, 0000H
MOV AL, DATA1
MOV BL, DATA2

ADD AL, BL
MOV SUM, AL

MOV AX, 4C00H


INT 21H

MAIN ENDP
END MAIN

Identify the values of all registers for each instruction as shown in Table 1.

Solution:
Table 1. 8086 Registers Values
Instr.
Initial 1 2 3 4 5 6 7 8 Halt
Register

AX 0000 0714 0714 0000 0052 0052 007B 007B 4C00 4C00

BX 0000 0000 0000 0000 0000 0029 0029 0029 0029 0029

DS 0700 0700 0714 0714 0714 0714 0714 0714 0714 0714

CS 0715 0715 0715 0715 0715 0715 0715 0715 0715 0715

IP 0000 0003 0005 0008 000B 000F 0011 0014 0017 0200

Dept. of CS&E HITEC University Taxila Page 1 of 7


BSCE - 6th Semester Assignment # 1 (Solution) Spring 2017

Q - 2 In the real mode addressing, Identify the starting and ending memory
addresses of segment located by the following segment register values:-
a) DS = 1000H
b) SS = 2345H
c) CS = E000H
d) ES = AB0FH

Solution:

In real mode addressing, each segment is of 64KB having addresses 0000H — FFFFH.

General formula for identifying starting and ending memory addresses of segment is:-

Starting address = Segment x 10H + 0000H


Ending address = Segment x 10H + FFFFH

So,
Segment Starting Address Ending Address

DS = 1000H 1000H x 10H + 0000H = 10000H 1000H x 10H + FFFFH = 1FFFFH

SS = 2345H 2345H x 10H + 0000H = 23450H 2345H x 10H + FFFFH = 3344FH

CS = E000H E000H x 10H + 0000H = E0000H E000H x 10H + FFFFH = EFFFFH

ES = AB0FH AB0FH x 10H + 0000H = AB0F0H AB0FH x 10H + FFFFH = BB0EFH

Q - 3 Assume that DS = 4500, SS = 2000, BX = F000, SI = 3000 and AX = 2512.


Show the exact physical memory location where AX is stored in each of the
following. All values are in hex.
MOV [BX+20], AX
MOV [BX+SI], AX

Solution:

In 8086 microprocessor, the registers BX and SI contains the offset addresses. The BX and SI
offset addresses combines with DS segment register to make the physical address of memory. So,

Physical address = DS:[ BX + Immediate data ] or DS:[ BX + SI ]

For the instruction, MOV [BX+20], AX


The physical address will be DS:[BX+20], which means
DS:[BX+20] = 4500:[F000 + 20] = 4500:[F020] = 4500 x 10 + F020 = 54020H

For the instruction, MOV [BX+SI], AX


The physical address will be DS:[BX+SI], which means
DS:[BX+SI] = 4500:[F000 + 3000] = 4500:[2000] = 4500 x 10 + 2000 = 47000H

Dept. of CS&E HITEC University Taxila Page 2 of 7


BSCE - 6th Semester Assignment # 1 (Solution) Spring 2017

Q - 4 Develop a short sequence of instructions that adds two thirty two bit numbers
(FE432211H and D1234EF1H) with the sum appearing in BX-AX.

Solution: Hint:

.MODEL SMALL CF
.STACK 64 BX AX
+ DX CX
.DATA ; Start of Data Segment —————
DATA1 DW 2211H ; Define word BX AX
DATA2 DW 0FE43H
DATA3 DW 4EF1H
DATA4 DW 0D123H

.CODE ; Start of Code Segment


MAIN PROC
MOV AX, @DATA ; Initialise DS
MOV DS, AX
MOV AX, 0000H ; Initialise AX = 0H
MOV BX, 0000H ; Initialise BX = 0H

MOV AX, DATA1 ; AX = 2211H


MOV CX, DATA3 ; CX = 4EF1H
ADD AX, CX ; AX = AX + CX, may or may not generate CF

MOV BX, DATA2 ; BX = FE43H


MOV DX, DAAT4 ; DX = D123H
ADC BX, DX ; BX = BX + DX + CF

MOV AX, 4C00H


INT 21H

MAIN ENDP
END MAIN

Q - 5 What is wrong with the following instructions:


a) ADD AL, AX
b) ADC CS, DS
c) INC [BX]
d) ADD [AX], [BX]
e) INC SS

Solution:
a) ADD AL, AX — Source and destination registers should be of same size.
b) ADC CS, DS — Arithmetic operations between segment registers are not allowed.
c) INC [BX] — Not clear, if data increment at location [BX] is of BYTE size or WORD size. It is
required to mention BYTE PTR [BX] for BYTE increment and WORD PTR [BX] for WORD
increment.
d) ADD [AX], [BX] — Arithmetic operations between memory to memory are not allowed.
e) INC SS — Increment operation on segment registers are not allowed.

Dept. of CS&E HITEC University Taxila Page 3 of 7


BSCE - 6th Semester Assignment # 1 (Solution) Spring 2017

Q - 6 Suppose, present content of flag register is 058FH. Find the content of AX and
Flag register after executing the following instructions:
a) MOV AX, 1001H
b) MOV DX, 20FFH
c) ADD AX, DX

Solution:

In arithmetic and logical operations, only CF (0th bit), PF (2nd bit), AF (4th bit), ZF (6th bit), SF (7th
bit) effected.
So, Flag register 058FH contains the following values,
7 6 5 4 3 2 1 0

SF ZF AF PF CF

1 0 0 0 1 1 1 1

After executing MOV AX, 1001H — AX register will have 1001H.


After executing MOV AX, 20FFH — DX register will have 20FFH.
After executing ADD AX, DX — AX register will have 1001H + 20FFH = 3100H. If the instruction
were ADC AX, DX, then previous carry would be added.

The final content of AX = 3100H, and flag register would be


7 6 5 4 3 2 1 0

SF ZF AF PF CF

0 0 x 1 x 1 0 0

Parity Flag — In x86 processors, the parity flag reflects the parity only of the least significant byte
of the result, and is set if the number of set bits of ones is even.

Auxiliary Flag — It indicates when an arithmetic carry or borrow has been generated out of the
four least significant bits, or lower nibble. It is primarily used to support binary-coded decimal
(BCD) arithmetic.

Q - 7 Develop a short sequence of instructions that adds AL, BL, CL, DL and AH. Save
the sum in the DH register.

Solution:

ADD BL, AL
ADD CL, BL
ADD DL, CL
ADD AH, DL
MOV DH, AH

Dept. of CS&E HITEC University Taxila Page 4 of 7


BSCE - 6th Semester Assignment # 1 (Solution) Spring 2017

Q - 8 Write a sequence of assembly instructions that divide the number in BL by the


number in CL and then multiplies the result by 2. The final answer must be a 16-
bit number stored in the DX register.

Solution:

.MODEL SMALL
.STACK 64

.DATA
DATA1 DB 0EH ; DATA1 variable for first value as dividend
DATA2 DB 7H ; DATA2 variable for second value as divisor
QUOT DB ? ; QOUT variable for Quotient
REM DB ? ; REM variable for Reminder

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV BL, DATA1 ; Initialise BL with DATA1


MOV AL, BL ; For Division, the dividend should be in AX
MOV AH, 0 ; As data is of 1-Byte, make AH=0
MOV CL, DATA2 ; Initialise CL with DATA2
DIV CL ; DIV instruction — AX = AL / CL

MOV QUOT, AL ; Transfer quotient (present in AL) to QOUT


MOV REM, AH ; Transfer reminder (present in AH) to REM

MOV BL, 2 ; To multiply the result with 2, transfer data to register BL


MUL BL ; MUL instruction — AX = AL x BL

MOV DX, AX ; Transfer result to DX register

MOV AX, 4C00H


INT 21H

MAIN ENDP
END MAIN

Dept. of CS&E HITEC University Taxila Page 5 of 7


BSCE - 6th Semester Assignment # 1 (Solution) Spring 2017

Q - 9 Write an assembly program that finds the largest number among the following
numbers (stored in data segment) 25H, 12H, 15H, 1FH, 2BH.
Solution:

.MODEL SMALL
.STACK 64

.DATA
DATA1 DB 25H,12H,15H,1FH,2BH ; Data array initialisation in data segment

.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX

MOV CX, 5H ; Set counter to size of array


MOV BX, OFFSET DATA1 ; Transfer offset of DATA1
MOV AL, 0H ; AL used to store highest number
; Initialise AL = 0

AGAIN: CMP AL, [BX] ; Compare AL and [BX] — AL - [BX]


JA NEXT ; Jump to NEXT, if AL is higher than [BX]
MOV AL, [BX] ; Otherwise, AL = [BX]

NEXT: INC BX ; Increment BX to access the next number


LOOP AGAIN ; Move to AGAIN till CX=0

MOV DL, AL ; Transfer the highest number stored in AL to DL

MOV AX, 4C00H


INT 21H

MAIN ENDP
END MAIN

Dept. of CS&E HITEC University Taxila Page 6 of 7


BSCE - 6th Semester Assignment # 1 (Solution) Spring 2017

Q - 10 Write a assembly program that transfers 5 bytes of data from data segment with
offset of 0010H to memory location with an offset of 0210H.

Solution:

.MODEL SMALL
.STACK 64

.DATA
TEMP DB 16 DUP(?) ; Initialise 10 dummy bytes to make offset 0010H
ARRAY DB 11H, 22H, 33H, 44H, 55H ; Data initialisation

.CODE
MAIN PROC
MOV AX, OFFSET DATA
MOV DS, AX

MOV BX, 0210H ; Set destination offset (as destination)


MOV SI, OFFSET ARRAY ; Get array starting address (as source)

MOV CX, 05H ; Set the counter to transfer 5 bytes


MOV AL, 0H ; AL used to store array 1 byte data
; Initialise AL = 0

AGAIN: MOV AL, [SI] ; Transfer 1 byte of array to AL


MOV [BX], AL ; Move AL to offset BX

INC SI ; Increment source address


INC BX ; Increment destination address
LOOP AGAIN

MOV AX, 4C00H


INT 21H

MAIN ENDP
END MAIN

Dept. of CS&E HITEC University Taxila Page 7 of 7

Você também pode gostar