Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #14808 > unrolled thread

A binary search algorithm that searches for an element similar to the key

Started bypozz <pozzugno@gmail.com>
First post2011-12-21 00:13 +0100
Last post2012-01-25 16:44 -0800
Articles 20 on this page of 64 — 18 participants

Back to article view | Back to comp.lang.c


Contents

  A binary search algorithm that searches for an element similar to the key pozz <pozzugno@gmail.com> - 2011-12-21 00:13 +0100
    Re: A binary search algorithm that searches for an element similar to the key Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-21 00:14 +0000
      Re: A binary search algorithm that searches for an element similar to the key pozz <pozzugno@gmail.com> - 2011-12-21 06:26 -0800
        Re: A binary search algorithm that searches for an element similar to the key Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-21 21:04 +0000
          Re: A binary search algorithm that searches for an element similar to the key pozz <pozzugno@gmail.com> - 2011-12-21 23:59 -0800
            Re: A binary search algorithm that searches for an element similar to the key Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-22 12:02 +0000
              Re: A binary search algorithm that searches for an element similar to the key pozz <pozzugno@gmail.com> - 2011-12-22 05:48 -0800
                Re: A binary search algorithm that searches for an element similar to the key Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-22 19:24 +0000
          Re: A binary search algorithm that searches for an element similar to the key pozz <pozzugno@gmail.com> - 2011-12-22 00:08 -0800
            Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-22 08:49 +0000
    Re: A binary search algorithm that searches for an element similar to the key Barry Schwarz <schwarzb@dqel.com> - 2011-12-20 21:27 -0800
    Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-21 01:01 -0800
      Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-21 04:36 -0800
        Re: A binary search algorithm that searches for an element similar to the key Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-12-21 12:49 +0000
        Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-21 19:12 +0000
        Re: A binary search algorithm that searches for an element similar to the key Keith Thompson <kst-u@mib.org> - 2011-12-21 13:37 -0800
          Re: A binary search algorithm that searches for an element similar to the key gazelle@shell.xmission.com (Kenny McCormack) - 2011-12-21 23:37 +0000
          Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 11:25 -0800
            Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-27 20:13 +0000
              Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 13:25 -0800
                Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-27 22:14 +0000
                  Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 15:12 -0800
                    Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-28 00:09 +0000
                      Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 16:22 -0800
                        Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-28 03:03 +0000
              Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-27 13:51 -0800
                Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-27 22:14 +0000
            Re: A binary search algorithm that searches for an element similar to the key Keith Thompson <kst-u@mib.org> - 2011-12-27 14:53 -0800
        Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-23 19:45 +0100
          Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-24 06:45 +0100
            Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-24 09:52 +0100
            Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-24 16:37 +0100
              Re: A binary search algorithm that searches for an element similar to the key hopcode <hopcode@nulnulul.de> - 2011-12-24 19:11 +0100
                Re: A binary search algorithm that searches for an element similar to the key Nathan <nathancbaker@gmail.com> - 2011-12-24 12:20 -0800
        Re: A binary search algorithm that searches for an element similar to the key Nick Keighley <nick_keighley_nospam@hotmail.com> - 2011-12-28 03:21 -0800
          Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-28 04:01 -0800
            Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-28 18:17 +0000
              Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-28 16:58 -0800
                Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-29 00:43 +0000
                  Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-28 18:16 -0800
                    Re: A binary search algorithm that searches for an element similar to the key Keith Thompson <kst-u@mib.org> - 2011-12-28 18:28 -0800
                      Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-28 18:39 -0800
                        Re: A binary search algorithm that searches for an element similar to the key Keith Thompson <kst-u@mib.org> - 2011-12-28 19:00 -0800
                          Re: A binary search algorithm that searches for an element similar to the key Geoff <geoff@invalid.invalid> - 2011-12-28 22:04 -0800
                            Re: A binary search algorithm that searches for an element similar to the key pacman@kosh.dhis.org (Alan Curry) - 2011-12-29 07:50 +0000
                            Re: A binary search algorithm that searches for an element similar to the key Seebs <usenet-nospam@seebs.net> - 2011-12-29 18:50 +0000
                              Re: A binary search algorithm that searches for an element similar to the key Patrick Scheible <kkt@zipcon.net> - 2011-12-29 12:52 -0800
                                Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-02 02:45 -0800
                                  Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-03 16:30 -0800
                          Re: A binary search algorithm that searches for an element similar to the key gazelle@shell.xmission.com (Kenny McCormack) - 2011-12-29 10:00 +0000
                      Re: A binary search algorithm that searches for an element similar to the key gazelle@shell.xmission.com (Kenny McCormack) - 2011-12-29 09:58 +0000
    Re: A binary search algorithm that searches for an element similar to the key 88888 Dihedral <dihedral88888@googlemail.com> - 2011-12-21 06:44 -0800
      Re: A binary search algorithm that searches for an element similar to the key John Tsiombikas <nuclear@member.fsf.org> - 2011-12-21 17:27 +0000
    Re: A binary search algorithm that searches for an element similar to  the key pete <pfiland@mindspring.com> - 2011-12-21 17:54 -0500
    Re: A binary search algorithm that searches for an element similar to the key Peter Nilsson <airia@acay.com.au> - 2011-12-21 23:09 -0800
      Re: A binary search algorithm that searches for an element similar to the key pozz <pozzugno@gmail.com> - 2011-12-22 00:14 -0800
      Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-22 09:50 +0100
      Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-22 18:23 +0100
    Re: A binary search algorithm that searches for an element similar to  the key pete <pfiland@mindspring.com> - 2011-12-22 06:56 -0500
    Re: A binary search algorithm that searches for an element similar to the key pacman@kosh.dhis.org (Alan Curry) - 2011-12-22 21:59 +0000
    Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-25 11:54 +0100
      Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-25 15:45 +0100
        Re: A binary search algorithm that searches for an element similar to the key "io_x" <a@b.c.invalid> - 2011-12-29 09:06 +0100
    Re: A binary search algorithm that searches for an element similar to the key Tim Rentsch <txr@alumni.caltech.edu> - 2012-01-25 16:44 -0800

