Author Topic: ASM4FUN is almost ready  (Read 1463 times)

frktons

  • Member
  • ****
  • Posts: 512
ASM4FUN is almost ready
« on: November 08, 2021, 11:10:02 PM »
Hello beautiful ASM people.  :eusa_dance:

Today I downloaded the MASM32 package for win10, the old one is missed with old disk
and not anymore functioning probably.

The installation process was ok, the help file WIN32.HLP put online for MASM Editor.

So let's start with the first  episode of the ASM FUN SAGA.

As I mentioned elsewhere, I want to find a fast way to:

1) convert 1 million strings into INTEGER numbers
2) compare the first one of them with the following until I find a gap of 10 units or more (bigger number)
or less (smaller number).

3) display the number of occurrences of the bigger, and smaller numbers found, so that when one is found
the process restart from that point forward in the list (an array probably).

Let's start with the first part "Conversion of 1 million strings into INTEGER numbers.

Any suggestion is welcome

 :thumbsup:
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: ASM4FUN is almost ready
« Reply #1 on: November 09, 2021, 12:05:26 AM »
What format are the string in ?
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: ASM4FUN is almost ready
« Reply #2 on: November 09, 2021, 01:21:18 AM »
I want to find a fast way to:

1) convert 1 million strings into INTEGER numbers
2) compare the first one of them with the following until I find a gap of 10 units or more (bigger number)
or less (smaller number).

Roughly half a second for a Million numbers, with a non-specialised algo. What do you mean with "fast", and why does it have to be fast?

frktons

  • Member
  • ****
  • Posts: 512
Re: ASM4FUN is almost ready
« Reply #3 on: November 09, 2021, 03:53:07 AM »
What format are the string in ?

Hi Steve,

just four ASCII bytes: "1234" to convert into an integer.

I want to find a fast way to:

1) convert 1 million strings into INTEGER numbers
2) compare the first one of them with the following until I find a gap of 10 units or more (bigger number)
or less (smaller number).

Roughly half a second for a Million numbers, with a non-specialised algo. What do you mean with "fast", and why does it have to be fast?

Hi JJ.

I have to perform the comparison many times, even if the conversion could be done just once
and store the INTEGER numbers into an array.

Thanks guys. always kind and helpful.

In pseudocode it could be expressed like:

START TIME
DO UNITIL 1M times
   
    number = convert(string)

END DO
END TIME

PRINT "Time count is "; TIME_USED





There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

nidud

  • Member
  • *****
  • Posts: 2388
    • https://github.com/nidud/asmc
Re: ASM4FUN is almost ready
« Reply #4 on: November 09, 2021, 04:35:38 AM »
deleted
« Last Edit: February 24, 2022, 09:42:55 PM by nidud »

frktons

  • Member
  • ****
  • Posts: 512
Re: ASM4FUN is almost ready
« Reply #5 on: November 09, 2021, 04:39:25 AM »
    mov     ecx,[rcx]
    and     ecx,not '0000'
    movzx   eax,cl
    movzx   edx,ch
    imul    eax,eax,1000
    imul    edx,edx,100
    add     eax,edx
    shr     ecx,16
    movzx   edx,cl
    shr     ecx,8
    imul    edx,edx,10   
    add     eax,edx
    add     eax,ecx


Thanks my friend, I am going to study the code to understand what exactly you do
with this serie of multiplications and additions, shift right and moving around registers, I have some intuition though.

:-)

There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: ASM4FUN is almost ready
« Reply #6 on: November 09, 2021, 07:37:37 AM »
Hi Frank,

It sounds like you are doing some form of integer sort algorithm. 4 digits numbers in the range of 0000 to 9999 should in fact be very simple and really fast if you do it right. Something like a "letterbox" sort which is basically an array of 9999 members which you just write each number to its array index then scan from one end of the array to the other optionally dropping any blanks.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

frktons

  • Member
  • ****
  • Posts: 512
Re: ASM4FUN is almost ready
« Reply #7 on: November 09, 2021, 08:12:58 AM »
Hi Steve.

My goal is not to sort the array of strings, but to convert a fixed length string of 4 bytes
into an Integer (4 bytes as well).

I have about 8 millions strings of 4 bytes with values between "0000" to "9999" but the two extreme are not there.

I think storing the 8 millions strings into an array, convert them into 8 millions INTEGER of 4 bytes
is taking quite a while.

I am going to test it in PowerBasic, that I somehow remember how to code and find the needed info.
After I will do a loop in ASM 1 to 8 millions times and find a better solution in speed and, why not, elegance.

When finished I will post the results, and try to make it FUN and useful. Then the optimization will start.

 :thumbsup:
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama