Click to See Complete Forum and Search --> : pls help me with assemblers


king-gideon
April 2nd, 2009, 07:57 PM
i need to write a program in assembly language that counts the number of a character in a string.
sumthin like this
input string:gdfdzfgfgf
input letter:z
string contains 1.

input string:gdfdzfgfgf
input letter:d
string contains 2.

i wrote sumthing likt this but it is only showing the position not the number of the character

CLEAR MACRO COLOR
MOV AX, 0600H
MOV BH, COLOR
XOR CX, CX
MOV DX, 184FH
INT 10H
ENDM

TEXTOUT MACRO TEXT
MOV AH, 09
LEA DX, TEXT
INT 21H
ENDM

TEXTIN MACRO BUF
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
MOV DS, AX
MOV ES, AX

CLEAR 30
TEXTOUT MESS1
TEXTIN BUF1
TEXTOUT MESS2
MOV AH,1
INT 21H

XOR CH, CH
MOV CL, QNT1
JCXZ NOTFOUND
LEA DI, TEXT1
XOR BX,BX
CLD

NEXT:
SCASB
JNE CONTINUE
PUSH CX
ADD BX,1

CONTINUE:
LOOP NEXT

CMP BX,0
JE NOTFOUND

TEXTOUT MESSYES
POP AX

;AX=QNT1-AX+1
XOR BH,BH
MOV BL,QNT1
SUB BX,AX
MOV AX,BX
ADD AX,1


XOR CX,CX
MOV BX,10D
_REPEAT:
XOR DX,DX
DIV BX
PUSH DX
INC CX
CMP AX,0
JNZ _REPEA
MOV AH,2
_PRINT:
POP DX
OR DL,30H
INT 21H
LOOP _PRINT


NOTFOUND:
TEXTOUT MESSNOT

EXIT: XOR AL, AL
MOV AH, 4CH
INT 21H
CODE ENDS
END START

rxbagain
April 2nd, 2009, 10:09 PM
Hi gideon,

I changed the way scanning is done. Instead of checking the input 1 by 1, i used REPNE SCASB (Repeat while not equal SCASB) so that it will loop by itself until the a match is found.

There is also a problem in the way you output the result. I did not check it much, what I did is I just placed my own algo in converting the number to text.

Here is the modification beginning from the label "NEXT:"

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
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
; for the explanation of the algo i used, check this post (http://www.codeguru.com/forum/showthread.php?p=1817834#post1817834)
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


Hope it will help you :)

king-gideon
April 3rd, 2009, 03:17 AM
thanks so much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

svn_11@yahoo.com
October 16th, 2009, 08:24 AM
pls help me..i im nobe in assembly language i dont know the nxt step.
this is the code but i dont know the nxt
a100
mov ax, 00
int 33
mov ax, 01
int 33
mov ax, 03
int 10
mov ah, 02
mov dx, 001c
mov bh, 00
int 10
mov ah, 09
mov dx, 01d3
int 21
mov ah, 02
mov dx, 031c
int 10
mov ah, 09
mov dx, 0228
int 21
mov ah, 02
mov dx, 041d
int 10
mov ah, 09
mov dx, 01de
int 21
mov ah, 02
mov dx, 051c
int 10
mov ah, 09
mov dx, 01e7
int 21
mov ah, 02
mov dx, 061a
int 10
mov ah, 09
mov dx, 01f3
int 21
mov ah, 02
mov dx, 071d
int 10
mov ah, 09
mov dx, 0202
int 21
mov ah, 02
mov dx, 0a1e
int 10
mov ah, 09
mov dx, 0232
int 21
mov cx, 0000
mov dx, 0000
mov bx, 0000
mov ax, 03
int 33
cmp bx, 1
jne 017c
cmp cx, 0120
jg 17c
cmp cx, 00d0
jl 17c
cmp dx, 0020
je 01ad
cmp dx, 0028
je 01b2
cmp dx, 0030
je 01b7
cmp dx, 0038
je 01bc
cmp dx, 0050
je 01d1
jne 17c
mov dx, 020b
jmp 01bf
mov dx, 020f
jmp 01bf
mov dx, 0218
jmp 01bf
mov dx, 0221
mov ah, 02
mov bx, 0000
mov di, dx
mov dx, 0c1d
int 10
mov dx, di
mov ah, 09
int 21
int 20
db "Calculator$"
db "Addition$"
db "Subtraction$"
db "Multiplication$"
db "Division$"
db "Add$"
db "Subtract$"
db "Multiply$"
db "Divide$"
db "Menu$"
db "Exit$"

this is the frame

menu
add
sub
mul
divide
exit
1st screen
The 1st frame nid to be clicakble to do the 2 screen frame
example if u click the a,d,d,i.t,i,o,n any of the letters we going to second frame to do the operation the same in subtraction and multiplication but the division nid a two answer the quotient and remainder

1st number___
2nd number___
result___
press any key 2 return to menu
second screen
note 3 digits max including negative value and the numbers be in ascii code...

pls help me..tnx

jcaccia
October 16th, 2009, 10:50 AM
svn_11@yahoo.com: please stop posting the same problem in different unrelated threads. If you have a question/problem create your own thread.