Page 2 of 4 — ← Prev page 1 [2] 3 4  Next page →


#15047

FromSeebs <usenet-nospam@seebs.net>
Date2011-12-27 22:14 +0000
Message-ID<slrnjfkgl3.1pok.usenet-nospam@guild.seebs.net>
In reply to#15043
On 2011-12-27, 88888 Dihedral <dihedral88888@googlemail.com> wrote:
> We don't have to argue about chief technical officer's views
> and chief financial officer's views.  

> CTO and CFO normally think quite differently. 

This has nothing to do with anything.

I think at this point I'm obliged to give up.  You've not yet made a lucid
comment about C that I'm aware of.  You went on at some length about needing
a "division library" for ARM, but are apparently completely unaware of how
actual compilers for ARM handle division.  You regularly advocate taking
perfectly functional code which can be easily maintained and will work on any
known computer, and mangling it into something harder to maintain which works
on only some computers and isn't even demonstrably faster.  You appear to have
permanently fixated on the state of the art in compilers in the 1970s, and
you constantly brag about being well-paid and in charge of things and how you
want your skills to be rare.

This is the opposite of competence.

Good software development should not be focused on trying to show off or
impress people, but on making software that actually works and does its job
well.

It should not be focused on offering vague and irrelevant platitudes, talking
at great length about irrelevant trivia and pretending they're highly
significant, and trying to impress everyone with how much more money you earn
than other people.  Who CARES?

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#15058

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-12-27 15:12 -0800
Message-ID<9772891.799.1325027526699.JavaMail.geo-discussion-forums@preg20>
In reply to#15047
Seebs於 2011年12月28日星期三UTC+8上午6時14分23秒寫道:
> On 2011-12-27, 88888 Dihedral <dihedr...@googlemail.com> wrote:
> > We don't have to argue about chief technical officer's views
> > and chief financial officer's views.  
> 
> > CTO and CFO normally think quite differently. 
> 
> This has nothing to do with anything.
> 
> I think at this point I'm obliged to give up.  You've not yet made a lucid
> comment about C that I'm aware of.  You went on at some length about needing
> a "division library" for ARM, but are apparently completely unaware of how
> actual compilers for ARM handle division. 

Are you kidding about Keil C-compiler that was bought by ARM ?

You can mix assembly with C from the products of the same company in ARM7-9-10-11 and 8051. 

Because many general instructions in many CPU are actually executed by slow
micro-codes especially  in 8051 and  8052 of the 196X AB register architecture , therefore  the slowest part of the instructions might need to be optimized by professionals in applications of various parameters.

The integer  division in the x86 family does improve a lot in these years. 




 

[toc] | [prev] | [next] | [standalone]


#15064

FromSeebs <usenet-nospam@seebs.net>
Date2011-12-28 00:09 +0000
Message-ID<slrnjfkn3d.1t95.usenet-nospam@guild.seebs.net>
In reply to#15058
On 2011-12-27, 88888 Dihedral <dihedral88888@googlemail.com> wrote:
> Are you kidding about Keil C-compiler that was bought by ARM ?

No.  I'm not talking about it at all.  There is no reference in any way to
that.

I am talking about the fact that there is NO NEED WHATSOEVER for a "division
library" for ARM, because whether or not any given CPU has a divider, *the
C compilers already take care of this*.

> Because many general instructions in many CPU are actually executed by slow
> micro-codes especially  in 8051 and  8052

This sounds almost meaningful, but I'm coming to think it's just word salad.

You seem deeply obsessed with the notion that you can somehow hugely improve
things by outsmarting compilers, but the net result is that so far as I can
tell you're less able to produce an actual program which does a thing than
the average second or third year CS student.

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#15066

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-12-27 16:22 -0800
Message-ID<23742229.403.1325031772405.JavaMail.geo-discussion-forums@prdv33>
In reply to#15064
Seebs於 2011年12月28日星期三UTC+8上午8時09分12秒寫道:
> On 2011-12-27, 88888 Dihedral <dihedr...@googlemail.com> wrote:
> > Are you kidding about Keil C-compiler that was bought by ARM ?
> 
> No.  I'm not talking about it at all.  There is no reference in any way to
> that.
> 
> I am talking about the fact that there is NO NEED WHATSOEVER for a "division
> library" for ARM, because whether or not any given CPU has a divider, *the
> C compilers already take care of this*.
> 
> > Because many general instructions in many CPU are actually executed by slow
> > micro-codes especially  in 8051 and  8052
> 
> This sounds almost meaningful, but I'm coming to think it's just word salad.
> 
> You seem deeply obsessed with the notion that you can somehow hugely improve
> things by outsmarting compilers, but the net result is that so far as I can
> tell you're less able to produce an actual program which does a thing than
> the average second or third year CS student.
> 

Could you do RSA 1024 bit encoding and decoding in arm7 without checking 
the possibilities to improve by assembly with C ?

If you are selling compilers , then I'll post some problems
with a specified platform for you to recommend the compiler to 
be tested here. 


  



  

[toc] | [prev] | [next] | [standalone]


#15071

FromSeebs <usenet-nospam@seebs.net>
Date2011-12-28 03:03 +0000
Message-ID<slrnjfl161.21nc.usenet-nospam@guild.seebs.net>
In reply to#15066
On 2011-12-28, 88888 Dihedral <dihedral88888@googlemail.com> wrote:
> Could you do RSA 1024 bit encoding and decoding in arm7 without checking 
> the possibilities to improve by assembly with C ?

This is a question which has nothing to do with the assertion I was
criticizing.

And really, this is why I'm gonna go ahead and killfile you.  You are illucid.
You can't respond to a question or assertion; you sort of wander off in a haze
of buzzwords and unrelated assertions.

The assertion you made was that we needed a division library for ARM because
the chip doesn't have a divider.  In fact, that doesn't mean we need a
"division library", it just means that the compiler vendors have to do
something behind the scenes to make division work.

> If you are selling compilers , then I'll post some problems
> with a specified platform for you to recommend the compiler to 
> be tested here. 

I'm not selling compilers.

I'm not even asserting that it is in general impossible to gain a benefit from
hand-tuning things; I'm just asserting that you seem to leap to it as a course
of action without a moment's thought as to the costs and benefits.

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#15044

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-12-27 13:51 -0800
Message-ID<22056707.297.1325022672175.JavaMail.geo-discussion-forums@prol32>
In reply to#15041
Seebs於 2011年12月28日星期三UTC+8上午4時13分54秒寫道:
> On 2011-12-27, 88888 Dihedral <dihedr...@googlemail.com> wrote:
> > I love those jobs that ordinary low paid programmers can't do
> > that is how I got paid well.
> 
> If your code and writing is any indication, this is a terrifying concept.
> 
> > It  is  not the  language used but just 
> > the difficulties and talents required to complete tough tasks 
> > to get the rewards must be rare.
> 
> Huh.  I would much rather put the hard work into building a robust and
> maintainable design such that the skills needed to keep it running aren't
> rare.
> 

To keep of the workers on a factory to chunk out profits
for the employers is different from controlling those machinares
and techniques to install the assembly lines. 

> The goal here is not to show off, it's to do the best work possible.
> Maintainable code is better than flashy code.
> 

I agree with you for the requirements of  workers
on the mass production factories. 





> -s
> -- 
> Copyright 2011, all wrongs reversed.  Peter Seebach / usenet...@seebs.net
> http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
> http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
> I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#15046

FromSeebs <usenet-nospam@seebs.net>
Date2011-12-27 22:14 +0000
Message-ID<slrnjfkgos.1pok.usenet-nospam@guild.seebs.net>
In reply to#15044
On 2011-12-27, 88888 Dihedral <dihedral88888@googlemail.com> wrote:
> Seebs??? 2011???12???28????????????UTC+8??????4???13???54????????????
>> Huh.  I would much rather put the hard work into building a robust and
>> maintainable design such that the skills needed to keep it running aren't
>> rare.

> To keep of the workers on a factory to chunk out profits
> for the employers is different from controlling those machinares
> and techniques to install the assembly lines. 

This is again illucid.

>> The goal here is not to show off, it's to do the best work possible.
>> Maintainable code is better than flashy code.

> I agree with you for the requirements of  workers
> on the mass production factories. 

This has nothing to do with workers in factories.  This is how you turn
software development from a bunch of prima donnas who don't actually do good
work into a career worthy of some degree of respect.

Flashy code *does not actually work better*.  Fooling around with stuff like
that is okay recreation, but if someone's paying me for software, I try to
deliver something which does its job, not something that shows off why I'm
an IOCCC judge.

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#15051

FromKeith Thompson <kst-u@mib.org>
Date2011-12-27 14:53 -0800
Message-ID<ln8vlx1v9z.fsf@nuthaus.mib.org>
In reply to#15036
88888 Dihedral <dihedral88888@googlemail.com> writes:
> Keith Thompson於 2011年12月22日星期四UTC+8上午5時37分25秒寫道:

Are those Chinese ideographs?  Be aware that most users aren't going to
be able to read them.

>> 88888 Dihedral <dihedr...@googlemail.com> writes:
>> [...]
>> > A program in C code within 20 lines should be coded in assembly easily
>> > for professionals in any 32 bit cpu easily.
>> 
>> But why on Earth would anyone want to waste the time doing so?
> 
> I love those jobs that ordinary low paid programmers can't do
> that is how I got paid well. It  is  not the  language used but just 
> the difficulties and talents required to complete tough tasks 
> to get the rewards must be rare.

If you're not going to answer my question, please don't post your
ramblings as a followup to the article in which I asked it.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
    Will write code for food.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#14924

