BBC BASIC for Windows
Programming >> Assembly Language Programming >> Using variables in Assember
http://bb4w.conforums.com/index.cgi?board=assembler&action=display&num=1369848290

Using variables in Assember
Post by Matt on May 29th, 2013, 5:24pm

Hi,

(Edit: just figured out what the problem to this is - memory allocation is too small.)

Ok. What am I missing here. I've checked all the help I can find, but I still can't work it out.

This works (extrapolated from BB4W help):
Code:
      ypos% = 10
      xpos% = 10
      DIM code 20
      FOR opt=1 TO 3 STEP 2
        P%=code
        [OPT opt
        .win
        push 5
        push 0
        push 0
        push ypos%
        push xpos%
        push 0
        push @hwnd%
        call "SetWindowPos"
        ret
        ]
      NEXT
      CALL win 


x/ypos% variables seem to be set in the memory as absolute vaues. Therefore changing them and then RE-calling the code makes no difference. This I understand.

However, looking at the code in MDILIB.BBC...

Code:
...
      .N%
      cmp dword [esp+8],&600 : jz M%
      pop eax : push [^O%] : push eax : jmp "CallWindowProc"
      ]
      SYS "GetWindowLong",@hwnd%,-4 TO O%
      SYS "SetWindowLong",@hwnd%,-4,N%
... 


This seems to imply form my novice perspective that using push [^variable] instead of just push variable should allow the variable to be changed and then the code to be re-called.

From BB4W Help:
Quote:
In assembly language code you might want to copy the value of a BBC BASIC (integer) variable into one of the processor's registers:
mov eax,[^variable%]


However,
Code:
      DIM code 20
      FOR opt=1 TO 3 STEP 2
        P%=code
        [OPT opt
        .win
        push 5
        push 0
        push 0
        push [^ypos%]
        push [^xpos%]
        push 0
        push @hwnd%
        call "SetWindowPos"
        ret
        ]
      NEXT
      ypos% = 10
      xpos% = 10
      CALL win 


not only doesn't work, it crashes BB4W.

I'm obviously missing something fundamental and probably quite obvious to others, but I just cannot figure this out (and I'm getting tired of restarting BB4W).

Matt
Re: Using variables in Assember
Post by Matt on May 29th, 2013, 9:04pm

What's the easiest way to check what memory is required? The only way I can see of doing it is to over estimate, then look at the memory locations on the listing and work out the usage from that. This can then be used to edit the program.

Matt

Edit: Worked it out :- end code with PRINT P%-code
Re: Using variables in Assember
Post by admin on May 29th, 2013, 9:18pm

on May 29th, 2013, 5:24pm, Matt wrote:
Ok. What am I missing here.

What you are missing is that you are using FOR opt=1 TO 3 STEP 2 when you should be using FOR opt=9 TO 11 STEP 2 with L% initialised appropriately. That will raise an error if you exceed the allocated space.

Richard.
Re: Using variables in Assember
Post by Matt on May 30th, 2013, 04:55am

Thanks Richard,

I overlooked that 'bit'.

Matt