MPMC Manual - Ar17
MPMC Manual - Ar17
LAB MANUAL
INTRODUCTION TO MASM/TASM
ASSEMBLY LANGUAGE PROGRAMMING USING MASM SOFTWARE:
The programs are written using assembly language in editor then compile it. The complier
converts assembly language statements into machine language statements/checks for errors.
Then execute the compiled program.
There are different soft wares developed by different companies for assembly language
programming, they are:
MERITS OF MASM:
→ Path setting
Suppose it display path as Z:\>
Then type MOUNT C C:\ MASM then drive c is mounted as local directory C:\MASM\
DEBUG:
This command utility enables to write and modify simple assembly language programs in an easy
fashion. It provides away to run and test any program in a controlled environment.
We can change any part of the program and immediately execute the program with resemble of it.
We can also run machine language (Object files) directly by using DEBUG.
DEBUG COMMANDS:
INPUT I port
QUIT Q
REGISTER R [register]
UNASSEMBLE U [range]
Initialize DS
AL Data1
BL Data2
AL AL+BL
Data Memory AL
AL Data1
AL AL-BL
Data Memory AL
AL Data1
AX AL*BL
Data Memory AX
AL Data1
AH 00H
AX AX / BL
Data Memory AX
STOP
Exp No:
Date:
DATA SEGMENT
N1 EQU 04H
N2 EQU 06H
RESULT DB 06H DUP (00)
DATA ENDS
CODE SEGMENT
START:
MOV AX, DATA
MOV DS, AX
MOV AL, N1
MOV BL, N2
ADD AL, BL
MOV [RESULT], AL
MOV AL, N1
SUB AL, BL
MOV [RESULT+1], AL
MOV AL, N1
MUL BL
MOV [RESULT+2], AL
MOV [RESULT+3], AH
MOV AL, N1
MOV AH, 00H
DIV BL
MOV [RESULT+4], AL
MOV [RESULT+5], AH
MOV AH, 4CH
INT 21H
CODE ENDS
END START
MANUAL CALCULATIONS:
RESULT:
FLOW CHART:
START
Initialize DS
SI 5000H
AX Data1
BX Data2
AX AX+BX
[SI] AX
AX Data1
AX AX-BX
[SI+2] AX
AX Data1
AX, DX AX*BX
[SI+4] AX
[SI+6] DX
AX Data1
DX 0000H
AX, DX DX AX / BX
[SI+8] AX
[SI+0AH] DX
STOP
Exp No:
Date:
ARITHMETIC OPERATIONS ON 16-BIT DATA
Initialize DS
Initialize Data1, Data2
CX COUNT
BX COUNT-1
AL Data1 [BX]
Data memory AL
BX BX-1
CX CX-1
NO
CX=0
YES
CX COUNT
BX COUNT-1
AL Data1 [BX]
Data memory AL
BX BX-1
CX CX-1
NO
CX=0
YES
STOP
Exp No:
Date:
MULTIBYTE ADDITION AND SUBTRACTION
ABSTRACT: Assembly language program to perform multibyte addition and subtraction
PORT USED: None
REGISTERS USED: AL, BX, CX
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Load CX register with count
Step 4: Load BX register with No. of bytes
Step 5: Copy the contents from the memory location n1 [BX] to AL
Step 6: Perform addition with second number n2 [BX]
Step 7: Store the result to the memory location sum [BX]
Step 8: Decrement BX
Step 9: Decrement CX, if CX not equal to Zero jump to step5
Step 10: Load CX register with count
Step 11: Load BX register with no: of bytes
Step 12: Store the contents from memory location n1 [BX] to AL
Step 13: Perform subtraction with second number n2 [BX]
Step 14: Store the result to the memory location sum [BX]
Step 15: Decrement BX
Step 16: Decrement CX, if CX not equal to Zero jump to step12
Step 17: Stop
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N1 DB 33H, 33H, 33H
N2 DB 11H, 11H, 11H
COUNT EQU 0003H
SUM DB 03H DUP (00)
DIFF DB 03H DUP (00)
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA`
MOV DS, AX
MOV CX, COUNT
MOV BX, 0002H
CLC
BACK: MOV AL, N1 [BX]
ADC AL, N2 [BX]
MOV SUM [BX], AL
DEC BX
Physical Address
Mnemonic
Segment Offset Hex
Label Operands Comments
Address Address Code
LOOP BACK
MOV CX, COUNT
MOV BX, 0002H
CLC
BACK1: MOV AL, N1 [BX]
SBB AL, N2 [BX]
MOV DIFF [BX], AL
DEC BX
LOOP BACK1
MOV AH, 4CH
INT 21H
CODE ENDS
END START
MANUAL CALCULATIONS:
RESULT:
FLOW CHART:
START
Initialize DS
DX, AX 0
CX No. of Numbers
SI Offset Address
AL, BL [SI]
AX AL*BL
SI SI+1
DX AX+DX
CX CX-1
ZF=1
NO
YES
[Memory
[M Location] DX
END
Exp No:
Date:
2. SUM OF SQUARES OF GIVEN N NUMBERS
ABSTRACT: Assembly language program to perform sum of squares of given numbers
PORT USED: None
REGISTERS USED: AX, BL and DX
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Load CX register with count
Step 3: Initialize AX and DX register values to zero
Step 4: Load SI with offset list
Step 5: Copy the contents from memory location SI to AL
Step 6: Copy the contents of AL to BL
Step 7: Perform multiplication between the contents of AL and BL
Step 8: Perform addition between the contents of Ax and DX
Step 9: Increment SI
Step 10: Decrement CX and jump to step 5 if no zero
Start 11: Store the result to the data memory
Step 12: Stop
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DB 02H, 03H, 04H,
RES DW 01H DUP (00)
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA
MOV DS, AX
MOV CX, 0003H
XOR AX, AX
XOR DX, DX
MOV SI, OFFSET LIST
BACK: MOV AL, [SI]
MOV BL,AL
MUL BL
ADD DX, AX
INC SI
LOOP BACK
MOV [RES], DX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
MANUAL CALCULATIONS:
RESULT:
FLOW CHART:
START
Initialize DS
BX ,AX Data
CX (Data-1)
BX BX-1
AX AX*BX
CX CX-1
NO
ZF=1
YES
END
Exp No: Date:
ABSTRACT: Assembly language program to perform addition of n-BCD numbers using 8086
MASM software.s
PORT USED: None
REGISTERS USED: AX, BL and DX
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Load CX register with count
Step 3: Initialize AX and DX register values to zero
Step 4: Load SI with offset list
Step 5: Copy the contents from memory location SI to AL
Step 6: Copy the contents of AL to BL
Step 7: Perform multiplication between the contents of AL and BL
Step 8: Perform addition between the contents of Ax and DX
Step 9: Increment SI
Step 10: Decrement CX and jump to step 5 if no zero
Start 11: Store the result to the data memory
Step 12: Stop
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
PROGRAM:
CODE SEGMENT
START:MOV AX,DATA
MOV DS,AX
XOR BX,BX
XOR AX,AX
MOV CL,NUM[BX]
INC BX
MOV AL,NUM[BX]
BACK: INC BX
ADD AL,NUM[BX]
DAA
JNC AGAIN
INC AH
AGAIN:LOOP BACK
MOV [RESULT],AX
MOV AH,4CH
INT 21H
CODE ENDS
END START
RESULT:
FLOW CHART:
START
Initialize DS
BX ,AX Data
CX (Data-1)
BX BX-1
AX AX*BX
CX CX-1
NO
ZF=1
YES
END
Exp No:
Date:
4. FACTORIAL OF GIVEN NUMBER
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
N DB 02H
FACT DW ?
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA
MOV DS, AX
XOR AX, AX
XOR CX, CX
INC AX
MOV CL, N
CMP CL, O1H
JE RES
BACK: MUL CL
LOOP BACK
RES : MOV [FACT], AX
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
MANUAL CALCULATIONS:
RESULT:
FLOW CHART:
START
Initialize DS
CX Count
DX Count
SI Offset list
CX DX
AL [SI]
SI SI+1
Compare AL, [SI]
CF=1
YES
NO
[SI] AL
SI SI-1
[SI] AL
CX CX-1
NO
CX=0
YES
DX DX-1
NO
DX=0
YES
STOP
Exp No:
Date:
5. SORTING OF ‘N’ NUMBERS
ABSTRACT: Assembly language program to do sorting of numbers in a given series
PORT USED: None
REGISTERS USED: CX, DX, AL, SI
ALGORITHM:
Step 1: Start
Step 2: Initialize data segment
Step 3: Load CX register with count
Step 4: Copy the contents from CX to DX
Step 5: Load SI with offset list
Step 6: Copy the contents from DX to CX
Step 7: Move the contents from memory location SI to AL
Step 8: Increment SI
Step 9: Compare AL contents with [SI]
Step 10: Jump to step15 if carry
Step 11: Exchange the contents of AL with [SI]
Step 12: Decrement SI
Step 13: Move the contents from AL to memory location SI
Step 14: Increment SI
Step 15: Decrement CX and jump to step7 if no zero
Step 16: Decrement DX and jump to step5 if no zero
Step 17: Stop
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DB 56H, 12H, 72H, 32H
COUNT EQU 0003H
DATA ENDS
CODE SEGMENT
ORG 1000H
START:
MOV AX, DATA
MOV DS, AX
MOV CX, COUNT
MOV DX, CX
AGAIN: MOV SI, OFFSET LIST
MOV CX, DX
BACK: MOV AL, [SI]
INC SI
CMP AL, [SI]
JC NEXT
XCHG [SI], AL
DEC SI
Physical Address
Mnemonic
Segment Offset Hex
Label Operands Comments
Address Address Code
MOV [SI], AL
INC SI
NEXT: LOOP BACK
DEC DX
MANUAL CALCULATIONS:
RESULT:
FLOW CHART:
START
AL 13H
AH 00H
Interrupt 10H
AH 00H
Interrupt 10H
YES
ZF=0
NO
BL 0FH
AH 14
Interrupt 10H
STOP
Exp No: Date:
START
AL 13H
AH 00H
Interrupt 10H
AH 00H
Interrupt 10H
YES
ZF=0
NO
BL 0FH
AH 14
Interrupt 10H
STOP
Exp No: Date:
1(b) READING KEYBOARD BUFFERED WITHOUT ECHO
ALGORITHM:
Step1: Start
Step2: Initialize SI with Offset Result.
Step3: Initialize AH with 00h
Step11: Stop.
MANUAL CALCLATIONS:
PROGRAM:
CODE SEGMENT
ORG 1000h
INT 16h
JMP BACK
INT 21h
CODE ENDS
END START
Physical Address
Label Hex Code Mnemonic Comments
Segment Offset
Operands
Address Address
RESULT:
FLOW CHART:
START
DX Addr. Of CWR
AL 80
[DX] AL
DX Addr. Of Port-A
AL 00
CX FFH
CX=0
NO
YES
Exp No:
Date:
DIGITAL TO ANALOG CONVERTER
DESCRIPTION: 8279 study card provides keyboard as well as display section. this section features size
8 digit seven segment displays while the keyboard connections comprises a 4x4 matrix hex a pad and
associated circuitry The options for using shift and control keys during key scanning are also provided.
The interface has 3 connections P1, J1 & J4 to interface the card with ESA 86/88E trainers. Connect the 50
pin FRC connectors P1 to connector J2 to ESA 86/88E study card adapter.
::
MANUAL CALCULATIONS:
ALGORITHM:
Step1: Start
Physical Address
Label Hex Mnemonic Comments
Step2: Load SI with memory location
Code Operands
Step3: Move 10 to AL register
Step4: Load CX with count
Step5: Initialize the command word register i.e., 0FF42
Step6: Locate the contents in AL register to DX register using port out
Step7: Move D3 to AL register
Step8: Locate the contents in AL register to DX register using port out
Step2: Decrement DX
CODE TABLE
PROGRAM:
START: MOV SI, 2000H
MOV CX, 0008H
MOV AL, 10
MOV DX, 00F42
OUT DX,AL
MOV AL,0D3
OUT DX,AL
MOV AL,90
OUT DX,AL
NEXT: MOV DX,0FF40
MOV AL,[SI]
OUT DX,AL
CALL DELAY
INC SI
LOOP NEXT
JMP START
DELAY PROGRAM:
MOV DX.0FFFFH
BACK: DEC DX
JNZ BACK
RET
INPUT DATA:
2000 00 77 F3 60 87 E6 77
RESULT:
FLOW CHART:
START
Initialize
R1 00
R2 00
R7 08
DPTR Memory Address
A [DPTR]
A Rotate Left A
YES NO
CF=1
R2 R2+1 R1 R1+1
R7 R7-1
YES NO
ZF=1
[DPTR+1] R1
[DPTR+2] R2
STOP
Exp No: Date:
9.FINDING NUMBER OF 1’S AND NUMBER OF 0’S IN A
GIVEN 8-BIT NUMBER
ABSTRACT: Assembly language program to find number of 1’s and 0’s
ALGORITHM:
Step 1: Start
Step 2: Initialize R1 and R2 registers with zeros
Step 3: Load the value 08H into R7 register
Step 4: Initializing base address location where given number is stored
Step 5: Coping value from memory location at which DPTR is pointing
Step 6: Rotate Accumulator Left Through Carry
Step 7: if CY=1 then Jump to Step 10
Step 8: Increment the content of R1 register
Step 9: Jump to Step11
Step 10: Increment the content of R2 register
Step 11: Decrement register R7 and jump if not Zero to step 6
Step 12: Moving the content of R1 to register A
Step 13: Increment the content of DPTR register
Step 14: Moving the content of register A to external RAM
Step 15: Moving the content of R2 to register A
Step 16: Increment the content of DPTR register
Step 17: Moving the content of register A to external RAM
Step 18: Repeat step18
CODE TABLE:
MOVX A, @DPTR
AGAIN: RLC A
JC NEXT
INC R1
SJMP HERE
NEXT: INC R2
HERE: DJNZ R7, AGAIN
MOV A, R1
INC DPTR
MOVX @DPTR, A
MOV A, R2
INC DPTR
MOVX @DPTR, A
RESULT:
FLOW CHART:
START
Initialize
R1 No of numbers
R2 00
DPTR Memory Address
A [DPTR]
A Rotate Right A
YES NO
CF=1
DPTR DPTR+1
R1 R1-1 R2 [DPTR] +R2
NO ZF=1 YES
[DPTR] R2
STOP
Exp No: Date:
10. ADDITION OF EVEN NUMBERS FROM A GIVEN ARRAY
ABSTRACT: Assembly language program to find the Addition of even numbers
from a given array.
PORTS USED: None
REGISTERS USED: A, R1, R2, DPTR
ALGORITHM:
Step 1: Start
Step 2: Clear the Carry flag i.e CF=0
Step 3: Load the value 04H into R1 register
Step 3: Initializing R2 register to zero
Step 4: Initializing base address location where given number is stored
Step 5: Coping value from memory location at which DPTR is pointing
Step 6: Bit 0 of the accumulator is rotated into the carry
Step 6: Rotate Accumulator Left Through Carry
Step 7: Jump if Carry Not Set to step 9
Step 8: Transfers execution to the specified address to step 13
Step 9: Moving the content of external RAM to register A
Step 10: Adds the contents of register A and Register R2
Step 11: Moving the content of register A to external RAM
Step 12: Moving the content of register R2 to register A
Step 13: Increment the content of DPTR register
Step 14: Decrement register R1 and jump if not Zero to step 9
Step 15: Repeat step15
MANUAL CALCULATIONS:
PROGRAM:
CLR C
MOV R1, #04
MOV R2, #00H
MOV DPTR, #6000H
UP: MOVX A, @DPTR
RRC A
JNC SKIP
SJMP EXIT
SKIP: MOVX A, @DPTR
ADD A, R2
MOV R2, A
EXIT: INC DPTR
DJNZ R1, UP
MOV A, R2
MOVX @DPTR, A
HLT: SJMP HLT
CODE TABLE:
#include <reg51.h>
void DELAY(void);
void main(void)
while(1)
DELAY();
DELAY();
void DELAY(void)
for(i=0;i<10;i++)
for(j=0;j<10000;j++);
}
RESULT:
Exp No: Date:
2.
and LEDs
#include<reg52.h>
LED_pin = 0; //LED ON
Delay(2000); //Delay
void Delay(int k)
int j;
int i;
for(i=0;i<k;i++)
for(j=0;j<100;j++)
RESULT:
Exp No: Date:
RESULT: