Jump to content

help pls... assembly language

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
ishi

ishi

    Newbie

  • Members
  • Pip
  • 1 posts
hello,

i was wondering if someone could give me an idea on building a program in assembly language which asks the user to enter a string and count the no. of times an entered character occurs in that given string.

#2
chax

chax

    Learning Programmer

  • Members
  • PipPipPip
  • 76 posts
First write a C routine in TC that doesn't print but does everything else that you say without using standard libraries. Now compile but don't assemble or link. What you get is the assembly language program. Now print the result using INT 10h BIOS or INT 20/21h (Not sure) dos interrupt.
Size does matter for science and its laws changes accordingly.
[SIGPIC][/SIGPIC]
An C

#3
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
Something like this...

USE16

ORG 0x100


	section .data

msg:	db	'Insert some text: $'

buf:

max:	db	255

cnt:	db	0

str:	times 255 db 0



	section .text

_start:

	push	word msg

	call	near _print

	push	word buf

	call	near _read

	push	word 'A'

	push	word str

	push	word [max]

	call	near _findchr

	call	near _wait

	call	near _exit

	retn



_print:

	push	bp

	mov	bp, sp

	mov	ah, 0x09

	mov	dx, word [bp+4]

	int	0x21

	pop	bp

	retn	2


_read:

	push	bp

	mov	bp, sp

	mov	ah, 0x0A

	mov	dx, word [bp+4]

	int	0x21

	pop	bp

	retn	2


_findchr:

	push	bp

	mov	bp, sp

	mov	si, word [bp+6]

	xor	cx, cx

	xor	ax, ax

.loop:

	cmp	cx, word [bp+8]

	je	.out

	cmp	si, word [bp+4]

	je	.found

	inc	si

	inc	cx

	jmp	.loop

.found:

	inc	ax

	jmp	.loop

.out:

	pop	bp

	retn	2


_wait:

	mov	ah, 0x00

	int	0x16

	retn


_exit:

	mov	ax, 0x4C00

	int	0x21

	retn


It asks for a string, then it checks the ocurrence of character 'A' in the string you entered, and the number of ocurrences is returned by AX. Assemble it with NASM and check it, i think that everything is well...