From"io_x" <a@b.c.invalid>
Date2011-12-23 19:45 +0100
Message-ID<4ef4cb7b$0$1387$4fafbaef@reader2.news.tin.it>
In reply to#14825
NGs  comp.lang.c,alt.lang.asm
"88888 Dihedral" <dihedral88888@googlemail.com> ha scritto nel messaggio
news:16923526.318.1324470963080.JavaMail.geo-discussion-forums@prez15...
>I wrote a binary search in assembly in 386 20 years ago.
>
> This is trivial. There were EAX, EBX, ECX, EDX and ESI, EDI which are 6
> 32 bit general registers and a stack that can be pushed and popped.
>
> I suggest you store the array starting address  in ESI and use EDI as a
> general
> pointer in the heap.
>
> A program in C code within 20 lines should be coded in assembly easily for
> professionals in any 32 bit cpu easily.
>
> I'll warn  any programmer that  dare to use  any lousy name of any variable
> to be a pointer witout ptr* or p* in the name  under my  supervision.
>
>
> Then I'll ask the programmer to convert the program into a specified assembly
> to  prove the programmer is not stealing codes form others and faking to be
> his own works.

this is the implemention to the one in k&r2 so it is not my work 100%
i had one try on that in .asm. I use RosAsm with one my home
made asm macro language; i don't know if it is right...
i like all that, these simple little instruction that goes togheter...
fuck all hlls languages

; return  -10 error, 0 not find, address of the found element in array
; would be like the C library one, with the only difference return -10 for error
; and use type without UB, and not admit index  with  (i32) indx<0
;u8*  __stdcall
;binSearchR(u8* InOutPKey, u8* InBase,
;           u32 nElmBase,  u32 SizeElmBase, i32  cmp(u8* elm1, u8*  elm2) );
; 0k, 4k, 8j, 12i, 16b, 20ra, 24InOutKey, 28InBase,  32P_nElmBase,
36P_SizeElmBase, 40P_cmp
binSearchR:
          push    ebx
          push    esi
          push    edi
          push    ebp
          push    ebp
;int3
          cmp     dword[esp+  24],  0
          je      .e
          cmp     dword[esp+  28],  0
          je      .e
          cmp     dword[esp+  36],  0
          jle     .e
          cmp     dword[esp+  40],  0
          je      .e
          cmp     dword[esp+  32],  0
          je      .nf
          jl      .e
          jmp     short  .1
.nf:      mov     eax,  0
          clc
          jmp     short  .z
.e:       mov     eax,  -10
          stc
          jmp     short  .z
.1:       mov     esi,  0
          mov     edi,  dword[esp+  32]
          dec     edi
          mov     ebx,  dword[esp+  40]
.2:       cmp     esi,  edi
          ja      .nf
          mov     ebp,  esi
          add     ebp,  edi
          jc      .e
          shr     ebp,  1       ; k=(i+j)/2
          mov     eax,  dword[esp+  36]
          mul     ebp
          cmp     edx,  0
          jne     .e
          mov     edx,  dword[esp+  24]
          add     eax,  dword[esp+  28]
          mov     dword[esp+  0],  eax
          push    edx
          push    eax
          call    ebx
          add     esp,  8
          cmp     eax,  0
          jge     .3
          mov     edi,  ebp
          sub     edi,  1
          jmp     short  .2
.3:       cmp     eax,  0
          jle     .4
          mov     esi,  ebp
          add     esi,  1
          jmp     short  .2
.4:       mov     eax,  dword[esp+  0]
          clc
.z:
          pop     ebp
          pop     ebp
          pop     edi
          pop     esi
          pop     ebx
          ret     20


this is the C program to experiment the above

#include <stdio.h>
#include <stdlib.h>
#define u32 unsigned
#define i32 int
#define u8  unsigned char
#define R   return
#define P   printf

u8*  __stdcall
binSearchR(u8* InOutPKey,    u8* InBase,
           u32 nElmBase, u32 SizeElmBase, i32  cmp(u8* elm1, u8*  elm2) );

i32 cmpu32(u8*  elm1,  u8*  elm2)
{     if(*elm1>*elm2)  R  -1;
 else if(*elm1<*elm2)  R   1;
 else                  R   0;
}

int  main(void)
{u32  v[]={0, 2, 5, 7, 8, 8, 9, 13, 20},  val=13;
 u8  *r;

 r=binSearchR((u8*)&val, (u8*)  v, 9, sizeof(u32), cmpu32);
 if(r!=0) P("r=%p find=%u\n", (void*)r, *r);

 R  0;
}

this is the origin like RosAsm .dll
----------------------------
PREPARSE MACRO2D

section DATA

hInstance   dd   0

;                9
arrayInt    dd   0,2,4,5,8,8,9,10, 11

export      binSearchR

section TEXT


; return  -10 error, 0 not find, address of the found element in array
; would be like the C one, with the only difference return -10 for error
;u8*  __stdcall
;binSearchR(u8* InOutPKey, u8* InBase,
;           u32 nElmBase,  u32 SizeElmBase, i32  cmp(u8* elm1, u8*  elm2) );
; 0k, 4k, 8j, 12i, 16b, 20ra, 24InOutKey, 28InBase,  32P_nElmBase,
36P_SizeElmBase, 40P_cmp
binSearchR:
<b,i,j,k,k
     ;int3
     ^24==0#.e|^28==0#.e |^36<=0?#.e
     ^40==0#.e|^32==0#.nf|<?#.e|#.1
.nf: a=0  |clc|#.z
.e:  a=-10|stc|#.z
.1:  i=0 |j=^32|--j|b=^40
.2:  i>j#.nf
     k=i |k+=j  |jc .e  |k>>=1     ; k=(i+j)/2
     a=^36|mul k|r!=0#.e|r=^24|a+=^28|^0=a
     b<(a,r)|a<0!?#.3|j=k|j-=1|#.2
