0% found this document useful (0 votes)
77 views20 pages

Micro

Here are the key differences between macros and procedures in assembly language: Macros: - Macros allow code to be reused without needing to call a subroutine. - Macro code is copied/pasted during assembly where it is invoked. - Macros don't save registers or return an address, they just insert code. Procedures: - Procedures define subroutines that can be called from different parts of a program. - When a procedure is called, the return address is pushed on the stack. - Procedures allow saving/restoring registers across calls using the stack. - Procedures provide modularity and structure by grouping related code. In summary:
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
77 views20 pages

Micro

Here are the key differences between macros and procedures in assembly language: Macros: - Macros allow code to be reused without needing to call a subroutine. - Macro code is copied/pasted during assembly where it is invoked. - Macros don't save registers or return an address, they just insert code. Procedures: - Procedures define subroutines that can be called from different parts of a program. - When a procedure is called, the return address is pushed on the stack. - Procedures allow saving/restoring registers across calls using the stack. - Procedures provide modularity and structure by grouping related code. In summary:
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 20

Write an ALP to arrange numbers in array in descending order

DATA SEGMENT

ARRAY DB 15H,05H,08H,78H,56H

DATA ENDS

CODE SEGMENT

START:ASSUME CS:CODE,DS:DATA

MOV DX,DATA

MOV DS,DX

MOV BL,05H

STEP1: MOV SI,OFFSET ARRAY

MOV CL,04H

STEP: MOV AL,[SI]

CMP AL,[SI+1]

JNC DOWN

XCHG AL,[SI+1]

XCHG AL,[SI]

DOWN:ADD SI,1

LOOP STEP

DEC BL

JNZ STEP1

MOV AH,4CH

INT 21H

CODE ENDS

END START
Demonstrate in detail the program development steps in assembly language programming.

Program Development steps 1. Defining the problem The first step in writing program is to think very
carefully about the problem that you want the program to solve.

2. Algorithm The formula or sequence of operations or task need to perform by your program can
be specified as a step in general English is called algorithm.

3. Flowchart The flowchart is a graphically representation of the program operation or task.

4. Initialization checklist Initialization task is to make the checklist of entire variables, constants, all
the registers, flags and programmable ports.

5. Choosing instructions We should choose those instructions that make program smaller in size and
more importantly efficient in execution.

6. Converting algorithms to assembly language program Every step in the algorithm is converted
into program statement using correct and efficient instructions or group of instructions.
Draw architectural block diagram of 8086 and describe its register organization

Register Organization of 8086

1. AX (Accumulator) – Used to store the result for arithmetic / logical operations

2. BX – Base – used to hold the offset address or data

3. CX – acts as a counter for repeating or looping instructions.

4. DX – holds the high 16 bits of the product in multiply (also handles divide operations)

5. CS – Code Segment – holds base address for all executable instructions in a program

6. SS - Base address of the stack

7. DS – Data Segment – default base address for variables

8. ES – Extra Segment – additional base address for memory variables in extra segment.

9. BP – Base Pointer – contains an assumed offset from the SS register.

10. SP – Stack Pointer – Contains the offset of the top of the stack.

11. SI – Source Index – Used in string movement instructions. The source string is pointed to by the
SI register.

12. DI – Destination Index – acts as the destination for string movement instructions

13. IP – Instruction Pointer – contains the offset of the next instruction to be executed.

14. Flag Register – individual bit positions within register show status of CPU or results of arithmetic
operations.
Write ALP using macro to perform multiplication of two 8 Bit Unsigned number

; Macro For Multiplication

PRODUCT MACRO FIRST,SECOND

MOV AL,FIRST

MOV BL,SECOND

MUL BL

PRODUCT ENDM

DATA SEGMENT

NO1 DB 05H

NO2 DB 04H

MULTIPLE DW ?

DATA ENDS

CODE SEGMENT ASSUME CS: CODE,DS:DATA

START:MOV AX,DATA

MOV DS,AX

PRODUCT NO1,NO2

MOV MULTIPLE, AX

MOV AH,4CH

INT 21H

CODE ENDS

END

Write ALP using procedure to solve equation such as Z= (A+B)*(C+D)

; Procedure For Addition

SUM PROC NEAR

ADD AL,BL

RET

SUM ENDP

DATA SEGMENT

NUM1 DB 10H

NUM2 DB 20H
NUM3 DB 30H

NUM4 DB 40H

RESULT DB?

DATA ENDS

CODE SEGMENT

ASSUME CS: CODE,DS:DATA

START:MOV AX,DATA

MOV DS,AX

MOV AL,NUM1

MOV BL,NUM2

CALL SUM

MOV CL,AL

MOV AL, NUM3

MOV BL,NUM4

CALL SUM

MUL CL

MOV RESULT,AX

MOV AH,4CH

INT 21H

CODE ENDS

END
Write ALP to perform block transfer operation of 10 numbers.

;Assume block of TEN 16 bit no.s

;Data Block Transfer Using String Instruction

CODE SEGMENT

ASSUME CS:CODE,DS:DATA,ES:EXTRA

MOV AX,DATA

MOV DS,AX

MOV AX,EXTRA

MOV ES,AX

MOV CX,000AH

LEA SI,BLOCK1

LEA DI,ES:BLOCK2

CLD REPNZ MOVSW

MOV

AX,4C00H

INT 21H

CODE ENDS

DATA SEGMENT

BLOCK1 DW 1001H,4003H,6005H,2307H,4569H, 6123H,

1865H, 2345H,4000H,8888H

DATA ENDS

EXTRA SEGMENT

BLOCK2 DW ?

EXTRA ENDS END


Write ALP to perform block transfer operation of 10 numbers.

;Assume block of TEN 16 bit no.s

;Data Block Transfer Using String Instruction

CODE SEGMENT

ASSUME CS:CODE,DS:DATA,ES:EXTRA

MOV AX,DATA

MOV DS,AX

MOV AX,EXTRA

MOV ES,AX

MOV CX,000AH

LEA SI,BLOCK1

LEA DI,ES:BLOCK2

CLD REPNZ MOVSW

MOV AX,4C00H

INT 21H

CODE ENDS

DATA SEGMENT

BLOCK1 DW 1001H,4003H,6005H,2307H,4569H, 6123H,

1865H, 2345H,4000H,8888H

DATA ENDS

EXTRA SEGMENT

BLOCK2 DW ?

EXTRA ENDS

END

Write ALP to count ODD and EVEN numbers in an array.

;Count ODD and EVEN No.S In Given ;Array Of 16 Bit No.

;Assume array of 10 no.s

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA


MOV DS,AX

MOV DX,0000H

MOV CX,COUNT

MOV SI, OFFSET ARRAY1

NEXT: MOV AX,[SI]

ROR AX,01H

JC ODD_1

INC DL

JMP COUNT_IT

ODD_1 : INC DH

COUNT_IT: INC SI INC SI

LOOP NEXT

MOV ODD_COUNT,DH

MOV EVENCNT,DL

MOV AH,4CH

INT 21H

CODE ENDS

DATA SEGMENT

ARRAY1 DW F423H, 6523H, B658H, 7612H, 9875H,

2300H, 1559H, 1000H, 4357H, 2981H

COUNT DW 0AH

ODD_COUNT DB ?

EVENCNT DB ?

DATA ENDS

END START
Describe mechanism for generation of physical address in 8086 with suitable example.

As all registers in 8086 are of 16 bit and the physical address will be in 20 bits. For this reason the
above mechanism is helpful.

i.e. Calculate physical Address for the given

CS= 3525H, IP= 2450H

Write an ALP to reverse a string. Also draw flowchart for same.

Program:

DATA SEGMENT

STRB DB 'GOOD MORNING$'

REV DB 0FH DUP(?)

DATA ENDS

CODE SEGMENT

START:ASSUME CS:CODE,DS:DATA

MOV DX,DATA

MOV DS,DX

LEA SI,STRB

MOV CL,0FH

LEA DI,REV

ADD DI,0FH
UP:MOV AL,[SI]

MOV [DI],AL

INC SI

DEC DI

LOOP UP

MOV AH,4CH

INT 21H

CODE ENDS

