Miccc
Miccc
Assembly language
OBJECTIVE:
ABSTRACT:
To find the reverse, we just copy the string from one memory location to another in
reverse order and display it. We first copy the first two bytes of the string array as it is
in the new string, since they remain same for the reversed string. Then we position the
SI pointer to the end of the given string and copy character by character in the new
string in reverse order. Finally the new string is displayed, which is the reverse of the
original string.
STC/SPRT/CSE/2022-2023 Page 1
Reversing a String in 8086
Assembly language
INTRODUCTION:
Intel 8086 microprocessor is the enhanced version of Intel 8085 microprocessor. It was
designed by Intel in 1976. o The 8086 microprocessor is a16-bit, N-channel, HMOS
microprocessor.
Where the HMOS is used for "High-speed Metal Oxide Semiconductor". o Intel
8086 is built on a single semiconductor chip and packaged in a 40-pin IC package.
The type of package is DIP (Dual Inline Package). o Intel 8086 uses 20 address lines
and 16 data- lines. It can directly address up to 220 = 1 Mbyte of memory. o It
consists of a powerful instruction set, which provides operation like division and
multiplication very quickly.
8086 is designed to operate in two modes, i.e., Minimum and Maximum mode.
STC/SPRT/CSE/2022-2023 Page 2
Reversing a String in 8086
Assembly language
Using 8086 micro-processor, we will create a program that reverses a string using all
the above process.
To find the reverse, we just copy the string from one memory location to another in
reverse order and display it.
We first copy the first two bytes of the string array as it is in the new string, since they
remain same for the reversed string. Then we position the SI pointer to the end of the
given string and copy character by character in the new string in reverse order.
Finally the new string is displayed, which is the reverse of the original string.
SOFTWARE REQUIREMENTS:
STC/SPRT/CSE/2022-2023 Page 3
Reversing a String in 8086
Assembly language
METHODOLOGY:
STC/SPRT/CSE/2022-2023 Page 4
Reversing a String in 8086
Assembly language
• Reusability of code:
The procedures provide us an ease in our code by making the set of instructions
reusable. So, we need not write the same set of instructions again and again when
required.
• Less usage of memory:
The procedure is a subprogram which is stored in the memory only one. But it
can used as many times as required. So, this occupies less memory space.
• Development becomes easier:
By using procedures in a code, the modular programming can be well
implemented and so, each part of the code is written in a different module which
can be developed by a separate developer. So, this reduces the burden on one
developer and the programming becomes simple for each of them.
• Reduced development time:
As separate developers can work on different modules of programs separately,
multiple developers can work on the project simultaneously which reduces the
total development time of the project.
• Debugging and error fixing becomes easier:
It becomes easier to detect and fix errors if the program is present in different
modules rather than the entire program being present in a single code fragment.
STC/SPRT/CSE/2022-2023 Page 5
Reversing a String in 8086
Assembly language
FLOWCHART:
STC/SPRT/CSE/2022-2023 Page 6
Reversing a String in 8086
Assembly language
STC/SPRT/CSE/2022-2023 Page 7
Reversing a String in 8086
Assembly language
PROGRAM:
.MODEL SMALL
.STACK 100H
.DATA
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
; interrupt to exit
MOV AH, 4CH
INT 21H
MAIN ENDP
REVERSE PROC
; load the offset of
; the string
MOV SI, OFFSET STRING
LOOP1:
; compare if this is;
;the last character
MOV AX, [SI]
CMP AL, '$'
JE LABEL1
INC CX
JMP LOOP1
LABEL1:
; again load the starting;
;address of the string
MOV SI, OFFSET STRING
LOOP2:
;if count not equal to zero
CMP CX,0
JE EXIT
; make dh, 0
XOR DH, DH
; increment si and;
;decrement count
INC SI
DEC CX
JMP LOOP2
EXIT:
; add $ to the end of string
MOV [SI],'$ '
RET
REVERSE ENDP
END MAIN
. MODEL SMALL
.STACK 100H
.DATA
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX
STC/SPRT/CSE/2022-2023 Page 9
Reversing a String in 8086
Assembly language
; interrupt to exit
MOV AH, 4CH
INT 21H
MAIN ENDP
REVERSE PROC
; load the offset of
; the string
MOV SI, OFFSET STRING
LOOP1:
; compare if this is;
;the last character
MOV AX, [SI]
CMP AL, '$'
JE LABEL1
JMP LOOP1
LABEL1:
; again load the starting;
;address of the string
MOV SI, OFFSET STRING
LOOP2:
;if count not equal to zero
CMP CX,0
JE EXIT
STC/SPRT/CSE/2022-2023 Page 10
Reversing a String in 8086
Assembly language
; pop the top of stack
POP DX
; make dh, 0
XOR DH, DH
; increment si and;
;decrement count
INC SI
DEC CX
JMP LOOP2
EXIT:
; add $ to the end of string
MOV [SI],'$ '
RET
REVERSE ENDP
END MAIN
STC/SPRT/CSE/2022-2023 Page 11
Reversing a String in 8086
Assembly language
Output:
STC/SPRT/CSE/2022-2023 Page 12