SoFunction
Updated on 2025-04-06

Assembly language implements a method to search for character 'A' in a specified string

I don't know how I wrote this kind of thing before, so I can leave it to memorial...

;Design the program using string operation instructions to realize the search for the character ‘A’ in the specified string,
;If there is a character 'A' in the string of the note,
;The position of the first 'A' character in the string is recorded in the BX register,
;If not included, BX=0FFFFH is made.
;Before the program starts to find the specified characters, please output prompt information on the screen:
;The program is running! The output information after searching: the program is over!

DATAS SEGMENT
  STRING DB 'CDAFX246hk'
  NO DW 10
  FALSE DW 0FFFFH
  STR1 DB 'The program is running!$'
  STR2 DB 0DH,0AH,'The program is over!$' 
DATAS ENDS

STACKS SEGMENT
  DW 20 DUP(?)
STACKS ENDS

CODES SEGMENT
  ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
  MOV AX,DATAS
  MOV DS,AX
  MOV ES,AX

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

  MOV BX,FALSE
  LEA DI,STRING
  MOV AL,'A'
  MOV CX,NO
  REPNE SCASB
  CMP CX,0
  JE COUNT
  DEC DI
  MOV BX,DI
COUNT:

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

  MOV AH,4CH
  INT 21H
CODES ENDS
  END START

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.