News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Hello!

Started by Dami3n, December 10, 2007, 02:59:20 PM

Previous topic - Next topic

Dami3n

I have school project where i have to compare the speed of assembly to something else like c++.
The only way i could think of is to make 2 programs, one with asm and one with c++ to print numbers to 100000 or something like that.

I can easily create program like that with c++ but how can i make it with asm. asm seems to hard for me  :'(
So how to code something with asm so the value would always rise with 1 and then print it again till something is 10000 or more?

Edit:

Ok i got it half work with this

.while (jokin < 9)
      invoke   ConsoleOutput,addr strText01
            inc jokin
            .endw

But how can i make it to print that jokin like
1
2
3
4
5
6
7
8
9
.
.
.

Mark Jones

Hello Dami3n, welcome to the forum. Please post the assembler code you have tried to use so that we may comment on it and point you in the right direction. Also note that we can help you understand your code, but we will not do your homework for you. :U
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

jj2007

Quote from: Mark Jones on December 10, 2007, 04:29:49 PM
we can help you understand your code, but we will not do your homework for you. :U
Indeed  :bg
But it's good to know anyway that there are still schools that teach assembler. Attached a very simple implementation of your printing homework - extract to your MASM drive with "use folder names", then edit the jokin.asm and drag the result over asmbuild.exe
What is not included is a timing routine. If you feel strong enough for the next step, check http://www.masm32.com/board/index.php?topic=770.0
However, a simple "count up to 1000 and print" program will not tell you anything about speed differences, because the bottleneck is the printing, i.e. screen drivers etc.
Cheers, and welcome to the forum :bg

[attachment deleted by admin]

george999

include \masm32\include\masm32rt.inc
.data
number     DWORD ?,0
cnt        DWORD ?,0
.code
start:

mov cnt,100
mov number,1
Label1:
print str$(number),13,10
inc number
sub cnt,1
jnz Label1
call wait_key
invoke ExitProcess,0
end start


Build with console assemble & link

ossama

Quote from: jj2007 on December 10, 2007, 04:34:50 PM
However, a simple "count up to 1000 and print" program will not tell you anything about speed differences,
yeh, you are right,
i suggest to write a loop doing add/inc/..and after the loop is finished we show a message box to tell us that the loop is finished,
the source code is like this:

     xor eax,eax
     @@:
     inc eax
     cmp eax,0ffffffffh          ;it is not enough to compare speed difference and we can write many sub loops
     jb @B
     invoke MessageBox,NULL,addr szLoopFinished,NULL,MB_OK
..
..
..


Mark Jones

...or, we could all just do his homework for him... lol :clap:

Gotta wonder, what would have happened if I had never said anything? Probabilistic causality and all. Oh-well.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

u

Pre-allocate the whole output buffer,
do the counting in a decimal string, that is reversed (instead of calling something like dword2ascii). Also use a down-counter, and align the code. Then, make unroll into groups of "how many decimal digits should be printed".
The above ideas come just for a few seconds of thinking what the slow parts can be:
- constantly calling slow (high-latency) OS api on every single digit. Scratch. => a big array, that we manage ourselves
- dword->string conversion, with half a dozen divisions... Scratch. Use paper'n'pencil-style incrementing.
- counting how many characters each string has. Scratch. Know how many they are, and manage the data in reverse (777= "777", 778="877", 779="977")
- looping on each digit is slow. Do inlining.
- comparing strings isn't fast. Do regular integer aritmetic, too. For the count of iterations.
- inlining it all is insane. Make a procedure PrintNums(NumDigits).

Pity, this stuff would be fun if the task was for something even remotely useful :)
Please use a smaller graphic in your signature.

Dami3n

Well this aint my homework, let me explain.

Im on last year of my school, and we had to pick subject which to explaing and write about 30 pages. I choosed assembly :D
With this program, help im asking, im trying to compare the speed of assembly to something else like c++ programm
I just take time and see which one will print those numbers faster, and i know its assembly ;D.

So this is small part of my work, but important one :D

Edit: Iv been using assembly for little example memory hacking (ce anyone?)
Of course this is different but because i like to code something small (maybe some day something bigger), i think im going to study assembly more, and because this forum is so nice i guess i will be back after my whole school project.