.3:          a>0!?#.4|i=k|i+=1|#.2
.4:  a=^0|clc
.z:
>b,i,j,k,k
ret 20

Main:
    mov eax D$esp+8
    mov D$hInstance eax
    mov eax 1
ret 12




[toc] | [prev] | [next] | [standalone]


#14941

From"io_x" <a@b.c.invalid>
Date2011-12-24 06:45 +0100
Message-ID<4ef5661d$0$1375$4fafbaef@reader2.news.tin.it>
In reply to#14924
"io_x" <a@b.c.invalid> ha scritto nel messaggio 
news:4ef4cb7b$0$1387$4fafbaef@reader2.news.tin.it...
> NGs  comp.lang.c,alt.lang.asm
> "88888 Dihedral" <dihedral88888@googlemail.com> ha scritto nel messaggio
> news:16923526.318.1324470963080.JavaMail.geo-discussion-forums@prez15...
>>I wrote a binary search in assembly in 386 20 years ago.
>>
>> This is trivial. There were EAX, EBX, ECX, EDX and ESI, EDI which are 6
>> 32 bit general registers and a stack that can be pushed and popped.
>>
>> I suggest you store the array starting address  in ESI and use EDI as a
>> general
>> pointer in the heap.
>>
>> A program in C code within 20 lines should be coded in assembly easily for
>> professionals in any 32 bit cpu easily.
>>
>> I'll warn  any programmer that  dare to use  any lousy name of any variable
>> to be a pointer witout ptr* or p* in the name  under my  supervision.
>>
>>
>> Then I'll ask the programmer to convert the program into a specified assembly
>> to  prove the programmer is not stealing codes form others and faking to be
>> his own works.
>
> this is the implemention to the one in k&r2 so it is not my work 100%
> i had one try on that in .asm. I use RosAsm with one my home
> made asm macro language; i don't know if it is right...
> i like all that, these simple little instruction that goes togheter...
> fuck all hlls languages
>
> ; return  -10 error, 0 not find, address of the found element in array
> ; would be like the C library one, with the only difference return -10 for 
> error
> ; and use type without UB, and not admit index  with  (i32) indx<0
> ;u8*  __stdcall
> ;binSearchR(u8* InOutPKey, u8* InBase,
> ;           u32 nElmBase,  u32 SizeElmBase, i32  cmp(u8* elm1, u8*  elm2) );
> ; 0k, 4k, 8j, 12i, 16b, 20ra, 24InOutKey, 28InBase,  32P_nElmBase,
> 36P_SizeElmBase, 40P_cmp
> binSearchR:
>          push    ebx
>          push    esi
>          push    edi
>          push    ebp
>          push    ebp
> ;int3
>          cmp     dword[esp+  24],  0
>          je      .e
>          cmp     dword[esp+  28],  0
>          je      .e
>          cmp     dword[esp+  36],  0
>          jle     .e
>          cmp     dword[esp+  40],  0
>          je      .e
>          cmp     dword[esp+  32],  0
>          je      .nf
>          jl      .e
>          jmp     short  .1
> .nf:      mov     eax,  0
>          clc
>          jmp     short  .z
> .e:       mov     eax,  -10
>          stc
>          jmp     short  .z
> .1:       mov     esi,  0
>          mov     edi,  dword[esp+  32]
>          dec     edi
>          mov     ebx,  dword[esp+  40]
> .2:       cmp     esi,  edi
>          ja      .nf
>          mov     ebp,  esi
>          add     ebp,  edi
>          jc      .e
>          shr     ebp,  1       ; k=(i+j)/2
>          mov     eax,  dword[esp+  36]
>          mul     ebp
>          cmp     edx,  0
>          jne     .e
>          mov     edx,  dword[esp+  24]
>          add     eax,  dword[esp+  28]
>          mov     dword[esp+  0],  eax
>          push    edx
>          push    eax
>          call    ebx
>          add     esp,  8
>          cmp     eax,  0
>          jge     .3
>          mov     edi,  ebp
>          sub     edi,  1
>          jmp     short  .2
> .3:       cmp     eax,  0
>          jle     .4
>          mov     esi,  ebp
>          add     esi,  1
>          jmp     short  .2
> .4:       mov     eax,  dword[esp+  0]
>          clc
> .z:
>          pop     ebp
>          pop     ebp
>          pop     edi
>          pop     esi
>          pop     ebx
>          ret     20

the above is wrong
i rewrote it
in
; return  -10 error, 0 not find, address of the found element in array
; would be like the C one, with the only difference return -10 for error
;u8*  __stdcall
;binSearchR(u8* InOutPKey, u8* InBase,
;           u32 nElmBase,  u32 SizeElmBase, i32  cmp(u8* elm1, u8*  elm2) );
; 0k, 4k, 8j, 12i, 16b, 20ra, 24InOutKey, 28InBase,  32P_nElmBase,
36P_SizeElmBase, 40P_cmp
binSearchR:
          push    ebx
          push    esi
          push    edi
          push    ebp
          push    ebp
;int3
          cmp     dword[esp+  24],  0
          je      .e
          cmp     dword[esp+  28],  0
          je      .e
          cmp     dword[esp+  36],  0
          jle     .e
          cmp     dword[esp+  40],  0
          je      .e
          cmp     dword[esp+  32],  0
          je      .nf
          jl      .e
          jmp     short  .1
