flat assembler
Message board for the users of flat assembler.

Index > Heap > Looking for a teacher.

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
TmX



Joined: 02 Mar 2006
Posts: 821
Location: Jakarta, Indonesia
TmX
Coty wrote:
Uh, C can exist outside an OS, Linux is made fully out of C... C != Scripting language. It's compiler is capable of producing pure machine code, larger, slower, yes, but still possible.


linux is not written fully in C
well most of the big parts are indeed in C, while the rest of them are in asm
Post 04 Sep 2011, 16:03
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
ouadji
That's the reason, I don't want to use WinAPI calls. I know that's nothing.
--
bubble sorting ? you mean, if I have numbers, for example: 9 3 5 2 7 - this must be written like 2,3,5,7,9 right ? I'll think about that ))
Post 04 Sep 2011, 16:21
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 04 Sep 2011, 16:29
View user's profile Send private message Send e-mail Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
may I know the theory in asm style what to do ? Confused I'm stucking on second stage..
Post 04 Sep 2011, 16:49
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

something like that

Code:
;procedure bubbleSort( A : list of sortable items )
;   n = length(A)
;   repeat
;      newn = 0
;      for i = 1 to n-1 inclusive do
;         if A[i-1] > A[i] then
;            swap(A[i-1], A[i])
;            newn = i
;         end if
;      end for
;      n = newn
;   until n = 0
;end procedure
;--------------------------------------------------------------------
list_ dd 0x47,0x44,0x24,0x23,0x17,0x24,0x46,0x19,0xFF,0x00
sizeof.list_=($-list_)/4
;--------------------------------------------------------------------
proc        bubbleSort, A, n

                mov     edi,[A]
             mov     edx,[n]

.loop_repeat:        mov     ebx,edx

         or      ebx,ebx
             jz      .end_bs

         xor     edx,edx ;edx==newn
          xor     eax,eax ;eax==i
             dec     ebx
         jz      .end_bs

.loop_for:   inc     eax
         cmp     eax,ebx
             ja      .loop_repeat

            lea     esi,[edi+(eax*4)]
           
            mov     ecx,[esi-4]
         cmp     ecx,[esi]
           jbe     .loop_for

               xchg    ecx,[esi]
           mov     [esi-4],ecx

             mov     edx,eax
             jmp     .loop_for

.end_bs:   ret

endp
;--------------------------------------------------------------------

                stdcall bubbleSort, list_, sizeof.list_
    

_________________
I am not young enough to know everything (Oscar Wilde)- Image


Last edited by ouadji on 04 Sep 2011, 20:11; edited 1 time in total
Post 04 Sep 2011, 19:56
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
lodsd Wink
Post 04 Sep 2011, 20:09
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

lodsd, yes, but it's more didactic that way.
(it seems to me it's more like the pseudo-code)

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 04 Sep 2011, 20:14
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
ouadji wrote:

lodsd, yes, but it's more didactic that way.
(it seems to me it's more like the pseudo-code)


I know lol Very Happy,

I like your way too because then you'd have to use ESI and perform dec & inc.

But I just guess there are different ways to do it. Very Happy
Post 04 Sep 2011, 20:25
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Quote:
But I just guess there are different ways to do it

yes, almost as much as the number of programmers.

but mine works Smile

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 04 Sep 2011, 20:33
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
ouadji wrote:
yes, almost as much as the number of programmers.


YEAH !
Image


Which I doubt is known if you ask me Very Happy
Post 04 Sep 2011, 20:38
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
when speed does not matter

Code:
; destroys ecx
bubbleSort:
            pushad
            mov esi, edi
    .A:     lodsd
            cmp eax, [esi]
            jge .B
            xchg eax, [esi]
    .B:     stosd
            loop .A
            popad
            loop bubbleSort
            ret
    

Code:
            ; descending sort 
            cld
            mov edi, list_
            mov ecx, sizeof.list_
            call  bubbleSort
    

Code:
            ; ascending sort 
            std
            mov edi, list_+(sizeof.list_*4)-4
            mov ecx, sizeof.list_
            call bubbleSort
    
Post 04 Sep 2011, 21:25
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
I did it! my way:
Code:
numbers db 9,3,7,2,5,8,6,1,0,4
main:
        xor eax,eax ;eax = 0
        mov ebx,9 ;gaameorebs 81jer Smile
        mov ecx,9 ;size-1
        mov esi,numbers ;esi = numbers
@@:
        lodsb ;al = numbers++
        .if (al > byte[esi]) ;/
        xchg al,byte[esi]    ;| tu metia shevucvalot adgilebi, tu ara da igive gavameorot.
        mov byte[esi-1],al   ;\
        .endif
        loop @b ;gavameorot size-1 jer.
        sub esi,9 ;davabrunot ricxvebis swori misamarti.
        mov ecx,9 ;size-1
        dec ebx
        test ebx,ebx ;shesrulda yvelaferi 81jer ?
        jz .done     ;tu ki mashin morches! Very Happy
        loop @b      ;tu ara, isev gaimeoros!
.done:
        ret ;aq morcha yvelaferi! Smile    

sry for comments ^^
Post 27 Sep 2011, 20:20
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Code:
numbers db 9,2,7,2,5,4,6,1,0,4 
    

Rolling Eyes *whistle*
Post 28 Sep 2011, 00:29
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
typedef
what ? it works with that too.
Post 28 Sep 2011, 10:02
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.