Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 1st, 2005, 10:09 PM   #11
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
I basically used DI instead of EDI. I don't know what assembler you're using, but in NASM, [DI] means the value that's being pointed to by DI. If DI holds the memory address of the first character in the string, then [DI] basically is the value of the first character. The WORD keyword basically explicitly tells the compiler that we're working with a 16-bit value.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Feb 2nd, 2005, 1:04 AM   #12
oxyi
Newbie
 
Join Date: Jan 2005
Posts: 17
Rep Power: 0 oxyi is on a distinguished road
ahh roger that , let me tinker with it a bit, and report back what i have
thanks a lot mjordan2nd
oxyi is offline   Reply With Quote
Old Feb 2nd, 2005, 1:47 AM   #13
lostcauz
Hobbyist Programmer
 
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 4 lostcauz is on a distinguished road
Here's another using MASM.
; Count vowels, MASM 
; compiled using "console assemble and link" in Qeditor
.486                                    
.model flat, stdcall                    
option casemap :none                   
 
include \masm32\include\windows.inc    
include \masm32\macros\macros.asm       
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib

.data
    str1 db "aeiouAEIOU", 0
    str2 db "coUntsomevowEls", 0
    
.code          
             
start:   
    mov ecx, offset str1     ; load vowels
    mov edx, offset str2     ; load string
    xor esi, esi             ; zero vowel position counter
    xor edi, edi             ; zero string position counter
    xor ebx, ebx             ; number of vowels in word
l1: mov al, [ecx+esi]        ; begin loop, update vowel position
    cmp al, [edx+edi]        ; update string position
    jne @f                   ; not a vowel
    inc ebx                  ; is a vowel, count it
@@: inc esi                  ; increment vowel array position
    test al, al              ; check for terminator
    jne l1                   ; check all vowels
    inc edi                  ; next letter in word being checked
    cmp edi, [sizeof str2-1] ; test for end of string
    je  @f                   ; end of string
    xor esi, esi             ; reset vowel position counter
    jmp l1                   ; loop
@@: print str$(ebx)          ; print result to console
    exit
    
end start
__________________
-- lostcauz

Stepped in what?...
Behind whose barn?...
I didn't even know they had a cow!
lostcauz is offline   Reply With Quote
Old Feb 2nd, 2005, 10:20 PM   #14
oxyi
Newbie
 
Join Date: Jan 2005
Posts: 17
Rep Power: 0 oxyi is on a distinguished road
what is the difference between MASM and Microsoft Visual .Net,
because the way you coded is very different from what MJordan2nd wrote.

when I try something like

str1 db "aeiouAEIOU", 0
str2 db "coUntsomevowEls", 0

in visual.net, it gives me some kidn error.. is there a different syntex ?

Is MASM for like more advanced assembly coder? Thanks !

Last edited by oxyi; Feb 2nd, 2005 at 10:27 PM.
oxyi is offline   Reply With Quote
Old Feb 2nd, 2005, 10:23 PM   #15
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Well, the idea is the same. He's using a string that stores all the vowels and looping through it, checking each time. His way is definitely more elegant than mine.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Old Feb 2nd, 2005, 10:30 PM   #16
oxyi
Newbie
 
Join Date: Jan 2005
Posts: 17
Rep Power: 0 oxyi is on a distinguished road
Yap i got his idea, but was having problem implementing that.

So he store the all vowels in a string, then compare the vowels with a given string.
but I was having problem of putting

str1 db "aeiouAEIOU", 0 into the way you coded,
and i don't really get whats [edx+edi] does.

Btw thanks for a very nice commented code, it helps a lot
oxyi is offline   Reply With Quote
Old Feb 3rd, 2005, 3:32 AM   #17
lostcauz
Hobbyist Programmer
 
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 4 lostcauz is on a distinguished road
MASM is the Microsoft assembler. http://www.masm32.com/

Concerning [edx+edi], notice before entering the loop I xor'ed some registers with themselves. This sets the register to zero. I also pointed ecx and edx to the beginning of the 2 string arrays. ecx is pointing to the first character of the vowel array or 'a'. edx points to the first character in the other string which is 'c'. So when you first enter the loop, ecx is pointing to the first character (index zero) + esi, which is equal to zero, therefore resulting in the character 'a'. Since edi is also zero the same is true for edx. It points to the first character, 'c'.

After passing through the loop notice esi is incremented until the end of the vowel string. Now we are able to move to the next character in our other string. After incrementing edi the statement [edx+edi] may be broken down to [beginning of array + 1] which of course is 'o'. esi is reset to zero and we loop through the vowels once more. Since 'o' is a vowel, the vowel counting variable will be incremented. In this case I used ebx.
__________________
-- lostcauz

Stepped in what?...
Behind whose barn?...
I didn't even know they had a cow!
lostcauz is offline   Reply With Quote
Old Feb 4th, 2005, 4:12 AM   #18
oxyi
Newbie
 
Join Date: Jan 2005
Posts: 17
Rep Power: 0 oxyi is on a distinguished road
Ahhh got it, thanks Lostcauz !!

Very nice explaination
oxyi is offline   Reply With Quote
Old Feb 8th, 2005, 12:17 AM   #19
oxyi
Newbie
 
Join Date: Jan 2005
Posts: 17
Rep Power: 0 oxyi is on a distinguished road
Hi,

I am doing binary search now. But have some question doing so.

If i remembered how to do binary search correctly, it is like,
given a key in a pre-sorted array, then repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise narrow it to the upper half. Repeatedly check until the value is found or the interval is empty.

Now to the actualy code of implentation.

But I am not sure how do i go about doing this,



void binarySearch(apvector <int> &array, int lowerbound, int upperbound, int key)
{
       int position;
       int comparisonCount = 1;     //variable used to count the comparisons.

       // calculate the first search position.
       position = ( lowerbound + upperbound) / 2;

       while((array[position] != key) && (lowerbound <= upperbound))
       {
              comparisonCount++;
              if (array[position] > key)                // if the value in the search position..
             {                                                       // is greater than the number for ?/b>
                    upperbound = position - 1;    // which we are searching, change ..
             }                                                       // upperbound to the search position?/b>
             else                                                 // minus one.
            {                                                        // Else, change lowerbound to search..
                   lowerbound = position + 1;     // position plus one.
             }
             position = (lowerbound + upperbound) / 2;
       }
      if (lowerbound < = upperbound)
      {
            cout<< "The binary search found the number after " << comparisonCount 
                   << " comparisons.\n";
            cout<< "The number was found in array subscript "<< position<<endl<<endl;      
       }      
       else
             cout<< "Sorry, the number is not in this array.  The binary search made "
                   <<comparisonCount << " comparisons.";
       return;
}


so far, i got this,

int  binarySearch(int *array, int _size, int key, int *count)
{
	// isFound is the boolean result of search.
	int isFound=0;
	__asm {
	
	  push esi 
	  push edi
      push eax 
      push ebx 
      push ecx
	  push edx

	  mov esi, array //esi is the address of the input array
	  mov edi, count

My problem is, im not sure how would i go about divide the esi into half and
compared the value thats in there , or store the upperbound or lowerbound..

thanks again
oxyi is offline   Reply With Quote
Old Feb 8th, 2005, 7:51 PM   #20
oxyi
Newbie
 
Join Date: Jan 2005
Posts: 17
Rep Power: 0 oxyi is on a distinguished road
I kinda knew how to do it, but how would u
take a floor of a number, say 7/3 = 2.5, , but I only want 2 ?

because I want to find the middle of the array,
then somehow determine the end of the array, but
I am not quite sure how to accomplish that? anyone ?
oxyi is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:56 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC