well i am new to asm and i dunno many.

this simple formula eatin my brain. this c code, please help convet to masm style asm. Please.



result = ((sr * a) + (dr * (255 - a))) / 255


it is for alpha bland of func asm.

thank everybody in advancement.
Posted on 2003-11-22 02:57:33 by salad.dressing
salad.dressing,

The forumula would eat my brain too :grin: . It's not that hard you have parentheses to help you. Just work from the inside out and remember the operator precedence rules. But here's my attempt :)

 

mov eax, 255
sub eax, a
imul dr
mov ecx, eax
mov eax, sr
imul a
add eax, ecx
mov ecx, 255
cdq
idiv ecx
Posted on 2003-11-22 05:40:12 by Odyssey
mov	edx, 255

mov eax, a
sub edx, eax
imul eax, sr
imul edx, dr
mov ecx, 255
add eax, edx
cdq
idiv ecx
Here is another version.

Most likely you'll want a much faster version.
Posted on 2003-11-22 06:44:08 by bitRAKE
You probably should use MMX, its much easier to code and faster as well.
Posted on 2003-11-22 07:17:24 by x86asm
where i find mmx tuts. i am newbie. this formul above use floting numbers, but u performer int math. how in floting numbers to do.

thank you everyone for your solutions.

bitRAKE you have some your own tuts. pls can u help by writing examples of convert simple expresions to asm. may be that could help me.

salad.dressing
Posted on 2003-11-22 08:17:00 by salad.dressing
Hi :)
Another version using FP opcodes:


mov eax,255
push eax
fild dword ptr [esp]
fsub a
fmul dw
fld sr
fmul a
faddp st(1),st(0)
fidiv dword ptr [esp]
fstp result
pop eax

Yet another version, this time with integer params and result:


;result = ((sr * a) + (dr * (255 - a))) / 255
mov eax,255
push eax
fild dword ptr [esp]
fild a
fsubp st(1),st(0)
fild dw
fmulp st(1),st(0)
fild sr
fild a
fmulp st(1),st(0)
faddp st(1),st(0)
fidiv dword ptr [esp]
fistp result
pop eax

I'm new at FP programming so any suggestions/corrections are welcome.
Posted on 2003-11-22 08:27:39 by QvasiModo

where i find mmx tuts


The only tutorial I know of for mmx is the chapter on the mmx instruction set in the art of assembly language 32 bit edition text. That text also has a chapter on integer and floating point arithmetic. It covers the arithmetic instructions and how to convert HLL arithmetic expressions into assembly language. If you don't have anything against HLA you could check it out :). If you do I know of another good fpu tutorial that uses masm. You can it at http://www.masmforum.com/website/tutorials/index.html

Hope that helps :)
Posted on 2003-11-22 08:35:42 by Odyssey
well wow :)

thank u everybody and odyssey for uick solution. i like that. i heard lot about hla, but if i learn will i able to translet to normal masm? if yes, i will learn it.

thank

salad.dressing
Posted on 2003-11-22 08:43:39 by salad.dressing
It's very easy to convert code from HLA syntax to masm syntax and it should be easier for you because you are familiar with the masm syntax already. If you're in doubt about how to convert HLA code you can look at the masm code it generates.
Posted on 2003-11-22 08:47:56 by Odyssey
thank you

very nice hla. i instantly like it. only have to read book. Randy is very good writer. thanks you randy for such good product. i'm very enlightened.

salad
Posted on 2003-11-22 09:01:01 by salad.dressing

very nice hla. i instantly like it.


What do you like about it? :)
Posted on 2003-11-22 09:05:26 by Odyssey
simplicity.
Posted on 2003-11-22 09:17:15 by salad.dressing

simplicity.


Thats interesting :grin: . HLA has a lot of features that make it easier to use than traditional assemblers but like the HLL control structures and the standard library but it also has a lot of advanced features too. Like Randy has said before, he created HLA for beginners and for advanced programmers (him) :grin:
Posted on 2003-11-22 09:30:19 by Odyssey