.nf:      mov     eax,  0
          clc
          jmp     short  .z
.e:       mov     eax,  -10
          stc
          jmp     short  .z
.1:       mov     esi,  0
          mov     edi,  dword[esp+  32]
          dec     edi
          mov     ebx,  dword[esp+  40]
.2:       cmp     esi,  edi
          jg      .nf
          mov     ebp,  esi
          add     ebp,  edi
          jc      .e
          shr     ebp,  1       ; k=(i+j)/2
          mov     eax,  dword[esp+  36]
          mul     ebp
          cmp     edx,  0
          jne     .e
          mov     edx,  dword[esp+  24]
          add     eax,  dword[esp+  28]
          jc      .e
          mov     dword[esp+  0],  eax
          push    edx
          push    eax
          call    ebx
          add     esp,  8
          cmp     eax,  0
          jle     .3
          mov     edi,  ebp
          sub     edi,  1
          jmp     short  .2
.3:       jz      .4
          mov     esi,  ebp
          add     esi,  1
          jmp     short  .2
.4:       mov     eax,  dword[esp+  0]
          clc
.z:
          pop     ebp
          pop     ebp
          pop     edi
          pop     esi
          pop     ebx
          ret     20

[toc] | [prev] | [next] | [standalone]


#14951

From"io_x" <a@b.c.invalid>
Date2011-12-24 09:52 +0100
Message-ID<4ef591f3$0$1377$4fafbaef@reader2.news.tin.it>
In reply to#14941
"io_x" <a@b.c.invalid> ha scritto nel messaggio
news:4ef5661d$0$1375$4fafbaef@reader2.news.tin.it...

this seems a little more slow than C library bsearch() function one

; return  -1 error, 0 not find, address of the found element in array
; would be like the C one, with the only difference return -1 for error
;u8*  __stdcall
;binSearchR(u8* InOutPKey, u8* InBase,
;           u32 nElmBase,  u32 SizeElmBase, i32  cmp(u8* elm1, u8*  elm2) );
; 0k, 4k, 8j, 12i, 16b, 20ra, 24InOutKey, 28InBase,  32P_nElmBase,
36P_SizeElmBase, 40P_cmp
binSearchR:
          push    ebx
          push    esi
          push    edi
          push    ebp
          push    ebp
;int3
          cmp     dword[esp+  24],  0
          je      .e
          cmp     dword[esp+  28],  0
          je      .e
          mov     edi,  dword[esp+  32]
          mov     ebx,  dword[esp+  40]
          cmp     dword[esp+  36],  0
          jle     .e
          cmp     edi,  0
          je      .nf
          mov     esi,  0
          jl      .e
          cmp     ebx,  0
          je      .e
          dec     edi
          jmp     short  .2
.nf:      xor     eax,  eax
          clc
          jmp     short  .z
.e:       xor     eax,  eax
          dec     eax
          stc
          jmp     short  .z
.2:       cmp     esi,  edi
          jg      .nf
          mov     ebp,  esi
          mov     eax,  dword[esp+  36]
          add     ebp,  edi
          shr     ebp,  1       ; k=(i+j)/2
          mul     ebp
          cmp     edx,  0
          jne     .e
          add     eax,  dword[esp+  28]
          mov     ecx,  dword[esp+  24]
          mov     dword[esp+  0],  eax
          jc      .e
          push    ecx
          push    eax
          call    ebx
          add     esp,  8
          cmp     eax,  0
          jle     .3
          dec     ebp
          mov     edi,  ebp
          jmp     short  .2
.3:       jz      .4
          inc     ebp
          mov     esi,  ebp
          jmp     short  .2
.4:       mov     eax,  dword[esp+  0]
          clc
.z:
          pop     ebp
          pop     ebp
          pop     edi
          pop     esi
          pop     ebx
          ret     20
-------------------
; return  -1 error, 0 not find, address of the found element in array
; would be like the C one, with the only difference return -1 for error
;u8*  __stdcall
;binSearchR(u8* InOutPKey, u8* InBase,
;           u32 nElmBase,  u32 SizeElmBase, i32  cmp(u8* elm1, u8*  elm2) );
; 0k, 4k, 8j, 12i, 16b, 20ra, 24InOutKey, 28InBase,  32P_nElmBase,
36P_SizeElmBase, 40P_cmp
binSearchR:
<b,i,j,k,k
     ;int3
     ^24==0#.e|^28==0#.e|j=^32  | b=^40 |^36<=0?#.e
     j==0#.nf |i=0|<?#.e|b==0#.e|--j|#.2
.nf: a^=a    |clc|#.z
.e:  a^=a|--a|stc|#.z
.2:  i>j?#.nf|k=i|a=^36|k+=j |k>>=1        ; k=(i+j)/2
     mul k|r#.e|a+=^28 |c=^24|^0=a|jc .e
     b<(a,c) |a>0!?#.3|--k|j=k|#.2
.3:               =#.4|++k|i=k|#.2
.4:  a=^0|clc
.z:
>b,i,j,k,k
ret 20
------------------------
C:>ba 100
r=0012FF3C find=13
r=0012FF3C find=13
r=00000000
myBsearch=0.000000
sum=460116
  bsearch=0.000000
sum=460116

