Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
ekliptikz said:always a pleasure
ekliptikz said:always a pleasure
enlightenedby42 said:Actually in an assembly class right now and we've talked about it.
Really low level stuff is done in assembly, the rest in C or C++ (probably C++ lately). C++ is actually directly analagous to assembly, but you do not have as much precise control over efficency and things of that nature. Windows, 'nix, all those are built in that way from what I understand. Cool stuff.
Anybody who has had to take assembly knows why they use high level languages as early in the process as possible.Assembly can be harder than a left turn downtown sometimes.
enlightenedby42 said:My prof. wrote about a dozen instruction c-callable assembly function to replace the log function in the cmath library and timed them both calculating a million or so logs, and the assembly function was almost 3x faster! Makes you question the efficiency of included functions a bit.
Hah, too true. Actually in this particular case I believe that was handling of really big/really weird numberrs. But, nevertheless. I, for one, am gonna let the compiler handle it for me, that's for damn sure.ameoba said:...or what he left out.
Mostly ASM is only for the required low level stuff any more, since the average compiler can pump out better code on average then a human, and much faster at it too.
lolekliptikz said:french
enlightenedby42 said:Also, from what I understood, some of the increased efficency is (again, could be wrong here) due to the fact that c++ pushes and pops all the registers at the beginning and end of the function, respectively.
enlightenedby42 said:Also, from what I understood, some of the increased efficency is (again, could be wrong here) due to the fact that c++ pushes and pops all the registers at the beginning and end of the function, respectively.
Anyway, mea culpa for getting off topic a bit here. At least I'm still talking about programming.![]()
void BubbleSort(int data[], int count, int dir) {
bool done = false;
while(!done) {
done = true;
for(int i=0;i<count-1;i++) {
bool swap;
if(dir == 0) {
swap = data[i] > data[i+1];
}
else {
swap = data[i] < data[i+1];
}
if(swap) {
int temp = data[i];
data[i] = data[i+1];
data[i+1] = temp;
done = false;
}
}
}
}
PUBLIC ?BubbleSort@@YAXQAHHH@Z ; BubbleSort
; COMDAT ?BubbleSort@@YAXQAHHH@Z
_TEXT SEGMENT
_data$ = 8
_count$ = 12
_dir$ = 16
_done$ = -4
_i$276 = -8
_swap$280 = -12
_temp$284 = -16
?BubbleSort@@YAXQAHHH@Z PROC NEAR ; BubbleSort, COMDAT
; 3 : void BubbleSort(int data[], int count, int dir) {
push ebp
mov ebp, esp
sub esp, 80 ; 00000050H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-80]
mov ecx, 20 ; 00000014H
mov eax, -858993460 ; ccccccccH
rep stosd
; 4 : bool done = false;
mov BYTE PTR _done$[ebp], 0
$L274:
; 5 : while(!done) {
mov eax, DWORD PTR _done$[ebp]
and eax, 255 ; 000000ffH
test eax, eax
jne $L275
; 6 : done = true;
mov BYTE PTR _done$[ebp], 1
; 7 : for(int i=0;i<count-1;i++) {
mov DWORD PTR _i$276[ebp], 0
jmp SHORT $L277
$L278:
mov ecx, DWORD PTR _i$276[ebp]
add ecx, 1
mov DWORD PTR _i$276[ebp], ecx
$L277:
mov edx, DWORD PTR _count$[ebp]
sub edx, 1
cmp DWORD PTR _i$276[ebp], edx
jge $L279
; 8 : bool swap;
; 9 : if(dir == 0) {
cmp DWORD PTR _dir$[ebp], 0
jne SHORT $L281
PUBLIC BubbleSort
_TEXT SEGMENT
_data$ = 8
_count$ = 12
_dir$ = 16
_done$ = -4
BubbleSort PROC NEAR
push ebp
mov ebp, esp
sub esp, 8
push eax
push ebx
push ecx
push esi
push edi
mov ecx, [_data$+ebp]
mov edx, _dir$[ebp] ;direction indicator
bsSwapAgain:
mov DWORD PTR _done$[ebp], 1
mov esi, 0 ;array index
bsArrayLoop:
cmp edx, 0
jne bsSwapBackward
mov eax, [ecx+esi*4] ;data[i]
mov ebx, [ecx+esi*4+4] ;data[i+1]
sub ebx, eax
jns bsIterate ;skip if data[i] !> data[i+1]
mov ebx, DWORD PTR [ecx+esi*4+4] ;data[i+1]
mov [ecx+esi*4], ebx ;data[i] = data[i+1]
mov [ecx+esi*4+4], eax ;data[i+1] = data[i]
mov DWORD PTR _done$[ebp], 0
jmp bsIterate
bsSwapBackward:
mov eax, [ecx+esi*4] ;data[i]
mov ebx, [ecx+esi*4+4] ;data[i+1]
sub eax, ebx
jns bsIterate ;skip if data[i] !> data[i+1]
mov eax, [ecx+esi*4] ; data[i]
mov [ecx+esi*4], ebx ;data[i] = data[i+1]
mov [ecx+esi*4+4], eax ;data[i+1] = data[i]
mov DWORD PTR _done$[ebp], 0
bsIterate:
inc esi
mov eax, _count$[ebp]
dec eax
cmp esi, eax
jne bsArrayLoop
mov eax, _done$[ebp]
cmp eax, 0
je bsSwapAgain
pop edi
pop esi
pop ecx
pop ebx
pop eax
mov esp, ebp
pop ebp
ret 0
BubbleSort ENDP
_TEXT ENDS
END
fluxion said:C++ tosses out some pretty shitty code sometimes actually. take this C++ code for a bubblesort, for example:
[...]
probably room for optimization, but fairly straightforward right? here's the ASM VC++ compiler generates from the above source:
; Listing generated by Microsoft (R) Optimizing Compiler Version 14.00.50727.42
TITLE C:\sort.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB LIBCMT
INCLUDELIB OLDNAMES
PUBLIC ?BubbleSort@@YGXQAHHH@Z ; BubbleSort
; Function compile flags: /Ogtpy
; File c:\sort.cpp
_TEXT SEGMENT
_data$ = 8 ; size = 4
_count$ = 12 ; size = 4
_dir$ = 16 ; size = 4
?BubbleSort@@YGXQAHHH@Z PROC ; BubbleSort
; 1 : void BubbleSort(int data[], int count, int dir) {
00000 53 push ebx
00001 55 push ebp
00002 8b 6c 24 10 mov ebp, DWORD PTR _count$[esp+4]
00006 56 push esi
00007 57 push edi
00008 8b 7c 24 14 mov edi, DWORD PTR _data$[esp+12]
0000c 83 c5 ff add ebp, -1
0000f 90 npad 1
$LL8@BubbleSort:
; 4 : done = true;
; 5 : for(int i=0;i<count-1;i++) {
00010 33 f6 xor esi, esi
00012 85 ed test ebp, ebp
00014 b3 01 mov bl, 1
00016 7e 3a jle SHORT $LN14@BubbleSort
00018 eb 06 8d 9b 00
00 00 00 npad 8
$LL15@BubbleSort:
; 6 : bool swap;
; 7 : if(dir == 0) {
00020 83 7c 24 1c 00 cmp DWORD PTR _dir$[esp+12], 0
; 8 : swap = data[i] > data[i+1];
00025 8b 04 b7 mov eax, DWORD PTR [edi+esi*4]
00028 8b 4c b7 04 mov ecx, DWORD PTR [edi+esi*4+4]
0002c 75 07 jne SHORT $LN3@BubbleSort
0002e 3b c1 cmp eax, ecx
00030 0f 9f c2 setg dl
; 9 : }
; 10 : else {
00033 eb 05 jmp SHORT $LN2@BubbleSort
$LN3@BubbleSort:
; 11 : swap = data[i] < data[i+1];
00035 3b c1 cmp eax, ecx
00037 0f 9c c2 setl dl
$LN2@BubbleSort:
; 12 : }
; 13 : if(swap) {
0003a 84 d2 test dl, dl
0003c 74 09 je SHORT $LN5@BubbleSort
; 14 : int temp = data[i];
; 15 : data[i] = data[i+1];
0003e 89 0c b7 mov DWORD PTR [edi+esi*4], ecx
; 16 : data[i+1] = temp;
00041 89 44 b7 04 mov DWORD PTR [edi+esi*4+4], eax
; 17 : done = false;
00045 32 db xor bl, bl
$LN5@BubbleSort:
00047 83 c6 01 add esi, 1
0004a 3b f5 cmp esi, ebp
0004c 7c d2 jl SHORT $LL15@BubbleSort
; 2 : bool done = false;
; 3 : while(!done) {
0004e 84 db test bl, bl
00050 74 be je SHORT $LL8@BubbleSort
$LN14@BubbleSort:
00052 5f pop edi
00053 5e pop esi
00054 5d pop ebp
00055 5b pop ebx
; 18 : }
; 19 : }
; 20 : }
; 21 : }
00056 c2 0c 00 ret 12 ; 0000000cH
?BubbleSort@@YGXQAHHH@Z ENDP ; BubbleSort
_TEXT ENDS
END
Baseline: 0.4968
Baseline Tweaked: 0.3637
Baseline unoptimized: 1.011
Fluxion Assembly: 0.4643
Mikeblas Assembly: 0.3672
Mikeblas2 Assembly: 0.3405
Quicksort: 0.00245
Baseline: 356.5
Baseline Tweaked: 302.5
Baseline unoptimized: 658.1
Fluxion Assembly: 334.7
Mikeblas Assembly: 292.8
Mikeblas2 Assembly: 286.4
Quicksort: 0.06908
fluxion said:haha, very nice mikeblas. i know it wasn't a very good benchmark, and i didn't use any optimizations or anything with vc++. my main point was to address the insinuation that for assembly code to outpace it's C++ equivalent by a factor of 3 the code must have been crippled in some respect. an assembly newb like me hitting near that very mark while retaining full functionality seemed like a good counterpoint.
fluxion said:great post though, you really cleaned up the assembly code there. add 4 to esi instead of multiplying increments of 1 by 4 all the time...i'm slapping my forehead right now lol. lesson here is that there's always room for improvement![]()
x86 Assembly (for low level kernel stuff and device drivers)
ANSI C (again, for the low-level stuff)
C++ (general Windows API stuff like MFC, DirectX, etc)
XML (windows uses XML a lot for controlling display for a lot of COM apps)
HTML (see XML)
mikeblas said:Oh -- did you mean that the assembler version must have been cripped by removing features to become faster?
J32P2006 said:I just wanted something like this...
Thanks for all the input though. Holy shit, becareful of what you ask for.
And i'm having trouble learning visual basic 6.
svet-am said:x86 Assembly (for low level kernel stuff and device drivers)
ANSI C (again, for the low-level stuff)
C++ (general Windows API stuff like MFC, DirectX, etc)
XML (windows uses XML a lot for controlling display for a lot of COM apps)
HTML (see XML)
You didn't ask for it, but free advice: Skip VB6 and go for a .net - language.
I'd say C#, but VB.net is equally capable. I just don't like the syntax, and getting used to a C-style syntax will make it much easier to learn java, C or C++ later on.
Meh. I started with VB6 and it helped me learn to think in ways that I wouldnt before
I just wanted something like this...
Thanks for all the input though. Holy shit, becareful of what you ask for.
And i'm having trouble learning visual basic 6.