Edit2: btw thanks george999, this is just what i need, next time i will code it myself :D

---

OK then i used .while and it seems to work


include \masm32\include\masm32rt.inc
.data
number     DWORD ?,0
.code
start:

mov number,1
.while (number < 1000001)
print str$(number),13,10
inc number
.endw
call wait_key
invoke ExitProcess,0
end start

Few questions!
print str$(number),13,10 <-- Why is there 13,10. It seems that when i changed it to 10,10 it made line after everynumber
example:
1

2

3

4
...

I think that
" call wait_key
invoke ExitProcess,0"
Means waiting for user input and then, in this case close program.
Why is that identifier like this?
number     DWORD ?,0 <- Why the question mark, is it because we cannot be sure how big value is it going to be?
Well i guess that was all  :bg

u

13,10 specifies a "new line" (carriage return + linefeed) in Windows-style text. In Unix, it's a bit more elegant - just linefeed (10) for new-line. 

The code in your last post is almost identical to what you'd do in C++. Do not expect any speedup, and don't get shocked if your asm code is slower (just due to a different output-buffering method).
You want to shock people with 300 times speedup in asm, don't you :P - then type some serious code.
Please use a smaller graphic in your signature.

RuiLoureiro

Quote from: Dami3n on December 11, 2007, 07:45:24 PM
Why is that identifier like this?
number     DWORD ?,0 <- Why the question mark, is it because we cannot be sure how big value is it going to be?

Hi Dami3n,
              Search this forum for DWORD. You can learn many things about DWORD, BYTE, WORD, etc.

RuiLoureiro 

Dami3n

ok then with help of post ossama made i did copied this, let me just ask something:

include \masm32\include\masm32rt.inc
.data
szLoopFinished db "Done",0
.code

start:
xor eax,eax ;<- Kill eax, set it as 0 if im not wrong :/
@@: ; <- Fancy pancy label or something
inc eax ;Increase eax ofc
cmp eax,0ffffffffh ; <- Hex? alot if it is :O
jb @B ;<- Jumping back? where to? At @@?
invoke MessageBox,NULL,addr szLoopFinished,NULL,MB_OK ;<- Messagebox :D
end start


On line 10 there is code "cmp eax,0ffffffffh". I know its comparing 0fffffffh to eax and jumping if eax is below that value.
Is 0ffffffffh hex and means value 4294967295 at dec? if that's it then  :dazzled:

jj2007

Quote from: Dami3n on December 12, 2007, 07:57:46 PM
Is 0ffffffffh hex and means value 4294967295 at dec? if that's it then  :dazzled:
Yes it is - but don't worry, assembler is pretty fast indeed  :green

Tedd

Yes, you got it right - it just counts from 0 up to 4294967295 (the largest 32-bit number) and then shows a messagebox.
{Though you should really add "invoke ExitProcess, NULL" to the end of that to exit correctly.}

"@@:" is a special 'anonymous' label, where you need one but don't want to keep thinking up pointless names - they're useful for short loops and jumps. Then "@B" refers to the previous @@ label, and "@F" to the next one -- you can have multiple @@ labels without getting assembly warnings/errors.
No snowflake in an avalanche feels responsible.

Dami3n

Quote from: jj2007 on December 12, 2007, 08:42:09 PM
Quote from: Dami3n on December 12, 2007, 07:57:46 PM
Is 0ffffffffh hex and means value 4294967295 at dec? if that's it then  :dazzled:
Yes it is - but don't worry, assembler is pretty fast indeed  :green
hahahah of course its fast :D took only 1 or 2 seconds to run it :dance:

Quote from: Tedd on December 13, 2007, 12:05:33 PM
Yes, you got it right - it just counts from 0 up to 4294967295 (the largest 32-bit number) and then shows a messagebox.
{Though you should really add "invoke ExitProcess, NULL" to the end of that to exit correctly.}

"@@:" is a special 'anonymous' label, where you need one but don't want to keep thinking up pointless names - they're useful for short loops and jumps. Then "@B" refers to the previous @@ label, and "@F" to the next one -- you can have multiple @@ labels without getting assembly warnings/errors.

wow thanks, that is really good information to know  :U , i hate pointless names, they suck...
and thanks for the tip, will do  :boohoo: