Logo 
Search:

Assembly Language Forum

Ask Question   UnAnswered
Home » Forum » Assembly Language       RSS Feeds

[help]What went wrong with this code????

  Asked By: Kim    Date: Feb 27    Category: Assembly Language    Views: 1586
  

This program searches a string for a given character and then calculates and displays the number of occurrences of that character in the string. If the character character does not occurs even for once, then the number of occurrence will be zero.

when i tried to change from .asm to .obj, it got an error message like this:

<35>near jump or call to different CS
<41>near jump or call to different CS
<61>near jump or call to different CS
<66>near jump or call to different CS

really appreciate your help cos i'm new in assembly language...

data SEGMENT
msg1 DB 'Enter the string: $'
msg2 DB 'Enter the character: $'
msg3 DB 'Number of occurrences: $'
string1 DB 20 dup('$')
ENDS

code SEGMENT

start:

MOV AX, data ;Initialize the data segment
MOV DS, AX

print MACRO msg ;Define macro 'msg'
MOV AH,09h ;Prints the string whose
MOV DX,OFFSET msg ;starting offset is stored

INT 21h ;in DX register
ENDM

print msg1 ;Print first message
MOV SI,OFFSET string1 ;Transfers offset of 'string1'

;into SI register.
MOV CX,0 ;Clears CX to store count

string:
MOV AH,01h ;Asks for a character and stores

INT 21h ;it into AL register
CMP AL,0dh ;Checks if an ENTER is pressed
JE outside ;If pressed goes outside

MOV [SI],AL ;otherwise stores the character
INC SI ;SI increments to point next location

INC CX ;Increase CX to count character input
JMP string ;Jumps and continues loop

outside:
MOV AH,02h ;Prints a newline followed by a linefeed

MOV DL,0dh ;character to go to the beginning
INT 21h ;of next line
MOV DL,0ah
INT 21h
print msg2 ;Prints string 'msg2' here

MOV AH,01h ;Asks for a character
INT 21h
MOV SI,OFFSET string1 ;Stores starting offset of string1 in SI

MOV BL,0h ;Clears BL

search:
CMP [SI],AL ;Checks for the character

JNE next ;if not found skips the character count
INC BL ;Increases the count
next:
INC SI ;Increment SI for the next character in string

LOOP search

MOV AH,02h ;Prints a newline followed by a linefeed
MOV DL,0dh ;character to go to the beginning

INT 21h ;of next line
MOV DL,0ah
INT 21h
print msg3 ;Prints string 'msg3'

MOV DL,BL ;Transfers the final count to DL

ADD DL,'0' ;Calculates the ASCII value of count
MOV AH,02h ;Prints the count,which is the number of
INT 21h ;occurrence of the given character

MOV AX, 4c00h ;Exit to the operating system
INT 21h
ENDS

END start

Share: 

 

1 Answer Found

 
Didn't find what you were looking for? Find more on [help]What went wrong with this code???? Or get search suggestion and latest updates.




Tagged: