king-gideon
April 4th, 2009, 04:25 PM
thanks so much its ok.i have so many things to learn in assembly language and i rily appreciate ur help.
but i still got more things:).
i showed the fist program i did that is the one that counts the number of occurences of a character in a string to my teacher and he says it is correct but i should write it in a diferent way:(.he referred to the REPNE SCASB line and said i shud write it in a different way:).he also said i shud write the program in such a way that i dnt have to input with the keyboard.meaning the program is jud=st gonna run itself.
here is d code:
CLEAR MACRO COLOR
MOV AX, 0600H
MOV BH, COLOR
XOR CX, CX
MOV DX, 184FH
INT 10H
ENDM
TEXTOUT MACRO TEXT ;string output using the function 21H
MOV AH, 09
LEA DX, TEXT
INT 21H
ENDM
TEXTIN MACRO BUF ;string input
MOV AH, 0AH
LEA DX, BUF
INT 21H
ENDM
StackS SEGMENT PARA STACK 'STACK'
DW 32 DUP(?)
StackS ENDS
MAX_TEXT EQU 80
DATA SEGMENT PARA PUBLIC 'DATA'
MESS1 DB 0AH,0DH,"input string: $"
MESS2 DB 0AH,0DH,"input letter: $"
MESSNOT DB 0AH,0DH,"letter not found.$"
MESSYES DB 0AH,0DH,"it contains $ "
BUF1 DB MAX_TEXT
QNT1 DB 0
TEXT1 DB MAX_TEXT DUP(?)
DATA ENDS
CODE SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CODE, DS:DATA, SS:StackS
START: MOV AX, DATA ;load into DS
MOV DS, AX ;selects the given segment
MOV ES, AX
CLEAR 30
TEXTOUT MESS1
TEXTIN BUF1
TEXTOUT MESS2
MOV AH,1
INT 21H
XOR CH, CH ;clears upper bite
MOV CL, QNT1 ;loads the number of symbols into the substring
JCXZ NOTFOUND ;empty string is a part of string
LEA DI, TEXT1 ;address of the substring in source input
XOR BX,BX
CLD ;sets the flag in the direction of ascending order
NEXT:
*REPNE SCASB ; continuously scan until a match is found or CX is 0
*JNE CONTINUE ; if no match, goto show the result
*ADD BX,1 ; if match, increment our count
*JCXZ CONTINUE ; if nothing more to process, goto show the result
*JMP NEXT ; otherwise, continue with our loop
*CONTINUE:
*CMP BX,0 ;compare string
*JE NOTFOUND
PUSH BX ; save our count into the stack
TEXTOUT MESSYES
POP AX ; put the count (from the stack) to AX
; PRINT the value of AX
mov bx, sp
divide_by10:
xor dx, dx
mov cx, 10
div cx
push dx
or ax, ax
jnz divide_by10
print_result:
mov ah, 2
pop dx
add dl, '0'
int 21h
cmp sp, bx
jne print_result
JMP EXIT
NOTFOUND:
TEXTOUT MESSNOT
EXIT: XOR AL, AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START
he askd me to rewrite the parts i marked with asteriks in the program.
secondly he askd me to write another program that puts a frame around a string wen i input with the keyboard.
example: hello
wud appear on the screen as
*******
*hello *
*******
the size of the frame changes with the lenght of the word inputed.
thks:)))
but i still got more things:).
i showed the fist program i did that is the one that counts the number of occurences of a character in a string to my teacher and he says it is correct but i should write it in a diferent way:(.he referred to the REPNE SCASB line and said i shud write it in a different way:).he also said i shud write the program in such a way that i dnt have to input with the keyboard.meaning the program is jud=st gonna run itself.
here is d code:
CLEAR MACRO COLOR
MOV AX, 0600H
MOV BH, COLOR
XOR CX, CX
MOV DX, 184FH
INT 10H
ENDM
TEXTOUT MACRO TEXT ;string output using the function 21H
MOV AH, 09
LEA DX, TEXT
INT 21H
ENDM
TEXTIN MACRO BUF ;string input
MOV AH, 0AH
LEA DX, BUF
INT 21H
ENDM
StackS SEGMENT PARA STACK 'STACK'
DW 32 DUP(?)
StackS ENDS
MAX_TEXT EQU 80
DATA SEGMENT PARA PUBLIC 'DATA'
MESS1 DB 0AH,0DH,"input string: $"
MESS2 DB 0AH,0DH,"input letter: $"
MESSNOT DB 0AH,0DH,"letter not found.$"
MESSYES DB 0AH,0DH,"it contains $ "
BUF1 DB MAX_TEXT
QNT1 DB 0
TEXT1 DB MAX_TEXT DUP(?)
DATA ENDS
CODE SEGMENT PARA PUBLIC 'CODE'
ASSUME CS:CODE, DS:DATA, SS:StackS
START: MOV AX, DATA ;load into DS
MOV DS, AX ;selects the given segment
MOV ES, AX
CLEAR 30
TEXTOUT MESS1
TEXTIN BUF1
TEXTOUT MESS2
MOV AH,1
INT 21H
XOR CH, CH ;clears upper bite
MOV CL, QNT1 ;loads the number of symbols into the substring
JCXZ NOTFOUND ;empty string is a part of string
LEA DI, TEXT1 ;address of the substring in source input
XOR BX,BX
CLD ;sets the flag in the direction of ascending order
NEXT:
*REPNE SCASB ; continuously scan until a match is found or CX is 0
*JNE CONTINUE ; if no match, goto show the result
*ADD BX,1 ; if match, increment our count
*JCXZ CONTINUE ; if nothing more to process, goto show the result
*JMP NEXT ; otherwise, continue with our loop
*CONTINUE:
*CMP BX,0 ;compare string
*JE NOTFOUND
PUSH BX ; save our count into the stack
TEXTOUT MESSYES
POP AX ; put the count (from the stack) to AX
; PRINT the value of AX
mov bx, sp
divide_by10:
xor dx, dx
mov cx, 10
div cx
push dx
or ax, ax
jnz divide_by10
print_result:
mov ah, 2
pop dx
add dl, '0'
int 21h
cmp sp, bx
jne print_result
JMP EXIT
NOTFOUND:
TEXTOUT MESSNOT
EXIT: XOR AL, AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START
he askd me to rewrite the parts i marked with asteriks in the program.
secondly he askd me to write another program that puts a frame around a string wen i input with the keyboard.
example: hello
wud appear on the screen as
*******
*hello *
*******
the size of the frame changes with the lenght of the word inputed.
thks:)))