Docsity

Assembly Language Programming Examples and Exercises - Prof. Pandiarajan, Study notes of Microprocessors

Toggle sidebar
bg1
ST.ANNEโ€™S
COLLEGE OF ENGINEERING AND TECHNOLOGY
(Approved by AICTE, New Delhi. Affiliated to Anna University, Chennai)
(An ISO 9001: 2015 Certified Institution)
ANGUCHETTYPALAYAM, PANRUTI โ€“ 607 106.
.
DEPARTMENT OF
COMPUTER SCIENCE ENGINEERING
LAB MANUAL
JULY 2021โ€“ NOV 2021/ ODD SEMESTER
SUBJECT CODE/NAME: EC8681-MICROPROCESSORS AND
MICROCONTROLLERS LABORATORY
YEAR/SEM: II/III BATCH: 2019- 2023
AS PER ANNA UNIVERSITY, CHENNAI REGULATION 2021
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Assembly Language Programming Examples and Exercises - Prof. Pandiarajan and more Study notes Microprocessors in PDF only on Docsity!

ST.ANNEโ€™S

COLLEGE OF ENGINEERING AND TECHNOLOGY

(Approved by AICTE, New Delhi. Affiliated to Anna University, Chennai) (An ISO 9001: 2015 Certified Institution) ANGUCHETTYPALAYAM, PANRUTI โ€“ 607 106.

.

DEPARTMENT OF

COMPUTER SCIENCE ENGINEERING

LAB MANUAL

JULY 2021 โ€“ NOV 202 1 / ODD SEMESTER

SUBJECT CODE/NAME: EC8681-MICROPROCESSORS AND

MICROCONTROLLERS LABORATORY

YEAR/SEM: II/III BATCH : 20 19 - 2023

AS PER ANNA UNIVERSITY, CHENNAI REGULATION 2 021

16 BIT ADDITION

Start

Initialize count as zero for carry

Get the two data

Add the datas

If No

Carry

Yes

Increment the count

Store the result & carry

Stop

1 B) 16 BIT SUBTRACTION
ALGORITHM:-

(i) Start the process (ii) Initialize the count value (iii) Get the two data and subtract it. (iv) If carry exists, get the 2โ€Ÿs complement of the value. (v) Store the result and carry value. (vi) Stop the process.

PROGRAM

Labe l Address Mnemonics Hex code Comments

Opcode Operand 1000 MOV CL, 00 C6, C1, 00 ; Initialize the count

1003 MOV AX, [1100] 8B, 06, 00, 11 ; Move

st data to accumulator

1007 MOV BX, [1102] 8B, 1E, 02, 11 ; Move 2

nd data to โ€žBโ€Ÿ register 100B SUB BX, AX 29, C3 ; Subtract the two datas 100D JNC LOOP1 73, 05 ; Jump on no carry 100F INC CL FE, C1 ; Increment the counter 1011 NOT BX F7, D3 ; Get the complement value 1013 INC BX 43 ; Increment the value LOOP1: 1014 MOV [1104], BX 89, 1E, 04, 11 ; Store the result 1018 MOV [1106], CL 88, 0E, 06, 11 ; Store the carry 101C HLT F4 ; Stop the process

OUTPUT

16 โ€“ BIT SUBTRACTION

Address Input Address Out put

1100 76 1104 31 1101 86 1105 65 1102 45 1106 00 1103 81

1.C) 16 BIT MULTIPLICATION
ALGORITHM:-

(i) Start the process (ii) Get the two values (iii) Multiply the two values. (iv) Store the result and overflow (v) Stop the process.

PROGRAM

Label Address Mnemonics Hex code Comments

Opcode Operand 1000 MOV SI, 1100 C7, C6,00, 11 ; Move the source index 1004 MOV AX, [SI] 8B, 04 value 1006 MOV BX, [SI + 02] 8B, 54, 02 ; Move the first data 1009 MUL BX F7, E3 ; Get the second data 100B MOV [SI + 04], 89, 44, 04 ; Multiply the data 100E MOV AX 89, 54, 0b ; Store the result 1011 HLT [SI + 06], F4 ; Store the over flow DX ; Stop the process

INPUT

Address Input

1100 11 1101 11 1102 00 1103 11

OUTPUT

Address Output

1104 00 1105 21 1106 22 1107 01

FLOW CHART:-

Multiplication:-

Start

Get the two values

Multiply the values

Store the result & overflow

Stop

D) 16 BIT DIVISION
PROGRAM

Label Address Mnemonics Hex code Comments

Opcode Operand 1000 MOV SI, 1100 C7, C6,00, 11 ; Get the source index value 1004 MOV Ax, [SI] 8B, 04 ; Get the first data 1006 MOV DX, [SI + 8B, 54, 02 ; Initialize โ€žDXโ€Ÿ register 1009 MOV 02] 8B, 5C, 04 value 100C DIV BX, [SI + 04] F7, E3 ; Get the dividend value 100E MOV BX 89, 44, 06 ; Divide the value 1011 MOV [SI + 06], 89, 54, 08 ; Move the quotient 1014 HLT AX F4 ; Move the remainder & store [SI + 08], ; Stop the process DX

16 โ€“ BIT DIVISIION

Address Input

1100 42 (DIVIDEND) 1101 24 1102 00 1103 00

1104 02(DIVISOR) 1105 00

RESULT:-

Address Output 1106 21(QUOTIENT) 1107 12 1108 00(REMAINDER) 1109 00

Thus the assembly language program for 16 Bit Arithmetic and Logical operations has been done and verified.

VIVA QUES TIONS AND ANSWERS

1. What is a Microprocessor? Microprocessor is a CPU fabricated on a single chip, program-controlled device, which fetches the instructions from memory, decodes and executes the instructions. 2. What is Instruction Set? It is the set of the instructions that the Microprocessor can execute. 3. What is Clock Speed? Clock speed is measured in the MHz and it determines that how many instructions a processor can processed. The speed of the microprocessor is measured in the MHz or GHz. 4. What are the features of Intel 8086? Features: Released by Intel in 1978 Produced from 1978 to 1990s A 16-bit microprocessor chip. Max. CPU clock rate:5 MHz to 10 MHz Instruction set: x86- 5. What are the flags in 8086? In 8086 carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace flag, Interrupt flag, Direction flag, and Sign flag.

  1. What is assembly language? The language in which the mnemonics (short -hand form of instructions) are used to write a program is called assembly language. The manufacturers of microproces sor give the mnemonics. 7. What are machine language and assembly language programs? The software developed using 1's and 0's are called machine language, programs. The software developed using mnemonics are called assembly language programs. 8. What is the drawback in machine language and assembly language, programs? The machine language and assembly language programs are machine dependent. The programs developed using these languages for a particular machine cannot be directly run on another machine. 9. Define bit, byte and word. A digit of the binary number or code is called bit. Also, the bit is the fundamental storage unit of computer memory. The 8-bit (8-digit) binary number or code is called byte and 16-bit binary number or code is called word. (Some microprocessor manufactures refer the basic data size operated by the processor as word). 10. What is a bus? Bus is a group of conducting lines that carries data, address and control signals.
SORTING IN ASCENDING ORDER

Start

Load the address of the array in SI register

Load the count in CL register and decrement by one

2

Load the address of array in SI regist er

Load t he count in CH regist er and decre ment by one 1

Incre ment the array pointer (SI)

1

Get an element of array in AL register

2 Incre ment the array pointer (SI)

Compare next element of array with AL

Is No CF = 1?

Yes

Exchange AL and me mory pointed by SI

Exchange AL and me mory pointed by SI โ€“ 1

Decrement CH count

No Is

ZF = 1?

Yes Decrement CL count

No

Is

ZF = 1?

Yes Stop

PROGRAM

Labe l Address Mnemonics Hex code Comments

Opcode Operand ST ART : 1000 MOV SI, 1100H C7 C6 00 11 ; Set SI register as pointer for array 1004 MOV CL, [SI} 8A 0C ; Set CL as count for N โ€“ 1 repetitions 1006 DEC CL FE C RE P E AT 1008 MOV SI, 1100H C7 C6 00 11 ; Initialize pointer 100C MOV CH, [SI] 8A 2C : Set CH as count for N โ€“ 1 comparisons 100E DEC CH FE CD 1010 INC SI 46 ; Decrement the count RE P CO M 1011 MOV AL, [SI] 8A 04 ; Get an element of array in AL register 1013 INC SI 46 1014 CMP AL, [SI] 3A 04 ; Compare with next element of array ; in memory 1016 JC AHEAD 72 05 ; It AL register is lesser than memory, โ€žthen go to AHEAD 1018 XCHG AL, [SI] 86 04 ; If AL is less than memory then ; exchange 101A XCHG AL, [SI โ€“ 1] 86 44 FF ; the content of memory pointed by ; SI and the previous memory location AHEAD 101D DEC CH FE CD ; Decrement the count for comparisons 101F JNZ REPCOM 75 F0 ; Repeat comparisons until CH count is ; zero 1021 DEC CL FE C9 ; Decrement the count for repetitions 1023 JNZ REPEAT 75 E3 ; Repeat N โ€“ 1 comparisons until CL count is zero 1025 HLT F

Address Input

