Quantcast
Viewing all articles
Browse latest Browse all 152

finding smallest letter in a given array of characters

Hi,

I need to implement a function that finds the smallest letter in a given array of characters (according to its ASCII code), capitalizes it if necessary and then returns it. The function has the following input: an array of characters and the size of the array. Storing the result in dl.

I have this code but I can't get it to work properly

[code]
mov dl, 0x7f // initialize DL
mov dh, 0x61 // first value of small letter
mov ah, 0x20 // difference of small letter to capital letter
mov ecx, 0 // counter
mov ebx, arrayOfLetters // initialize array to ebx


FOR_EXPR:
cmp ecx, arraySize // loop from 0 to arraySize
jge END_FOR
mov al, byte ptr[ebx + ecx * 1] // reads the values of the array
cmp al, dl // compare max value to current item of the array
jl MIN_FOUND
inc ecx
jmp FOR_EXPR

END_FOR:
cmp dl, dh
jge CAPITALIZE

MIN_FOUND:
mov dl, al


CAPITALIZE:
sub dl, ah // capitalizes the letter
[/code]

The characters in the array is "cOmPuTeR"
When I try to run this code, I get the output "C" which is incorrect.(It should be "O") I figured that my code only goes through the first pass and doesn't loop so in my MIN_FOUND I added
[code]
MIN_FOUND:
mov dl, al
jmp FOR_EXPR
[/code]
but when I try to compile it, it won't run and gives me an unhandled exception.

I appreciate any input or suggestions thanks.

Viewing all articles
Browse latest Browse all 152

Trending Articles