flat assembler
Message board for the users of flat assembler.

Index > Main > Tomasz please show tutorial add new command to tables.inc

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 04 May 2023, 16:37
Quote:

This isn't the preprocessor, it is the assembler.

This is ASSEMBLE.INC ? Right ?
Nice. And how assembler calculated cos ? Smile

And where is (in ASSEMBLE.INC) i put my call my_cos_calc ?
Post 04 May 2023, 16:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 04 May 2023, 16:41
Look in EXPRCALC.INC & EXPRPARS.INC

You can compute COS with fcos
Post 04 May 2023, 16:41
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 04 May 2023, 16:50
I found in EXPRCALC.INC this:
Code:
        je      calculate_rva
        cmp     al,0F1h
        je      calculate_plt
        cmp     al,0D0h
        je      calculate_not
        cmp     al,0E0h
        je      calculate_bsf
        cmp     al,0E1h
        je      calculate_bsr    


How i understand, i put this:
Code:
        je      calculate_rva
        cmp     al,0F1h
        je      calculate_plt
        cmp     al,0D0h
        je      calculate_not
cmp     al,0D1h
je      calculate_cos
cmp     al,0D2h
je      calculate_sqrt
        cmp     al,0E0h
        je      calculate_bsf
        cmp     al,0E1h
        je      calculate_bsr    


Ok i writing my calculate_cos, but how and where is i put\store my result from cos ?
And how i get value for cos ?
Or i want store matrix4x4 its 16 floats(each 4 bytes), where is i put\store this floats array ?

I see this using ebx and edi:
Code:
;for what  using EBX and for what using EDI ?
shr_over:
        movsx   eax,byte [ebx+13]
        mov     dword [ebx],eax
        mov     dword [ebx+4],eax
        jmp     calculation_loop

finish_bs:
        add     eax,ecx
        xor     edx,edx
        mov     [edi],eax
        mov     [edi+4],edx
        mov     [edi+13],dl
        add     edi,14h
        jmp     calculation_loop
    


I apply cos to fasm.exe compiler.
Code:
;EXPRCALC.INC
calculate_cos:
        mov     eax,[current_line]
        mov     [error_line],eax
        ;mov     [error],edx
        mov     [error_info],error_cos_test ;i do this only for reaction on my cos !
        jmp     calculation_loop
error_cos_test: db 'cos ',0    

And do test.
Code:
mov eax,cos ;compiled ok  ! But i not see message: error_cos_test !
mov eax,cos 1.3 ;error ! Extra characters on line    


IDA Pro show:
mov eax, offset cos ; cos as dd data ! Nice.
mov eax, [cos] ;this work too !
movd xmm1,eax ;xmm1= 5.8111381e32. But how fasm put in cos this value ?

How do cos out value direct eax, not from address cos data ?
mov eax,1.0 ;cos 0
Post 04 May 2023, 16:50
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 05 May 2023, 03:39
cos exist in msvcrt. Inc
I do cos_fasm

Second I put call Messagebox in calculate_cos:
Code:
 

;EXPRCALC.INC
calculate_cos:
        pusha
Invoke Messagebox, 0,"cos_fasm"
Popa
        jmp     calculation_loop
    

Compile new version Fasmw ide

Run new version IDE

Code:
;compiled in new version Fasmw 1.73 
mov eax, cos_fasm 2 ;first compiler pass I see messageBox
;second compiler pass error on cos_fasm "invalid value"
    
Post 05 May 2023, 03:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 05 May 2023, 04:36
You need to process the value that follows your operator and update the registers (IIRC esi needs to be advanced). You can use not as an example of how to process the value.
Post 05 May 2023, 04:36
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 05 May 2023, 07:00
I done !
Code:
;EXPRCALC.INC
calculate_cos:  
                cmp     word [edi+8],0
                jne     invalid_expression
                cmp     byte [edi+12],0
                je      cos_fasm_ok_1
                call    recoverable_misuse
                
cos_fasm_ok_1:  fld  dword [edi] ;get fasm number
                fmul dword [error_cos_test-4]  ;convert radians to degrees
                fcos
                fstp dword [edi]            
                add  edi,14h
              
                jmp     calculation_loop

        dd 0.017452       
error_cos_test:         
    

I calculated one cos. But how calculated array 12 cos ?


Last edited by Roman on 05 May 2023, 08:32; edited 1 time in total
Post 05 May 2023, 07:00
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 05 May 2023, 07:19
Roman wrote:
... how calculated array 12 cos ?
With a loop.
Code:
while % <= 12
  ; cos goes here
end while    
Post 05 May 2023, 07:19
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 05 May 2023, 07:44
One problem.
Code:
mov eax,cos_fasm 0x3F800000 ;compiled ok.
mov eax,cos_fasm 1.0   ;fasm get error "reserved word used as symbol"
mov eax,cos_fasm 1f    ;fasm get error "reserved word used as symbol"
    
Post 05 May 2023, 07:44
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 05 May 2023, 08:34
in fasm expression elevation not handles floats. 0x3F800000 - it is integer, 1.0 & 1f - floats
Code:
calculate_expression:
        mov     [current_offset],edi
        mov     [value_undefined],0
        cmp     byte [esi],0
        je      get_string_value
        cmp     byte [esi],'.'
        je      convert_fp
      calculation_loop:     
as thou can see calculation loop happend with filtering floats before entry to calculation_loop - "cmp byte [esi],'.'" and within all inner checks of calculation_loop handling of floats - absent and handled with "jmp invalid_expression".
so thou have to add such handling if needed.
Post 05 May 2023, 08:34
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 05 May 2023, 08:37
I see fasm store two values in edi:
dword [edi] and dword [edi+4]


