Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

24 Apr, 2024: Testing a new version of the Overboard here. If you have an issue post about it to rocksolid.nodes.help (I know. Everyone on Usenet has issues)


devel / alt.lang.asm / x86 heapsort

SubjectAuthor
* Re: Trump vs NSAKerr-Mudd, John
`- x86 heapsortRobert Prins

1
Re: Trump vs NSA

<20220814124310.ed8480a49beda70be633be41@127.0.0.1>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=330&group=alt.lang.asm#330

  copy link   Newsgroups: alt.lang.asm
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: adm...@127.0.0.1 (Kerr-Mudd, John)
Newsgroups: alt.lang.asm
Subject: Re: Trump vs NSA
Date: Sun, 14 Aug 2022 12:43:10 +0100
Organization: Dis
Lines: 23
Message-ID: <20220814124310.ed8480a49beda70be633be41@127.0.0.1>
References: <647d8f33-eb94-4a92-baa8-6b4557778098n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: reader01.eternal-september.org; posting-host="2b753c37c1e2728221322f0d40f0efea";
logging-data="3293770"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Vj1vIEiPhAKWIVUVhjCvslImvyZcNDSE="
Cancel-Lock: sha1:9+Wfgd89DkIFSrNSRav2CUsIpIo=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
;X-no-Archive: Maybe
GNU: Terry Pratchett
 by: Kerr-Mudd, John - Sun, 14 Aug 2022 11:43 UTC

On Sun, 14 Aug 2022 04:13:35 -0700 (PDT)
Skybuck Flying <skybuckflying@gmail.com> wrote:

> https://youtu.be/qzxPBXJa_Ig
>
> TRUMP vs NSA (National Security Agency of United States of America)
>
[]
>
> WHO WILL WIN ????????????????????????????????????????????????????????????????????????????
>

Assembler programmig wins here, every time.

Who fancies a heapsort?
https://github.com/abdelq/heapsort/blob/master/heapsort.asm
MIPS; needs translating to x86 asm

http://www.rosettacode.org/wiki/Sorting_algorithms/Heapsort#Forth
again doesn't have a version in x86.

--
Bah, and indeed Humbug.

x86 heapsort

<thjq1r$2vcv0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=358&group=alt.lang.asm#358

  copy link   Newsgroups: alt.lang.asm
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: rob...@prino.org (Robert Prins)
Newsgroups: alt.lang.asm
Subject: x86 heapsort
Date: Wed, 5 Oct 2022 14:33:16 +0000
Organization: A noiseless patient Spider
Lines: 307
Message-ID: <thjq1r$2vcv0$1@dont-email.me>
References: <647d8f33-eb94-4a92-baa8-6b4557778098n@googlegroups.com>
<20220814124310.ed8480a49beda70be633be41@127.0.0.1>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 5 Oct 2022 11:33:15 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="9ad2a692bf4ea49448d8faf0cf9b3a05";
logging-data="3126240"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183pXRPGxBtp3wRt+mHp6VD"
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.1
Cancel-Lock: sha1:ug2tnQzmd6fYrj5ArGN9hYeNiwM=
In-Reply-To: <20220814124310.ed8480a49beda70be633be41@127.0.0.1>
Content-Language: en-US
 by: Robert Prins - Wed, 5 Oct 2022 14:33 UTC

On 2022-08-14 11:43, Kerr-Mudd, John wrote:
> On Sun, 14 Aug 2022 04:13:35 -0700 (PDT)
> Skybuck Flying <skybuckflying@gmail.com> wrote:
>
>> https://youtu.be/qzxPBXJa_Ig
>>
>> TRUMP vs NSA (National Security Agency of United States of America)
>>
> []
>>
>> WHO WILL WIN ????????????????????????????????????????????????????????????????????????????
>>
>
> Assembler programmig wins here, every time.
>
> Who fancies a heapsort?
> https://github.com/abdelq/heapsort/blob/master/heapsort.asm
> MIPS; needs translating to x86 asm

From my hitchhike statistics program @
<https://prino.neocities.org/miscellaneous/hitchtech.html>

{************** Copyright (C) Robert AH Prins 1996-2021 ****************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3, or (at your option) *
* any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA *
************************************************************************
+------------+---------------------------------------------------------+
| Date | Major changes |
+------------+---------------------------------------------------------+
| | |
+------------+---------------------------------------------------------+
| 2021-02-28 | - remove stack-frame from "damosort" |
+------------+---------------------------------------------------------+
| 2020-07-31 | - merge of daysort and mnthsort |
+------------+---------------------------------------------------------+
| 2020-05-31 | - reformat assembler |
+------------+---------------------------------------------------------+
| 2017-11-14 | - add profile code |
+------------+---------------------------------------------------------+
| 2016-08-15 | - only sort if more than one day |
+------------+---------------------------------------------------------+
| 2013-09-06 | - to asm: daysort |
+------------+---------------------------------------------------------+
| 2008-10-22 | - use native longint rather than integer |
+------------+---------------------------------------------------------+
| 2008-10-06 | - initial Virtual Pascal version |
+------------+---------------------------------------------------------+
************************************************************************
* DAMOSORT: *
* *
* Sort the array of totals per day/month in various orders *
***********************************************************************}
{$ifdef asm}
procedure damosort(n: longint; var sortin); assembler; {&uses none} {&frame-}
var sort: _sort_ptr absolute sortin;

var _i : longint;
var _l : longint;

var rra : sortptr;

var ready: boolean;

asm
//a-in damosort
// _l := succ(n shr 1)

mov eax, n
cmp eax, 1
jle @10

shr eax, 1
inc eax
mov _l, eax

mov esi, sort
mov esi, [esi]

mov ready, false

// repeat

@01:
// if _l > 1 then

cmp _l, 1
jle @02

dec _l

// rra:= sort^[_l]

mov ecx, _l
mov edi, [ecx * 4 + esi]
jmp @03

@02:
// rra := sort^[n]

mov ecx, n
mov edi, [ecx * 4 + esi]

// sort^[n]:= sort^[1]

mov ecx, [esi + 4]
mov edx, n
mov [edx * 4 + esi], ecx

// dec(n)

dec n

// if n = 1 then

cmp n, 1
jne @03

// sort^[1]:= rra

mov [esi + 4], edi

mov ready, true

@03:
mov eax, _l
mov _i, eax

mov ebx, _l
shl ebx, 1

// while (not ready) and
// (_j <= n) do

@04:
cmp ready, true
je @09

cmp ebx, n
jg @09

// if _j < n then

je @06

mov edx, [ebx * 4 + esi + 4]

// if (sort^[_j]^.major < sort^[_k]^.major) or
// (sort^[_j]^.major = sort^[_k]^.major) and
// (sort^[_j]^.minor < sort^[_k]^.minor) then

mov eax, [ebx * 4 + esi]
mov ecx, [eax + offset sort_list.major]
cmp ecx, [edx + offset sort_list.major]
jl @05

jne @06

mov ecx, [eax + offset sort_list.minor]
cmp ecx, [edx + offset sort_list.minor]
jge @06

@05:
inc ebx

@06:
mov edx, [ebx * 4 + esi]

// if (rra^.major < sort^[_j]^.major) or
// (rra^.major = sort^[_j]^.major) and
// (rra^.minor < sort^[_j]^.minor) then

mov ecx, [edi + offset sort_list.major]
cmp ecx, [edx + offset sort_list.major]
jl @07

jne @08

mov ecx, [edi + offset sort_list.minor]
cmp ecx, [edx + offset sort_list.minor]
jge @08

// sort^[_i]:= sort^[_j]

@07:
mov ecx, _i
mov [ecx * 4 + esi], edx

mov _i, ebx

shl ebx, 1
jmp @04

@08:
mov ebx, n
inc ebx
jmp @04

@09:
// sort^[_i]:= rra

mov ecx, _i
mov [ecx * 4 + esi], edi

cmp ready, true
jne @01

@10:
//a-out
end; {damosort}

{$else}

procedure damosort(n: longint; var sortin);
var sort: _sort_ptr absolute sortin;

var _i : longint;
var _j : longint;
var _k : longint;
var _l : longint;

var rra: sortptr;

var ready: boolean;

begin
if n > 1 then
begin
ready:= false;
_l := succ(n shr 1);

repeat
if _l > 1 then
begin
dec(_l);
rra:= sort^[_l];
end
else
begin
rra := sort^[n];
sort^[n]:= sort^[1];
dec(n);

if n = 1 then
begin
sort^[1]:= rra;
ready := true
end;
end;

_i:= _l;
_j:= _l * 2;

while (not ready) and
(_j <= n) do
begin
if _j < n then
begin
_k:= succ(_j);

if (sort^[_j]^.major < sort^[_k]^.major) or
(sort^[_j]^.major = sort^[_k]^.major) and
(sort^[_j]^.minor < sort^[_k]^.minor) then
inc(_j);
end;

if (rra^.major < sort^[_j]^.major) or
(rra^.major = sort^[_j]^.major) and
(rra^.minor < sort^[_j]^.minor) then
begin
sort^[_i]:= sort^[_j];
_i := _j;
_j := _j * 2;
end
else
_j:= succ(n);
end;

sort^[_i]:= rra;
until ready;
end;
end; {damosort}
{$endif}

Sorting an array of pointers to a list on two (major+minor) fields. And yes,
Virtual Pascal tells you to save ebx, esi, and edi, but this being a top-level
procedure, I've dispensed with that.

Robert
--
Robert AH Prins
robert(a)prino(d)org
The hitchhiking grandfather - https://prino.neocities.org/
Some REXX code for use on z/OS - https://prino.neocities.org/zOS/zOS-Tools.html

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor