flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > How this macro convert to asm ? |
Author |
|
macomics 22 Apr 2023, 13:24
Roman wrote: First question how write this to asm ? Last edited by macomics on 22 Apr 2023, 13:26; edited 1 time in total |
|||
22 Apr 2023, 13:24 |
|
Roman 22 Apr 2023, 13:45
I try but not correct result.
Code: txt db '55445',0 macro mdig t { mov ebx,1 xor edx,edx xor eax,eax l1: mov al,[t-1+ebx] test al,al jz ext mov cl,8 sub cl,bl shl cl,3 shr ax,cl ;(8-ecx)*8 and al,0ffh sub al,48 add edx,eax inc ebx cmp ebx,8 jb l1 ext: } mdig txt ;edx=334h wrong. Right edx=D895h |
|||
22 Apr 2023, 13:45 |
|
macomics 22 Apr 2023, 14:18
Your problem is that you have already taken the necessary byte and are doing operations on it, which fasm does immediately on the qword to get this same byte.
fasm does not have the ability to address a string constant by indexes to get bytes. You have it. You used it Code: mov al, [t-1+ebx] Then why do you need the rest of the shift operations? Code: mov cl,8 sub cl,bl shl cl,3 shr ax,cl ;(8-ecx)*8 and al,0ffh You can immediately move 0 to ebx and you won't need -1 when indexing |
|||
22 Apr 2023, 14:18 |
|
Roman 22 Apr 2023, 15:46
Oh ! I do this. Convert virtual text to int value.
Code: virtual at 0 ark:: ark_txt1 db '55445',0 ;i think i can do 64 bit int values ! ;ark_txt1 db '44441554451230',0 ;yes i test and get rax=286B5B10FB1Eh ark_size: end virtual ;in code Start: kuuu = 0 repeat ark_size load a byte from ark:%-1 if a = 0 break end if kuuu = kuuu*10+a-48 end repeat mov eax,kuuu ;eax=D895h (decimal 55445) |
|||
22 Apr 2023, 15:46 |
|
Roman 22 Apr 2023, 16:51
Found formula sin.
How adapted this for fasm preprocessor ? Enough float not double. Code: double sin_e2(double x) { double result = 0; int sign = 1; double xx = x * x; double pw = x; double fti = 1.0; for(int i = 1; i < 25; i += 2) { fti /= i; result += sign * pw * fti; fti /= ( i + 1 ); sign = -sign; pw *= xx; } return result; } |
|||
22 Apr 2023, 16:51 |
|
revolution 22 Apr 2023, 16:57
rept will do preprocessor arithmetic. Good luck.
|
|||
22 Apr 2023, 16:57 |
|
Roman 22 Apr 2023, 16:59
Quote: rept will do preprocessor arithmetic. Good luck. Thanks But not supported 1.0/num. |
|||
22 Apr 2023, 16:59 |
|
revolution 22 Apr 2023, 17:06
Roman wrote: But not supported 1.0/num. Code: rept 1 x:1/2 { display x+'0' } |
|||
22 Apr 2023, 17:06 |
|
Roman 22 Apr 2023, 17:42
Quote:
Show 0 And what is practical using rept 1 x:1/2 ? Code: rept 1 x:1/2 { mov eax, x#f } ;get mov eax,0 Fiasco |
|||
22 Apr 2023, 17:42 |
|
revolution 22 Apr 2023, 19:00
revolution wrote: You might want to consider fixed point arithmetic using integers. |
|||
22 Apr 2023, 19:00 |
|
Roman 22 Apr 2023, 22:08
X = 360/angl/180*3.14
1-x |
|||
22 Apr 2023, 22:08 |
|
macomics 22 Apr 2023, 22:40
Code: fldpi fild dword [const360] fidiv dword [angl] fidiv dword [const180] fmulp st0, st1 ... const360 dd 2 const180 dd 1 angl dd 5 |
|||
22 Apr 2023, 22:40 |
|
Roman 23 Apr 2023, 11:20
Code: mov eax,179.0 call mysin ;all ok, but failed on 180.0 get 6.01 must 0 mysin:xorps xmm3,xmm3 cmp eax,180.0 jz .2 cmp eax,0 jz .2 movd xmm1,eax ;x angle mov eax,1.0 movd xmm4,eax ;i movd xmm5,eax mov eax,180.0 movd xmm0,eax divss xmm1,xmm0 ;failed if xmm1=0 or 180 mulss xmm1,[.pi] ;x/180*pi convert to degree movss xmm0,xmm1 ;q mulss xmm1,xmm1 ;x*x mov ecx,5*2 .1: addss xmm3,xmm0 ;s+q mulss xmm0,[.min] ;q = q* (-1) * (x*x) / ((2*i+1) * (2*i)) mulss xmm0,xmm1 movss xmm6,xmm4 addss xmm6,xmm6 movss xmm7,xmm6 addss xmm6,xmm5 mulss xmm6,xmm7 divss xmm0,xmm6 addss xmm4,xmm5 ;i+1 dec ecx jnz .1 ;xmm3 out sin(x) .2: ret .pi dd 3.141592 .min dd -1.0 |
|||
23 Apr 2023, 11:20 |
|
revolution 24 Apr 2023, 10:02
The FPU has fsin.
|
|||
24 Apr 2023, 10:02 |
|
Roman 24 Apr 2023, 10:20
Quote: The FPU has fsin. I know. And have fsincos too. But fasm preprocessor not have. And me interesting calculate sin this way , for my education. And have another way calculated sin, if cpu not have fpu or sse,avx. Ok. How rewrite mysin to int for regs eax\edx ? EAX=4 EDX=5455 this equivalent float 4.5455 |
|||
24 Apr 2023, 10:20 |
|
revolution 24 Apr 2023, 10:34
Roman wrote: Ok. How rewrite mysin to int for regs eax\edx ? revolution wrote: You might want to consider fixed point arithmetic using integers. |
|||
24 Apr 2023, 10:34 |
|
Roman 24 Apr 2023, 10:44
This ?
Code: #define cordic_1K 0x26DD3B6A // 1/k = 0.6072529350088812561694 #define half_pi 0x6487ED51 // pi / 2 #define MUL 1073741824.000000 // 1.0 = 1073741824 #define CORDIC_NTAB 32 int cordic_tab [] = { 0x3243F6A8, 0x1DAC6705, 0x0FADBAFC, 0x07F56EA6, 0x03FEAB76, 0x01FFD55B, 0x00FFFAAA, 0x007FFF55, 0x003FFFEA, 0x001FFFFD, 0x000FFFFF, 0x0007FFFF, 0x0003FFFF, 0x0001FFFF, 0x0000FFFF, 0x00007FFF, 0x00003FFF, 0x00001FFF, 0x00000FFF, 0x000007FF, 0x000003FF, 0x000001FF, 0x000000FF, 0x0000007F, 0x0000003F, 0x0000001F, 0x0000000F, 0x00000008, 0x00000004, 0x00000002, 0x00000001, 0x00000000 }; void cordic32_sin_cos(int alpha, int *s, int *c, int n) { int k, d, tx; int z = alpha; *c = cordic_1K, *s = 0; n = (n > CORDIC_NTAB) ? CORDIC_NTAB : n; if(n<3) n = 3; for (k=0; k<n; ++k) { d = z >> 31; //d = z>=0 ? 0 : -1; tx = *c;why need this ? *c -= (((*s>>k) ^ d) - d);why need this ? *s += (((tx>>k) ^ d) - d);why need this ? z -= ((cordic_tab[k] ^ d) - d); } } // y = s, x = c int cordic32_atan2(int s, int c, int n) { int k, d, angle = 0; int re = c, im = s, tx; n = (n > CORDIC_NTAB) ? CORDIC_NTAB : n; if(n<3) n = 3; for (k=0; k<n; ++k) { d = im >> 31; angle += ((cordic_tab[k] ^ d) - d); tx = re; re += (((im>>k) ^ d) - d); im -= (((tx>>k) ^ d) - d); } return angle; } |
|||
24 Apr 2023, 10:44 |
|
Roman 24 Apr 2023, 12:58
|
|||
24 Apr 2023, 12:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.