Hi,
I am trying to write a program that [blue] displays "05D9AJ6Z" on the screen.
Sorts the string into two separate strings, [black]numeric characters in one[/black], [red]alpha in the other.[/red] [/blue][purple]The sorting must be done by the program, not "hard-coded" into design. [/purple][red]Allocate two char arrays in the .data segment to hold the two groups of characters.[/red][green]Displays each of the sorted strings (i.e., displays 0596 and DAJZ). [/green]
Can somebody help me write this program???
Thanks,
Ami
Comments
: Hi,
:
: I am trying to write a program that [blue] displays "05D9AJ6Z" on the screen.
: Sorts the string into two separate strings, [black]numeric characters in one[/black], [red]alpha in the other.[/red] [/blue][purple]The sorting must be done by the program, not "hard-coded" into design. [/purple][red]Allocate two char arrays in the .data segment to hold the two groups of characters.[/red][green]Displays each of the sorted strings (i.e., displays 0596 and DAJZ). [/green]
:
: Can somebody help me write this program???
:
: Thanks,
: Ami
[green]
First off get the obvious stuff out of the way and that is numbers are 30h-39h, and letters are 41h-5ah and 61-7ah. Next how are we going to detect a end of string? Maybe asciiz or some other character?
Code would probably look like this...
[code]
;use NASM
mov si, offset source_string ;the array to sort
mov di, offset numbers
mov bx, offset letters
Sort:
cmp byte [si], 0
je Done
cmp byte [si], 30h
jb Skip
cmp byte [si], 40h
jb Number
cmp byte [si], 41h
jb Skip
cmp byte [si], 5bh
jb Letter
cmp byte [si], 61h
jb Skip
cmp byte [si], 7bh
jb Letter
inc si ;
jmp Sort
Number:
movsb
jmp Sort
Letter:
lodsb
mov [bx], al
inc bx
jmp Sort
Skip:
inc si
jmp Sort
Done:
ret
numbers times 10 db 0 ;2 arrays 10 bytes in size
letters times 10 db 0
[/code]
Theres always a better way to do it but this was just off the top of my head. It might give you some ideas though. I haven't checked to see if this code has errors so I don't know for sure if it will work the way it should but I think it will. GoodLuck :-)
[/green]