C:>ba 1000
r=0012FF3C find=13
r=0012FF3C find=13
r=00000000
myBsearch=2.000000
sum=650808558
  bsearch=2.000000
sum=650808558

C:>ba 1500
r=0012FF3C find=13
r=0012FF3C find=13
r=00000000
myBsearch=5.000000
sum=-1984601096
  bsearch=5.000000
sum=-1984601096

C:>ba 2000
r=0012FF3C find=13
r=0012FF3C find=13
r=00000000
myBsearch=10.000000
sum=1373176982
  bsearch=9.000000
sum=1373176982


[toc] | [prev] | [next] | [standalone]


#14967

From"io_x" <a@b.c.invalid>
Date2011-12-24 16:37 +0100
Message-ID<4ef5f0d5$0$1386$4fafbaef@reader2.news.tin.it>
In reply to#14941
"io_x" <a@b.c.invalid> ha scritto nel messaggio 
news:4ef5661d$0$1375$4fafbaef@reader2.news.tin.it...

Buon Natale e
Felice 2012 

[toc] | [prev] | [next] | [standalone]


#14974

Fromhopcode <hopcode@nulnulul.de>
Date2011-12-24 19:11 +0100
Message-ID<jd54k4$l99$1@online.de>
In reply to#14967
Il 24.12.2011 16:37, io_x ha scritto:
> "io_x"<a@b.c.invalid>  ha scritto nel messaggio
> news:4ef5661d$0$1375$4fafbaef@reader2.news.tin.it...
>
> Buon Natale e
> Felice 2012
>

Frohe Weihnachten und
glückliches neues 2012

Cheers,

-- 
.:mrk[hopcode]
   .:x64lab:.
  group http://groups.google.com/group/x64lab
  site http://sites.google.com/site/x64lab

[toc] | [prev] | [next] | [standalone]


#14977

FromNathan <nathancbaker@gmail.com>
Date2011-12-24 12:20 -0800
Message-ID<888c6ab3-2b47-46e5-86e4-8eab7eb2e36f@f11g2000yql.googlegroups.com>
In reply to#14974
On Dec 24, 1:11 pm, hopcode <hopc...@nulnulul.de> wrote:
> Il 24.12.2011 16:37, io_x ha scritto:
>
> > "io_x"<a...@b.c.invalid>  ha scritto nel messaggio
> >news:4ef5661d$0$1375$4fafbaef@reader2.news.tin.it...
>
> > Buon Natale e
> > Felice 2012
>
> Frohe Weihnachten und
> glückliches neues 2012
>

Wishing a very Merry Christmas to all and have a Happy New Year!

Nathan.

[toc] | [prev] | [next] | [standalone]


#15090

FromNick Keighley <nick_keighley_nospam@hotmail.com>
Date2011-12-28 03:21 -0800
Message-ID<eb4027f7-c738-4f57-b85e-3bb2013e18ff@l19g2000yqc.googlegroups.com>
In reply to#14825
On Dec 21, 12:36 pm, 88888 Dihedral <dihedral88...@googlemail.com>
wrote:

> I wrote a binary search in assembly in 386 20 years ago.

oh goody.

> This is trivial. There were EAX, EBX, ECX, EDX and ESI, EDI which are 6
> 32 bit general registers and a stack that can be pushed and popped.

the tricky bit is the algorithm. Once you have the algorithm why not
code it in a HLL? A version written in C might actually run quicker
than your 20 year old assembler code because modern CPUs aren't 386s
and optimisers have got very good.

But trying to talk you out of your machine code obsession is simply a
waste of time.

<snip>

> A program in C code within 20 lines should be coded in assembly easily for
> professionals in any 32 bit cpu easily.

why bother?

> I'll warn  any programmer that  dare to use  any lousy name of any variable
> to be a pointer witout ptr* or p* in the name  under my  supervision.

we would part company pretty quickly. Next thing you'll go all
hungarian on me.

> Then I'll ask the programmer to convert the program into a specified assembly
> to  prove the programmer is not stealing codes form others and faking to be
> his own works.

this is just stupid

[toc] | [prev] | [next] | [standalone]


#15099

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-12-28 04:01 -0800
Message-ID<32714508.972.1325073684720.JavaMail.geo-discussion-forums@preg25>
In reply to#15090
Nick Keighley於 2011年12月28日星期三UTC+8下午7時21分19秒寫道:
> On Dec 21, 12:36 pm, 88888 Dihedral <dihedr...@googlemail.com>
> wrote:
> 
> > I wrote a binary search in assembly in 386 20 years ago.
> 
> oh goody.
> 
> > This is trivial. There were EAX, EBX, ECX, EDX and ESI, EDI which are 6
> > 32 bit general registers and a stack that can be pushed and popped.
> 
> the tricky bit is the algorithm. Once you have the algorithm why not
> code it in a HLL? A version written in C might actually run quicker
> than your 20 year old assembler code because modern CPUs aren't 386s
> and optimisers have got very good.
> 
> But trying to talk you out of your machine code obsession is simply a
> waste of time.
> 
> <snip>
> 
> > A program in C code within 20 lines should be coded in assembly easily for
> > professionals in any 32 bit cpu easily.
> 
> why bother?

I work in circuit designs by verilog and vhdl, too. 

Thus it is just personal habit  to think in hardware even in writing 
software. 

