Skip to main content

ADDRESSOF

Syntax

ADDRESSOF variable_name

    or

ADDRESSOF subroutine_name

Description

ADDRESSOF will return the address of a variable or subroutine.

Example

#include "LPC11xx.bas"

dim e3 as integer
dim s3 as
integer

INTERRUPT SUB TIMER1IRQ
T1_IR =
1 ' Clear interrupt
e3 = e3 + 1

ENDSUB

SUB ON_TIMER ( msec, dothis )

TIMER1_ISR = dothis + 1 'set vector in
VIC -- the +1 for Thumb operation
VICIntEnable =
VICIntEnable or (1<<19) 'Enable interrupt
T1_MR0 =
msec-1 ' set up match number of ms
T1_MCR =
3 ' Interrupt and Reset on MR0

T1_IR = 1 ' clear interrupt
T1_TC =
0 ' clear timer counter

T1_TCR = 1 ' TIMER1
Enable
ENDSUB

main:
print "TIMER1 Interrupt Test"

print "TIMER1 will interrupt every 2 seconds and print a dot"

ON_TIMER(2000, ADDRESSOF TIMER1IRQ)
s3 = 0
e3 =
0

WHILE (1)
if s3 <> e3
then
s3 = e3

print ".";
endif
LOOP

Cortex M series parts are running in Thumb code, which uses 16 bit instructions. Addresses used for the PC (program counter) indicate Thumb mode by setting the LSB of the address. That is why you see the vectors such as

    TIMER1_ISR   = dothis + 1  ' set vector in the VIC

If you do not set this bit,the program will crash in the LPC11xx, LPC17xx parts. Do not set it for LPC21xx parts.

Differences from other BASICs

  • similar to VB
  • no equivalent in PBASIC

See also