Logo 
Search:

Assembly Language Articles

Submit Article
Home » Articles » Assembly Language » Homework HelpRSS Feeds

Program to find the first and last character of a string and print it on the screen

Posted By: Maya Hughes     Category: Assembly Language     Views: 6873

Write a program to find the first and last character of a string and print it on the screen.

Code for Program to find the first and last character of a string and print it on the screen in Assembly Language

DATA SEGMENT
        STR1 DB "ENTER YOUR STRING HERE ->$"
        STR2 DB "YOUR STRING IS ->$"
        STR3 DB "FIRST CHARACTER IS ->$"
        STR4 DB "LAST CHARACTER IS ->$"
        INSTR1 DB 20 DUP("$")
        NEWLINE DB 10,13,"$"
        N DB "$"
        S DB ?

DATA ENDS

CODE SEGMENT
        ASSUME DS:DATA,CS:CODE
START:

        MOV AX,DATA
        MOV DS,AX

        LEA SI,INSTR1

;GET STRING
        MOV AH,09H
        LEA DX,STR1
        INT 21H

        MOV AH,0AH
        MOV DX,SI
        INT 21H


        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

;PRINT THE STRING

        MOV AH,09H
        LEA DX,STR2
        INT 21H

        MOV AH,09H
        LEA DX,INSTR1+2
        INT 21H

        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

;PRINT FIRST CHARACTER OF STRING

        MOV AH,09H
        LEA DX,STR3
        INT 21H

        MOV AH,02H
        MOV DL,INSTR1+2
        INT 21H

        MOV AH,09H
        LEA DX,NEWLINE
        INT 21H

;PRINT LAST CHARACTER OF STRING

        MOV AH,09H
        LEA DX,STR4
        INT 21H

        ADD SI,3

     L1:
        DEC SI
        MOV BL,BYTE PTR[SI]

;        MOV AH,09H
;        LEA DX,NEWLINE
;        INT 21H

;        MOV AH,02H
;        MOV DL,BL
;        INT 21H
  
        ADD SI,2
        CMP BYTE PTR[SI],"$"
        JNE L1

        MOV AH,02H
        MOV DL,BL
        INT 21H

        MOV AH,4CH
        INT 21H


CODE ENDS
END START


;OUTPUT:-
;Z:\SEM3\SS\21-30>P23
;ENTER YOUR STRING HERE ->JINESH
;YOUR STRING IS ->JINESH
;FIRST CHARACTER IS ->J
;LAST CHARACTER IS ->H
  
Share: 



Maya Hughes
Maya Hughes author of Program to find the first and last character of a string and print it on the screen is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in Assembly Language:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!