How to create an assembly program that will allow the user to enter somer characters and group the characters according to the following: alphabets, numbers, and special characters.


ASAP.

thanks.

Recommended Answers

All 6 Replies

How to create an assembly program that will allow the user to enter somer characters and group the characters according to the following: alphabets, numbers, and special characters.


ASAP.

thanks.

You want your free advice/pointers - ASAP.

do you know how?

Any particular processor?
Here's some fun code:

; CHRGRP.ASM : Compiled with A86 (http://eji.com/a86/)
; Do not use the Ampersand (&) (special char to separate commands in DOS.
; ------------------------------------------------------------------------
; This program will take bytes from the COMMAND-LINE & evaluate them for
; their TYPE (Numbers, Characters, Punctuation).
; ----------------------------- ;
; Print the title for Numbers	;
	mov ah, 09h		;
	mov dx, ttlNumbers	; NUMBERS header
	int 21h			; Write String
				;
	mov si, 0080h		; Address of the COUNT of command-line bytes
	mov cx, [si]		; Count of command-line bytes
	mov ch, 0h		; ...don't need/want this
	mov si, 0082h 		; put the address of chars in SI
chkNumLoop:
	mov bl, [si]		; move the current byte into BL
	call isANum		; check for NUM
	cmp bh, 1h		; if not a num...
	jne noPrintNum		; ...go to next char
printNum:			; else
	push si			; 
	mov si, printSpot	; put the byte in the STRING printing spot
	mov [si], bl		;
	mov ah, 09h		; ...
	mov dx, printSpot	; ...
	int 21h			; Print it
	pop si			;
noPrintNum:			;
	inc si			;
	loop chkNumLoop		; decrements CX when looping
				;
; ----------------------------- ;	
; Print the title for Chars	;
	mov ah, 09h		;
	mov dx, ttlChars	; CHARACTERS header
	int 21h			; Write String
				;
	mov si, 0080h		; Address of the COUNT of command-line bytes
	mov cx, [si]		; Count of command-line bytes
	mov ch, 0h		; ...don't need/want this
	mov si, 0082h 		; put the address of chars in SI
chkCharLoop:			;
	mov bl, [si]		; move the current byte into BL
	call isLowerChar	; check for Char
	cmp bh, 1h		; if not a char...
	je printChar		; 
	call isUpperChar	;
	cmp bh, 1h		;
	jne noPrintChar		;
printChar:			; else
	push si			;
	mov si, printSpot	; put the byte in the STRING printing spot
	mov [si], bl		;
	mov ah, 09h		; ...
	mov dx, printSpot	; ...
	int 21h			; Print it
	pop si			;
noPrintChar:			;
	inc si			;
	loop chkCharLoop	; decrements CX when looping
				;
; ----------------------------- ;	
; Print the title for Punct.	;
	mov ah, 09h		;
	mov dx, ttlPunctuation	; PUNCTUATION header
	int 21h			; Write String
				;
	mov si, 0080h		; Address of the COUNT of command-line bytes
	mov cx, [si]		; Count of command-line bytes
	mov ch, 0h		; ...don't need/want this
	mov si, 0082h 		; put the address of chars in SI
chkPunctLoop:			;
	mov bl, [si]		; move the current byte into BL
	call isLowerChar	; check for Char
	cmp bh, 1h		; if not a char...
	je  noPrintPunct	;
	call isUpperChar	; check for Upper char
	cmp bh, 1h		;
	je  noPrintPunct	;
	call isANum		; check for NUM
	cmp bh, 1h		; if not a num...
	je noPrintPunct		;
printPunct:			; All checks failed, it's PUNCT
	push si			;
	mov si, printSpot	; put the byte in the STRING printing spot
	mov [si], bl		;
	mov ah, 09h		; ...
	mov dx, printSpot	; ...
	int 21h			; Print it
	pop si			;
noPrintPunct:			;
	inc si			;
	loop chkPunctLoop	; decrements CX when looping
				;
	int 20h			; ********** DROP TO DOS *********
; ----------------------------- ;
isANum:				; Subroutine isANum();
	mov bh, 0h		;
	cmp bl, 30h		;
	jl  notANum		; Numbers are between 0x30 and 0x39
	cmp bl, 39h		;
	jg  notANum		;
	mov bh, 1h		; TRUE
notANum:; or done		;
	ret			;
; ----------------------------- ;
isUpperChar:			; Subroutine isUpperChar();
	mov bh, 0h		;
	cmp bl, 41h		;
	jl  notUpperChar	; Upper chars are between 0x41 and 0x5a
	cmp bl, 5ah		;
	jg  notUpperChar	;
	mov bh, 1h		; TRUE
notUpperChar:; or done
	ret			;
; ----------------------------- ;
isLowerChar:			; Subroutine isLowerChar();
	mov bh, 0h		;
	cmp bl, 61h		;
	jl  notLowerChar	; Lower chars are between 0x61 and 0x7a
	cmp bl, 7ah		;
	jg  notLowerChar	;
	mov bh, 1h		; TRUE
notLowerChar:; or done		;
	ret			;
				;
;--------------------[Print Spot]--------------------------------
printSpot: ; Transfer bytes here to print
	db 00, '$'		;
				;
;--------------------[HEADERS / TITLES]--------------------------
ttlChars:	db 0ah, 0dh, '[Characters]', 0ah, 0dh, 024h
ttlPunctuation:	db 0ah, 0dh, '[Punctuation]', 0ah, 0dh, 024h
ttlNumbers:	db 0ah, 0dh, '[Numbers]', 0ah, 0dh, 024h

; Results
;C:\science\asm>CHRGRP T5h4!i3-s2%I1^sNeat
;
;[Numbers]
;54321
;[Characters]
;ThisIsNeat
;[Punctuation]
;!-%

Please change all of the "MOV ??, 0h" to "XOR ??, ??".

You can also change the character print sections to call one routine:

;so something like this:
printNum:			; else
	push si			; 
	mov si, printSpot	; put the byte in the STRING printing spot
	mov [si], bl		;
	mov ah, 09h		; ...
	mov dx, printSpot	; ...
	int 21h			; Print it
	pop si			;
noPrintNum:

; BECOMES:
printNum:			; else
	push si			; 
	call doPrint;		;
	pop si			;
noPrintNum:	

; AS A FORWARD REFERENCE TO:
doPrint:			; Subroutine doPrint
	mov si, printSpot	; put the byte in the STRING printing spot
	mov [si], bl		;
	mov ah, 09h		; ...
	mov dx, printSpot	; ...
	int 21h			; Print it
	ret			;

Sorry for multiple updates, but here is a bug-fix (for when there are no command-line parameters present) and an enhancement on the print routine.

; CHRGRP.ASM : Compiled with A86 (http://eji.com/a86/)
; Do not use the Ampersand (&) (special char to separate commands in DOS.
; ------------------------------------------------------------------------
; This program will take bytes from the command-line and evaluate them for
; their TYPE (Numbers, Characters, Punctuation).
; ----------------------------- ;
	mov si, 0080h		; Address of the COUNT of command-line bytes
	mov cx, [si]		; Count of command-line bytes
	xor ch, ch		; ...don't need/want this
	cmp cl, 0h		; If there are no command-line parameters
	je doUsage		; ...show usage message and exit.
				;
; Print the title for Numbers	;
	mov ah, 09h		;
	mov dx, ttlNumbers	; NUMBERS header
	int 21h			; Write String
				;
	mov si, 0082h 		; else put the address of chars in SI
chkNumLoop:
	mov bl, [si]		; move the current byte into BL
	call isANum		; check for NUM
	cmp bh, 1h		; if not a num...
	jne noPrintNum		; ...go to next char
printNum:			; else
	push si			; 
	call doPrint;		;
	pop si			;
noPrintNum:			;
	inc si			;
	loop chkNumLoop		; decrements CX when looping
				;
; ----------------------------- ;	
; Print the title for Chars	;
	mov ah, 09h		;
	mov dx, ttlChars	; CHARACTERS header
	int 21h			; Write String
				;
	mov si, 0080h		; Address of the COUNT of command-line bytes
	mov cx, [si]		; Count of command-line bytes
	xor ch, ch		; ...don't need/want this
	mov si, 0082h 		; put the address of chars in SI
chkCharLoop:			;
	mov bl, [si]		; move the current byte into BL
	call isLowerChar	; check for Char
	cmp bh, 1h		; if not a char...
	je printChar		; 
	call isUpperChar	;
	cmp bh, 1h		;
	jne noPrintChar		;
printChar:			; else
	push si			; 
	call doPrint;		;
	pop si			;
noPrintChar:			;
	inc si			;
	loop chkCharLoop	; decrements CX when looping
				;
; ----------------------------- ;	
; Print the title for Punct.	;
	mov ah, 09h		;
	mov dx, ttlPunctuation	; PUNCTUATION header
	int 21h			; Write String
				;
	mov si, 0080h		; Address of the COUNT of command-line bytes
	mov cx, [si]		; Count of command-line bytes
	xor ch, ch		; ...don't need/want this
	mov si, 0082h 		; put the address of chars in SI
chkPunctLoop:			;
	mov bl, [si]		; move the current byte into BL
	call isLowerChar	; check for Char
	cmp bh, 1h		; if not a char...
	je  noPrintPunct	;
	call isUpperChar	; check for Upper char
	cmp bh, 1h		;
	je  noPrintPunct	;
	call isANum		; check for NUM
	cmp bh, 1h		; if not a num...
	je noPrintPunct		;
printPunct:			; All checks failed, it's PUNCT
	push si			; 
	call doPrint;		;
	pop si			;
noPrintPunct:			;
	inc si			;
	loop chkPunctLoop	; decrements CX when looping
				; ***************************
	int 20h			; ******* DROP TO DOS *******
; ----------------------------- ; ***************************
doUsage:			;
	mov ah, 09h		;
	mov dx, ttlUsage	;
	int 21h			; Print Usage Message
				; ***************************
	int 20h			; ******* DROP TO DOS *******
; ----------------------------- ; ***************************
isANum:				; Subroutine isANum();
	xor bh, bh		;
	cmp bl, 30h		;
	jl  notANum		; Numbers are between 0x30 and 0x39
	cmp bl, 39h		;
	jg  notANum		;
	mov bh, 1h		; TRUE
notANum:; or done		;
	ret			;
; ----------------------------- ;
isUpperChar:			; Subroutine isUpperChar();
	xor bh, bh		;
	cmp bl, 41h		;
	jl  notUpperChar	; Upper chars are between 0x41 and 0x5a
	cmp bl, 5ah		;
	jg  notUpperChar	;
	mov bh, 1h		; TRUE
notUpperChar:; or done		;
	ret			;
; ----------------------------- ;
isLowerChar:			; Subroutine isLowerChar();
	xor bh, bh		;
	cmp bl, 61h		;
	jl  notLowerChar	; Lower chars are between 0x61 and 0x7a
	cmp bl, 7ah		;
	jg  notLowerChar	;
	mov bh, 1h		; TRUE
notLowerChar:; or done		;
	ret			;
; ----------------------------- ;
doPrint:			; Subroutine doPrint
	mov si, printSpot	; put the byte in the STRING printing spot
	mov [si], bl		;
	mov ah, 09h		; ...
	mov dx, printSpot	; ...
	int 21h			; Print it
	ret			;

;--------------------[Print Spot]--------------------------------
printSpot: ; Transfer bytes here to print
	db 00, '$'		;
				;
;--------------------[HEADERS / TITLES]--------------------------
ttlChars:	db 0ah, 0dh, '[Characters]', 0ah, 0dh, 024h
ttlPunctuation:	db 0ah, 0dh, '[Punctuation]', 0ah, 0dh, 024h
ttlNumbers:	db 0ah, 0dh, '[Numbers]', 0ah, 0dh, 024h
ttlUsage:	db 0ah, 0dh,
		db 'Usage:', 0ah, 0dh, 09h, 'CHRGRP {some data to evaluate}$'

; Results
;C:\science\asm>CHRGRP T5h4!i3-s2%I1^sNeat
;
;[Numbers]
;54321
;[Characters]
;ThisIsNeat
;[Punctuation]
;!-%
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.