Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

Kod podprogramu, funkcji.

Ostatnio zmodyfikowano 2017-09-17 15:26
Autor Wiadomość
ksardias
Temat założony przez niniejszego użytkownika
Kod podprogramu, funkcji.
» 2017-09-17 11:47:15
Działam na C::B jest możliwość wypisania kodu danej funkcji, podprogramu?
P-164959
Kinexity
» 2017-09-17 13:41:16
Masz na myśli poznanie implementacji funkcji z biblioteki standardowej, czy wypisanie w konsoli kodu twojej własnej funkcji?
P-164960
ksardias
Temat założony przez niniejszego użytkownika
» 2017-09-17 15:10:16
Tę pierwszą opcje. Dzięki za dobór słownictwa, fajnie się czegoś nowego nauczyć.
P-164964
mateczek
» 2017-09-17 15:15:07
ja to mam takie zdanie.
Kto ma taką znajomość c++ by zrozumieć kod z biblioteki standardowej to na pewno wie jak go znaleźć:P
I zamiast kodu polecił bym dokumentacje http://www.cplusplus.com​/reference/
P-164965
Kinexity
» 2017-09-17 15:21:54
Biblioteka standardowa jest (jak się nie mylę) od razu skompilowana, więc nie zobaczysz nic poza plikami nagłówkowymi. Jeżeli chcesz poznać faktyczną implementację, to musisz pokopać w internecie. Wiem, że w VS (nie wiem, czy też w CB) na pewno jest parę plików w asemblerze, ale nic ponad to.

Przykład - dzielenie zmiennej typu
unsigned long long

        title   ulldiv - unsigned long divide routine
;***
;ulldiv.asm - unsigned long divide routine
;
;       Copyright (c) Microsoft Corporation. All rights reserved.
;
;Purpose:
;       defines the unsigned long divide routine
;           __aulldiv
;
;*******************************************************************************


.xlist
include vcruntime.inc
include mm.inc
.list

;***
;ulldiv - unsigned long divide
;
;Purpose:
;       Does a unsigned long divide of the arguments.  Arguments are
;       not changed.
;
;Entry:
;       Arguments are passed on the stack:
;               1st pushed: divisor (QWORD)
;               2nd pushed: dividend (QWORD)
;
;Exit:
;       EDX:EAX contains the quotient (dividend/divisor)
;       NOTE: this routine removes the parameters from the stack.
;
;Uses:
;       ECX
;
;Exceptions:
;
;*******************************************************************************

        CODESEG

_aulldiv        PROC NEAR
.FPO (2, 4, 0, 0, 0, 0)

        push    ebx
        push    esi

; Set up the local stack and save the index registers.  When this is done
; the stack frame will look as follows (assuming that the expression a/b will
; generate a call to uldiv(a, b)):
;
;               -----------------
;               |               |
;               |---------------|
;               |               |
;               |--divisor (b)--|
;               |               |
;               |---------------|
;               |               |
;               |--dividend (a)-|
;               |               |
;               |---------------|
;               | return addr** |
;               |---------------|
;               |      EBX      |
;               |---------------|
;       ESP---->|      ESI      |
;               -----------------
;

DVND    equ     [esp + 12]      ; stack address of dividend (a)
DVSR    equ     [esp + 20]      ; stack address of divisor (b)

;
; Now do the divide.  First look to see if the divisor is less than 4194304K.
; If so, then we can use a simple algorithm with word divides, otherwise
; things get a little more complex.
;

        mov     eax,HIWORD(DVSR) ; check to see if divisor < 4194304K
        or      eax,eax
        jnz     short L1        ; nope, gotta do this the hard way
        mov     ecx,LOWORD(DVSR) ; load divisor
        mov     eax,HIWORD(DVND) ; load high word of dividend
        xor     edx,edx
        div     ecx             ; get high order bits of quotient
        mov     ebx,eax         ; save high bits of quotient
        mov     eax,LOWORD(DVND) ; edx:eax <- remainder:lo word of dividend
        div     ecx             ; get low order bits of quotient
        mov     edx,ebx         ; edx:eax <- quotient hi:quotient lo
        jmp     short L2        ; restore stack and return

;
; Here we do it the hard way.  Remember, eax contains DVSRHI
;

L1:
        mov     ecx,eax         ; ecx:ebx <- divisor
        mov     ebx,LOWORD(DVSR)
        mov     edx,HIWORD(DVND) ; edx:eax <- dividend
        mov     eax,LOWORD(DVND)
L3:
        shr     ecx,1           ; shift divisor right one bit; hi bit <- 0
        rcr     ebx,1
        shr     edx,1           ; shift dividend right one bit; hi bit <- 0
        rcr     eax,1
        or      ecx,ecx
        jnz     short L3        ; loop until divisor < 4194304K
        div     ebx             ; now divide, ignore remainder
        mov     esi,eax         ; save quotient

;
; We may be off by one, so to check, we will multiply the quotient
; by the divisor and check the result against the orignal dividend
; Note that we must also check for overflow, which can occur if the
; dividend is close to 2**64 and the quotient is off by 1.
;

        mul     dword ptr HIWORD(DVSR) ; QUOT * HIWORD(DVSR)
        mov     ecx,eax
        mov     eax,LOWORD(DVSR)
        mul     esi             ; QUOT * LOWORD(DVSR)
        add     edx,ecx         ; EDX:EAX = QUOT * DVSR
        jc      short L4        ; carry means Quotient is off by 1

;
; do long compare here between original dividend and the result of the
; multiply in edx:eax.  If original is larger or equal, we are ok, otherwise
; subtract one (1) from the quotient.
;

        cmp     edx,HIWORD(DVND) ; compare hi words of result and original
        ja      short L4        ; if result > original, do subtract
        jb      short L5        ; if result < original, we are ok
        cmp     eax,LOWORD(DVND) ; hi words are equal, compare lo words
        jbe     short L5        ; if less or equal we are ok, else subtract
L4:
        dec     esi             ; subtract 1 from quotient
L5:
        xor     edx,edx         ; edx:eax <- quotient
        mov     eax,esi

;
; Just the cleanup left to do.  edx:eax contains the quotient.
; Restore the saved registers and return.
;

L2:

        pop     esi
        pop     ebx

        ret     16

_aulldiv        ENDP

        end
P-164966
ksardias
Temat założony przez niniejszego użytkownika
» 2017-09-17 15:26:15
Okay, ze zwykłej ciekawości chciałem zobaczyć jak takie coś wygląda, lubię rozkładać na części pierwsze coś co zwykle się po prostu używa, ale chyba jeszcze nie pora, dzięki! wracam do kodowania, produktywnej niedzieli wszystkim.
P-164967
« 1 »
  Strona 1 z 1