Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 13

MPI Tutorial 5

13.02.2024
14.02.2024
15.02.2024
19.02.2024
Problem 1

Write an ALP that transfers a block of 100 bytes of data. The


source and destination memory blocks start at 3000 H and
4000 H memory locations respectively. The data segment
register value is DSADDR.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution

MOV AX, DSADDR; Move initial address of DS register into AX.


MOV DS, AX; DS loaded with AX.
MOV SI, 3000H; Source address put into SI.
MOV DI, 4000 H; Destination address put into DI.
MOV CX, 64 H; Count value for number of bytes put into CX.
L1: MOV AH, [SI]; Source byte moved into AH.
MOV [DI], AH; AH byte moved into destination address.
INC SI; Increment source address.
INC DI; Increment destination address.
DEC CX; Decrement CX count.
JNZ L1; Jump to L1 until CX = 0.
HLT

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Problem 2

Write an ALP to find the biggest among 10 bytes stored in


memory.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution

.MODEL SMALL
.DATA

NUM DB 23H,82H,0H,09H,45H,72H,52H,81H,75H,37H ;take any 10 numbers


BIGGEST DB ? ;variable to store biggest number

.CODE
.STARTUP
LEA BX, NUM ;BX to point the array
MOV CL,0AH ;length of array
MOV AL,0 ;AL=0

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution…

L1: CMP AL,[BX] ;compare AL with each number


JAE AGAIN ;jump if AL>=the number
MOV AL,[BX] ;replace in AL if the number>AL

AGAIN: INC BX
DEC CL
JNZ L1
MOV BIGGEST,AL ;store the biggest value from AL to memory
.EXIT
END

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Problem 3

Write an ALP to add two double-words.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution
.MODEL SMALL
.DATA
LONGNUM1 DD 0F8FCE768H ;first double word data
LONGNUM2 DD 0C6EF2109H ;second double word data
SUM DD 0 ;sum
SUMC DB 0 ;if carry generated at 9th digit

.CODE
.STARTUP
LEA SI,LONGNUM1 ;SI as pointer to first operand
LEA DI,LONGNUM2 ;DI as pointer to second operand
LEA BX,SUM ;BX as pointer to sum
CLC ;clear carry
MOV CX,2 ;counter for number of words

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution…
L1: MOV AX,[SI] ;load word to AX from first number
ADC AX,[DI] ;addition of AX,word from second number and CF
MOV [BX],AX ;send sum to SUM memory location
INC SI ;increment SI twice
INC SI
INC DI ;increment DI twice
INC DI
INC BX ;increment BX twice
INC BX
LOOP L1 ;repeat for second word

MOV DL,0 ;clear DL register


ADC DL,0 ;DL=0+0+CF
MOV SUMC,DL ;send carry to SUMC location
.EXIT
ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION
Problem 4

Store two unsigned numbers (both are words) in location


WORD1 and WORD2. Write and ALP to compare the two
numbers and display a message stating which one is
bigger.

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution
.MODEL SMALL
.DATA
WORD1 DW 0ABCDH ;store the first number
WORD2 DW 0DCBAH ;store the second number
MSG1 DB "WORD1 IS BIGGER$" ;display if first word is greater
MSG2 DB "WORD2 IS BIGGER$" ;display if second word is greater

.CODE
.STARTUP
MOV AX,WORD1 ;load WORD1 to AX
CMP AX,WORD2 ;compare with WORD2
JB L1 ;jump to L1 if AX<WORD2
LEA DX,MSG1 ;point DX to MSG1
JMP DISP

L1: LEA DX,MSG2 ;point DX to MSG2


DISP: MOV AH,09 ;AH=09 for string display
INT 21H ;DOS function INT 21h is called
.EXIT
END

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Problem 5

Find the values in the destination after executing each line


of this ALP.
STC
MOV AX,5485H
RCR AL,1
MOV CL,03
RCL AX,CL
MOV CL,05
ROR AX,CL
ROL AX,1

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION


Solution
STC ;CF = 1
MOV AX,5485H ;AX=0101 0100 1000 0101
RCR AL,1 ;rotate through carry right 1 time, AL=1100 0010, CF=1
;generating from LSB of 85H in AL
;now AX = 0101 0100 1100 0010
MOV CL,03 ;CL=03, a counter for rotation
RCL AX,CL ;rotate through carry left 3 times, CF=1 before operation
;AX = 1010 0110 0001 0101, CF = 0 after operation
MOV CL,05 ;CL=05, a counter for rotation
ROR AX,CL ;rotate right 5 times, AX=1010 1101 0011 0000, CF =1
ROL AX,1 ;rotate left 1 time, AX = 0101 1010 0110 0001, CF =1

ELECTRICAL ELECTRONICS COMMUNICATION INSTRUMENTATION

You might also like