> 
> > I'll warn  any programmer that  dare to use  any lousy name of any variable
> > to be a pointer witout ptr* or p* in the name  under my  supervision.
> 
> we would part company pretty quickly. Next thing you'll go all
> hungarian on me.
> 
> > Then I'll ask the programmer to convert the program into a specified assembly
> > to  prove the programmer is not stealing codes form others and faking to be
> > his own works.
> 
> this is just stupid

Not really for those hardware designers. 

[toc] | [prev] | [next] | [standalone]


#15122

FromSeebs <usenet-nospam@seebs.net>
Date2011-12-28 18:17 +0000
Message-ID<slrnjfmlrc.2lac.usenet-nospam@guild.seebs.net>
In reply to#15099
On 2011-12-28, 88888 Dihedral <dihedral88888@googlemail.com> wrote:
> Thus it is just personal habit  to think in hardware even in writing 
> software. 

I suppose that, if you spent a lot of time training dogs, then needed to work
with a cat, you'd just think about it as though it were a dog, too.

>> > Then I'll ask the programmer to convert the program into a specified assembly
>> > to ??prove the programmer is not stealing codes form others and faking to be
>> > his own works.

>> this is just stupid

> Not really for those hardware designers. 

It's stupid because lots of programmers don't do assembly.  The test is
irrelevant.  It's like demanding that a poet be able to translate poetry
into German to prove that it's not plagiarized.

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#15142

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-12-28 16:58 -0800
Message-ID<18979294.42.1325120325069.JavaMail.geo-discussion-forums@prol32>
In reply to#15122
Seebs於 2011年12月29日星期四UTC+8上午2時17分57秒寫道:
> On 2011-12-28, 88888 Dihedral <dihedr...@googlemail.com> wrote:
> > Thus it is just personal habit  to think in hardware even in writing 
> > software. 
> 
> I suppose that, if you spent a lot of time training dogs, then needed to work
> with a cat, you'd just think about it as though it were a dog, too.
> 
> >> > Then I'll ask the programmer to convert the program into a specified assembly
> >> > to ??prove the programmer is not stealing codes form others and faking to be
> >> > his own works.
> 
> >> this is just stupid
> 
> > Not really for those hardware designers. 
> 
> It's stupid because lots of programmers don't do assembly.  The test is
> irrelevant.  It's like demanding that a poet be able to translate poetry
> into German to prove that it's not plagiarized.
> 

I don't work with programmers don't understand BIOS and OS very often. 

[toc] | [prev] | [next] | [standalone]


#15144

FromSeebs <usenet-nospam@seebs.net>
Date2011-12-29 00:43 +0000
Message-ID<slrnjfnfm4.30q1.usenet-nospam@guild.seebs.net>
In reply to#15142
On 2011-12-29, 88888 Dihedral <dihedral88888@googlemail.com> wrote:
> Seebs??? 2011???12???29????????????UTC+8??????2???17???57????????????
>> It's stupid because lots of programmers don't do assembly.  The test is
>> irrelevant.  It's like demanding that a poet be able to translate poetry
>> into German to prove that it's not plagiarized.

> I don't work with programmers don't understand BIOS and OS very often. 

This is yet another non-sequitur.  You don't need to be able to write
assembly in order to understand BIOS or OS code.  You might need to be able
to do a little assembly to produce a new one from scratch, but it's not
really a major component of most of the work going on.

I've done device drivers and the like, and thus far, I've only ever had to
mess with assembly once, when trying to debug a hardware glitch in SMP mode
on one particular motherboard chipset.  And even then, I didn't have to be
able to write assembly, just change a couple of instructions.

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

[toc] | [prev] | [next] | [standalone]


#15151

From88888 Dihedral <dihedral88888@googlemail.com>
Date2011-12-28 18:16 -0800
Message-ID<6655907.95.1325125018529.JavaMail.geo-discussion-forums@prfi34>
In reply to#15144
Seebs於 2011年12月29日星期四UTC+8上午8時43分52秒寫道:
> On 2011-12-29, 88888 Dihedral <dihedr...@googlemail.com> wrote:
> > Seebs??? 2011???12???29????????????UTC+8??????2???17???57????????????
> >> It's stupid because lots of programmers don't do assembly.  The test is
> >> irrelevant.  It's like demanding that a poet be able to translate poetry
> >> into German to prove that it's not plagiarized.
> 
> > I don't work with programmers don't understand BIOS and OS very often. 
> 
> This is yet another non-sequitur.  You don't need to be able to write
> assembly in order to understand BIOS or OS code.  You might need to be able
> to do a little assembly to produce a new one from scratch, but it's not
> really a major component of most of the work going on.
> 
> I've done device drivers and the like, and thus far, I've only ever had to
> mess with assembly once, when trying to debug a hardware glitch in SMP mode
> on one particular motherboard chipset.  And even then, I didn't have to be
> able to write assembly, just change a couple of instructions.
> 
> -s
> -- 
> Copyright 2011, all wrongs reversed.  Peter Seebach / usenet...@seebs.net
> http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
> http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
> I am not speaking for my employer, although they do rent some of my opinions.

If you are working with C++ or Java  then you do not have to care about C or hardware, nowadays professionals in C are separated from professionals in C++ or Java.


[toc] | [prev] | [next] | [standalone]


Page 2 of 4 — ← Prev page 1 [2] 3 4  Next page →

Back to top | Article view | comp.lang.c


csiph-web