flat assembler
Message board for the users of flat assembler.

Index > Windows > syntax issues

Author
Thread Post new topic Reply to topic
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 19 Sep 2009, 05:31
What am I doing wrong? / What is the best way to do this?

Code:
f:      push    rbp
        sub     rsp,8*4
        mov     rbp,rsp

  Frequency = rbp+8*0
  StartTime = rbp+8*1
  EndTime   = rbp+8*2
  LocVar    = rbp+8*3

        invoke  QueryPerformanceFrequency, addr Frequency
        invoke  QueryPerformanceCounter, addr StartTime
        ...

        add     rsp,8*4
        pop     rbp
        ret    
Post 19 Sep 2009, 05:31
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael 19 Sep 2009, 08:01
Code:
foo = sth    
declares an assembly-time constant or variable. Value of rbp register of course isn't known at compile time, so this is invalid.
Use equ:
Code:
Frequency equ rbp+8*0
StartTime equ rbp+8*1
;and so on    
Post 19 Sep 2009, 08:01
View user's profile Send private message Reply with quote
roxaz



Joined: 27 Jul 2008
Posts: 25
roxaz 19 Sep 2009, 08:02
how about using struct?

Code:
include '%fasminc%\win64a.inc'

struct Structure
  Frequency dq ?
  StartTime dq ?
  EndTime   dq ?
  LocVar    dq ?
ends

section '.text' code readable executable

  start:
        push    rbp
        sub     rsp,8*4
        mov     rbp,rsp

        invoke  QueryPerformanceFrequency, [rbp+Structure.Frequency]
        invoke  QueryPerformanceCounter, [rbp+Structure.StartTime]


        add     rsp,8*4
        pop     rbp
        ret      
Post 19 Sep 2009, 08:02
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Sep 2009, 16:33
Or this:
Code:
  start:

  virtual at rbp - .locals_size
      .Frequency dq ?
      .StartTime dq ?
      .EndTime   dq ?
      .LocVar    dq ?

  .locals_size = ($ - $$ + 7) and -8
  end virtual

        push    rbp
        mov     rbp, rsp
        sub     rsp, .locals_size


        invoke  QueryPerformanceFrequency, addr .Frequency
        invoke  QueryPerformanceCounter, addr .StartTime


        mov     rsp, rbp
        pop     rbp
        ret    


[edit]Replaced code with one using rbp in a more "canonical" way.
[edit2]Parameters modified to the correct ones.[/edit2]


Last edited by LocoDelAssembly on 19 Sep 2009, 16:54; edited 2 times in total
Post 19 Sep 2009, 16:33
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 19 Sep 2009, 16:35
thanks, I didn't know about equ.
But, the code generated for the invoke should be:
Code:
        sub     rsp,8*2
        lea     rcx,[Frequency]
        call    [QueryPerformanceFrequency]
        add     rsp,8*2         

and I haven't been able to get inoke to do this
Post 19 Sep 2009, 16:35
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Sep 2009, 16:40
What do you get instead?
Post 19 Sep 2009, 16:40
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 19 Sep 2009, 16:51
revolution,
that code has the same problem in that it generates
mov rcx,[rbp+8]
When calling QueryPF, rcx should be a pointer to the stack location:
sub rsp,8*2
lea rcx,[rbp+8*n]
call [QueryPerformanceFrequency]
add rsp,8*2
Post 19 Sep 2009, 16:51
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Sep 2009, 16:55
Well, I guess you are talking to me actually Wink

Yes sorry, I used the wrong parameters, I edited my code again, check it if it now works.
Post 19 Sep 2009, 16:55
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 19 Sep 2009, 16:56
I though
invoke QueryPF, addr Frequency
would do it, but this doesn't assemble. maybe a bug in the invoke macro?
Post 19 Sep 2009, 16:56
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 19 Sep 2009, 17:01
Sorry! LocoDelAssembly,
With your edited code, on the first invoke line I get a
Error: invalid operand
insruction: inc addr .Frequency
source: timingtest.asm[28]
proc64,inc [5]
proc64.inc [41]

using FASM 1.68
Post 19 Sep 2009, 17:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Sep 2009, 17:33
Oh, I'm using FASM 1.69.04. "addr" is present in PROC64.INC (in the case of 32-bit programming "addr" is located in win32{a|w}x.inc instead of PROC32.INC).

However, I see that FASM 1.68 also has "addr" defined in PROC64.INC. Perhaps you are not using the very latest version? (last update: 24 Aug 2009 14:13:10 UTC)
Post 19 Sep 2009, 17:33
View user's profile Send private message Reply with quote
tthsqe



Joined: 20 May 2009
Posts: 767
tthsqe 19 Sep 2009, 19:30
I got the new version, and it assembled it correctly.
Post 19 Sep 2009, 19:30
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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.