What stored in dword [edi+4] ?
Code:
calculate_not:
        cmp     word [edi+8],0
        jne     invalid_expression
        cmp     byte [edi+12],0
        je      not_ok
        call    recoverable_misuse
      not_ok:
        not     dword [edi]            ;this is fasm 32bit value.
        not     dword [edi+4]          ;What stored in dword [edi+4] ? 
        not     byte [edi+13]          ;What stored byte [edi+13] ? 
        add     edi,14h
        jmp     calculation_loop    
Post 05 May 2023, 08:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20513
Location: In your JS exploiting you and your system
revolution 05 May 2023, 10:05
Roman wrote:
What stored in dword [edi+4] ?
Values are not simply 32-bit integers.

You can store 64-bit values with an extra sign bit. eg. +-0xfedcba9876543210
You can store registers, with multipliers, with an offset. eg. rax+4*rdx-0xfedcba9876543210

And you can do arithmetic on those: eg (eax+4*edx+8) - (eax+2*edx+4) == (2*edx+4)
Post 05 May 2023, 10:05
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 05 May 2023, 11:03
Ok.
If I want implemented vec3add, how get 4 params in calculate_vec3add ?
Code:
PointXYZ DD vec3add 1,2,5,10 ;out DD 10,20,50    
Post 05 May 2023, 11:03
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 05 May 2023, 11:44
Most of your problems have a solution, designed years ago. I called it fasmg. Sticking to fasm 1 and trying to bend it to do all these things is a way of tormenting oneself, but it is a choice you are allowed to make.

Code:
include 'inline.inc'

inlinemacro vec3scale x,y,z, c
        return equ (x)*c, (y)*c, (z)*c
end inlinemacro

PointXYZ DD vec3scale(1,2,5, 10) ; DD 10,20,50
FPointXYZ DD vec3scale(1f,2f,5f, 10) ; DD 10.0,20.0,50.0    
Post 05 May 2023, 11:44
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 05 May 2023, 11:52
Nice.
But how do I get(in Fasm 1) four values for vec3add ?

PointXYZ DD vec3add 1,2,5,10 ;out DD 10,20,50

Or my calculate_vec3add: store all vec3 to my buffer
vec3pop out all vec3 from my buffer to dd

Code:
$vec3add   (1,2,3,10)
$vec3add   (3,2,1,30)
$vec3scale (13,22,31,80)
points dd $vec3pop 3

;Using text or pointer to text ?
$vec3add "1,2,3,10"

;or this variant
virtual at 0                       
                    virt_vec3a1 db '1,2,3,10',0
end virtual 
$vec3add  virt_vec3a1 ;but how get text from virt_vec3a1 address ?

;or load from text file.
$vec3add 'vdt1'  ;my calculate_vec3add load and read data from file vdt1.txt !
    


Last edited by Roman on 05 May 2023, 12:49; edited 5 times in total
Post 05 May 2023, 11:52
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 817
Location: Russian Federation, Sochi
ProMiNick 05 May 2023, 12:08
Roman, in fasmg calculation with floats allowed, but in fasm 1 not. Thou`ll have to backport this ability by hands (no one except thourself will not introduce that feature in fasm 1) or use fasmg instead.
Answer on "But how do I get(in Fasm 1) four values for vec3add ?": Thou could preproce code in fasmg previously than compile in fasm.
.
Post 05 May 2023, 12:08
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 05 May 2023, 12:11
Quote:
Thou could preproce code in fasmg previously than compile in fasm

Previously this mean save data in binary file ?

I using directx11 Compute shader(generating some ) and save data as binary file or as text file.

Quote:
in fasmg calculation with floats allowed

How about cos,sin,sqrt,round,fpatan,cross, matrix4x4 multiplication ?
Post 05 May 2023, 12:11
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 06 May 2023, 09:26
Strange passes
Code:
;EXPRCALC.INC
calculate_cos:  
                cmp     word [edi+8],0
                jne     invalid_expression
                cmp     byte [edi+12],0
                je      cos_fasm_ok_1
                call    recoverable_misuse
                
cos_fasm_ok_1:  
                inc  byte [.cnt]
                inc  byte [.cnt+2]
                cmp  byte [.cnt],4
                jb     .2
                mov  byte [.cnt],0
                mov  byte [.cnt+2],48
.2:             movzx eax,byte [.cnt]
                ;shr   eax,1
                movss xmm0,[.vec4+eax*4]
                movss [edi],xmm0
                add  edi,14h
                pusha
                invoke MessageBox,0,.cnt+2,0,0
                popa
                jmp     calculation_loop

.vec4        dd 1.0,2.0,3.0,4.0
.cnt         db -1,0,47,0 
    


If in new version fasmw i do:
Code:
 
;if i writing only one cos: 
mov eax,cos 0  ;i get eax=4.0, but i expected eax=1.0
                       ;i get four MessageBox 0 than 1 than 2 than 3

;if i writing two cos:
mov eax,cos 0  ;i get eax=3.0, but i expected eax=1.0
                       ;i get four MessageBox 0 than 1 than 2 than 3
mov eax,cos 0  ;i get eax=4.0, but i expected eax=2.0
                       ;i get four MessageBox 0 than 1 than 2 than 3
;how do executing my cos one time? 

    
Post 06 May 2023, 09:26
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 08 May 2023, 07:45
I see one cos push four values on something like as stack.
Last pushed 4.0 and first out 4.0
And why needed commited four times one cos ?
Post 08 May 2023, 07:45
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.