MPMC Assignment-1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

ASSIGNMENT-1

31/08/2020

MICRO PROCESSORS &


MICRO CONTROLLERS

REGISTER NUMBER: 810018104059


NAME:  NIVASPRAVEEN C
1. Give an example for the 8086 instructions: AAA, CWD, JNBE, LAHF, MOVS,
RCL, ROL and SAHF
AAA Instruction:

AAA converts the result of the addition of two valid unpacked BCD digits to a valid 2-
digit BCD number and takes the AL register as its implicit operand. Two operands of the
addition must have its lower 4 bits contain a number in the range from 0- 9.The AAA instruction
then adjust AL so that it contains a correct BCD digit. If the addition produce carry (AF=1), the
AH register is incremented and the carry CF and auxiliary carry AF flags are set to 1. If the
addition did not produce a decimal carry, CF and AF are cleared to 0 and AH is not altered. In
both cases the higher 4 bits of AL are cleared to 0. AAA will adjust the result of the two ASCII
characters that were in the range from 30h (“0”) to 39h(“9”).This is because the lower 4 bits of
those character fall in the range of 0-9.The result of addition is not a ASCII character but it is a
BCD digit.

Example:

MOV AH, 0 ; Clear AH for MSD

MOV AL, 6 ; BCD 6 in AL

ADD AL, 5 ; Add BCD 5 to digit in AL

AAA ; AH=1; AL=1 representing BCD 11.

CWD Instruction:

CWD converts the 16 bit signed value in the AX register into an equivalent 32 bit signed
value in DX: AX register pair by duplicating the sign bit to the left.

The CWD instruction sets all the bits in the DX register to the same sign bit of the AX
register. The effect is to create a 32- bit signed result that has same integer value as the original
16 bit operand.

Example:
Assume AX contains C435h. If the CWD instruction is executed, DX will contain FFFFh
since bit 15 (MSB) of AX was 1. Both the original value of AX (C435h) and resulting value of
DX: AX (FFFFC435h) represents the same signed number.

DX= 00000000 00000000

AX= 11110000 11000011 = -3897 decimal

CWD; Convert signal word in AX to signed double word in DX;AX

Result DX= 11111111 11111111

AX= 11110000 11000011 = -3987 decimal.

LAHF Instruction:

LAHF instruction copies the value of SF, ZF, AF, PF, and CF into bits of 7, 6, 4, 2 and 0
respectively of AH register. This LAHF instruction was provided to make conversion of
assembly language programs written for 8080 and 8085 to 8086 easier.

MOVS/MOVSB/MOVSW Instruction:

Move string byte or string word

Example:

MOVS destination, source

RCL Instruction:

RCL instruction rotates the bits in the operand specified by op1 towards left by the count
specified in op2.The operation is circular, the MSB of operand is rotated into a carry flag and the
bit in the CF is rotated around into the LSB of operand.

RCR op1, op2

Rotate operand around to the left through CF – RCL destination, source.

Example:
CLC ; put 0 in CF

RCL AX, 1 ; save higher-order bit of DX in CF

RCL DX, 1 ; save higher-order bit of DX in CF

ADC AX, 0 ; set lower-order bit if needed.

ROL Instruction:

ROL instruction rotates the bits in the operand specified by op1 towards left by the count
specified in op2. ROL moves each bit in the operand to next higher bit position. The higher order
bit is moved to lower order position. Last bit rotated is copied into carry flag.

ROL op1, op2

Example:

BX= 01011110 11011110

CL= 8 bits to rotate

ROL BH, CL; Rotate BX 8 bits towards left

CF= 0, BX= 11010011 01011100

SAHF Instruction:

SAHF copies the value of bits 7, 6, 4, 2, 0 of the AH register into the SF, ZF, AF, PF, and
CF respectively. This instruction was provided to make easier conversion of assembly language
program written for 8080 and 8085 to 8086.
2. Analyze an 8086 ALP to find the sum of numbers in an array of 10 elements.

DATA SEGMENT

ARR DB 5, 3, 7, 1, 9, 2, 6, 8, 4, 10

LEN DW $ -ARR

SUM DW?

DATA ENDS

CODE SEGMENT

ASSUME DS: DATA CS: CODE

START:

MOV AX, DATA

MOV DS, AX

LEA SI, ARR

MOV AX, 0

MOV CX, LEN

REPEAT:

MOV BL, ARR [SI]

MOV BH,0

ADD AX, BX

INC SI

LOOP REPEAT

MOV SUM, AX

MOV AH, 4CH

INT 21H
CODE ENDS

END SRART

3. Develop a program to transfer 50 bytes from memory location starting from


2000H and 3000H using the string instruction MOVSB.

MOV SI, 2000 ; Initialize SI with 2000

MOV DI, 3000 ; Initialize DI with 3000

MOV AX, 0000 ; Clear AX register

MOV DS, AX ; Store AX value to Data Segment (DS)

MOV EX, AX ; Store AX value to Extra Segment (ES)

MOV CL, [SI] ; Initialize Counter to the block size

MOV CH, 00H ; Clear CH register

INC SI ; Increase SI register

CLD ; Clear the directional flag

REP ; Repeat until CX= 0

MOVSB ; Move the string block

HLT ; Terminate the program


4. Write an 8086 ALP to check the whether the given string is Palindrome or not.

DATA SEGMENT

BLOCK1 DB ‘MALAYALAM’

MSG1 DB “IT IS PALINDROME $”

MSG2 DB “IT IS NOT PALINDROME $”

PAL DB 00H

DATA ENDS

PRINT MACRO MSG

MOV AH, 09H

LEA DX, MSG

INT 21H

INT 3H

ENDM

EXTRA SEGMENT

BLOCK2 DB 9 DUP (?)

EXTRA ENDS
CODE SEGMENT

ASSUME CS: CODE DS: DATA ES: EXTRA

START: MOV AX, DATA

MOV DS, AX

MOV AX, EXTRA

MOV ES, AX

LEA SI, BLOCK1

LEA DI, BLOCK2

MOV CX, 0009H

CLD

REPZ CMPSB

JNZ SKIP

PRINT MSG1

SKIP: PRINT MSG2

CODE ENDS

END START

OUTPUT: MALAYALAM is Palindrome

You might also like