1100 05 โ€“ c ount 1101 09 1102 49 1103 24 1104 32 1105 64

RESULT:

Address Output 1100 05 โ€“ count 1101 09 1102 24 1103 32 1104 49 1105 64

Thus the assembly language program to sort an array of data in ascending order using 8086

has been done and verify successfully.

SORTING IN DESCENDING ORDER

Start

Load the address of the array in SI register

Load the count in CL register and decre ment by one

2

Load the address of array in SI regist er

Load t he count in CH regist er and decre ment by one 1

Incre ment the array pointer (SI)

1 Get an elem ent of array in AL regist er

2 Incre ment the array pointer (SI)

Compare next element of array with AL

No

Is CF = 0?

Yes

Exchange AL and me mory pointed by SI

Exchange AL and memory pointed by SI โ€“ 1

Decrement CH count

No

Is ZF = 1?

Yes Decrement CL count

No

Is ZF = 1?

Yes Stop

PROGRAM

Labe l Address Mnemonics Hex code Comments

Opcode Operand ST ART : 1000 MOV SI, 1100H C7 C6 00 11 ; Set SI register as pointer for array 1004 MOV CL, [SI} 8A 0C ; Set CL as count for N โ€“ 1 repetitions 1006 DEC CL FE C RE P E AT 1008 MOV SI, 1100H C7 C6 00 11 ; Initialize pointer 100C MOV CH, [SI] 8A 2C : Set CH as count for N โ€“ 1 comparisons 100E DEC CH FE CD 1010 INC SI 46 ; Increment the count RE P CO M 1011 MOV AL, [SI] 8A 04 ; Get an element of array in AL register 1013 INC SI 46 1014 CMP AL, [SI] 3A 04 ; Compare with next element of array ; in memory 1016 JNC AHEAD 73 05 ; It AL is greater than memory, then go ; to AHEAD 1018 XCHG AL, [SI] 86 04 ; If AL is less than memory then 101A XCHG AL, [SI โ€“ 1] 86 44 FF ; exchange the content of memory ; pointed by SI and the previous memory ; location AHEAD 101D DEC CH FE CD ; Decrement the count for comparisons 101F JNZ REPCOM 75 F0 ; Repeat comparisons until CH count is zero 1021 DEC CL FE C9 ; Decrement the count for repetitions 1023 JNZ REPEAT 75 E3 ; Repeat N โ€“ 1 comparisons until CL count is zero 1025 HLT F

Address Input

1100 05 โ€“ c ount 1101 09 1102 49 1103 24 1104 32 1105 64

Address Output 1100 05 โ€“ count 1101 64 1102 49 1103 32 1104 24 1105 09

RESULT:

Thus the assembly language program to sort an array of data in descending order using 8086

has been done and verify successfully.

FLOWCHART

Start

Load the address of array in SI register

Load the address of result in DI register

Set CL as byte count

Incre ment array pointer (SI)

Get the first byte of array in AL register

Decrement the byte count

B Increm ent array point er (SI)

Get the next byte of array in BL register

Compare AL and BL register

Yes Is

CF = 1?

MoveNo BL to AL

A
A

Decrement byte count (CL)

B No

Is ZF = 1?

Yes Store AL in me mory

Stop

PROGRAM

Label Address Mnemonics Hex code Comments

Opcode Operand ST ART 1000 MOV SI, 1100H C7 C6 00 11 ; Set SI register as pointer for array 1004 MOV DI, 1200H C7 C7 00 12 ; Set DI register as pointer for result 1008 MOV CL, [SI] 8A 0C ; Set CL as count for elements in the array 100A INC SI 46 ; Increment the address pointer 100B MOV AL, [SI] 8A 04 ; Set first data as smallest 100D DEC CL FE C9 ; Decrement the count AGAI N 100F INC SI 46 ; Make SI to point to next data in array 1010 MOV BL, [SI ] 8A 1C ; Get the next data in BL register 1012 CMP AL, BL 38 D8 ; Compare current smallest data in AL ; with BL 1014 JC AHEAD 72 02 ; If carry is set then AL is less than BL ; hence proceed to AHEAD 1016 MOV AL, BL 88 D8 ; If carry is not set then make BL as ; current smallest AHE AD 1018 DEC CL FE C9 ; Decrement the count 101A JNZ AGAIN 75 F3 ; If count is not zero repeat search 101C MOV [DI], AL 88 05 ; Store the smallest data in memory 101E HLT F

Smallest no in the array Address Input 1100 ( 05) count (^1101) 22 (^1102) AA (^1103) FF 1104 45 (^1105) 50 Address Output 200 22

RESULT:

Thus the assembly language program for smallest data in an array using 8086 has been done

and verify successfully.