END START
Define logical and effective address. Describe physical address generation process in 8086. If
DS=345AH and SI=13DCH. Calculate physical address.

A logical address is the address at which an item (memory cell, storage element) appears to reside
from the perspective of an executing application program. A logical address may be different from
the physical address due to the operation of an address translator or mapping function. Effective

Address or Offset Address: The offset for a memory operand is called the operand's effective
address or EA. It is an unassigned 16 bit number that expresses the operand's distance in bytes from
the beginning of the segment in which it resides. In 8086 we have base registers and index registers.

Generation of 20 bit physical address in 8086:-

1. Segment registers carry 16 bit data, which is also known as base address.

2. BIU appends four 0 bits to LSB of the base address. This address becomes 20-bit address.

3. Any base/pointer or index register carries 16 bit offset.

4. Offset address is added into 20-bit base address which finally forms 20 bit physical address of
memory location

DS=345AH and SI=13DCH

Physical adress = DS*10H + SI

= 345AH * 10H + 13DCH

= 345A0+13DC

= 3597CH
Write an ALP to find largest number in array of elements 10H, 24H, 02H, 05H, 17H.

DATA SEGMENT

ARRAY DB 10H,24H,02H,05H,17H

LARGEST DB 00H

DATA ENDS

CODE SEGMENT

START:

ASSUME CS:CODE,DS:DATA MOV DX,DATA

MOV DS,DX

MOV CX,04H

MOV SI ,OFFSET

ARRAY MOV AL,[SI]

UP: INC SI

CMP AL,[SI]

JNC NEXT

MOV AL,[SI]

NEXT: DEC CX

JNZ UP

MOV LARGEST,

AL MOV AX,4C00H

INT 21H

CODE ENDS

END START
Write an ALP to count no.of 0’s in 16 bit number.

DATA SEGMENT

N DB 1237H

Z DB 0

DATA ENDS

CODE SEGMENT

ASSUME DS:DATA, CS:CODE

START:

MOV DX,DATA

MOV DS,DX

MOV AX, N

MOV CL,08

NEXT: ROL AX,01

JC ONE

INC Z

ONE: LOOP NEXT

HLT

CODE ENDS

END START
What is pipelining? How it improves the processing speed.

• In 8086, pipelining is the technique of overlapping instruction fetch and execution mechanism.

• To speed up program execution, the BIU fetches as many as six instruction bytes ahead of time
from memory. The size of instruction prefetching queue in 8086 is 6 bytes.

• While executing one instruction other instruction can be fetched. Thus it avoids the waiting time
for execution unit to receive other instruction.

• BIU stores the fetched instructions in a 6 level deep FIFO . The BIU can be fetching instructions
bytes while the EU is decoding an instruction or executing an instruction which does not require use
of the buses.

• When the EU is ready for its next instruction, it simply reads the instruction from the queue in the
BIU

. • This is much faster than sending out an address to the system memory and waiting for memory to
send back the next instruction byte or bytes

. • This improves overall speed of the processor


Write an assembly language program to solve p= x 2+y2 using Macro.(x and y are 8 bit numbers.

.MODEL SMALL

PROG MACRO a,b

MOV al,a

MUL al

MOV bl,al

MOV al,b

MUL al

ADD al,bl

ENDM

.DATA

x DB 02H

y DB 03H

p DB DUP()

.CODE

START:

MOV ax,data

MOV ds,ax

PROG x, y

MOV p,al

MOV ah,4Ch

Int 21H

END
Explain assembly language program development steps.

1. Defining the problem: The first step in writing program is to think very carefully about the
problem that the program must solve.

2. Algorithm: The formula or sequence of operations to be performed by the program can be


specified as a step in general English is called algorithm.

3. Flowchart: The flowchart is a graphically representation of the program operation or task.

4. Initialization checklist: Initialization task is to make the checklist of entire variables, constants, all
the registers, flags and programmable ports

5. Choosing instructions: Choose those instructions that make program smaller in size and more
importantly efficient in execution. 6. Converting algorithms to assembly language program: Every
step in the algorithm is converted into program statement using correct and efficient instructions or
group of instructions.

Give the difference between intersegment and intrasegment CALL

You might also like