Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable and pointer on the same line 1

Status
Not open for further replies.

MrSteveMan

Technical User
Dec 26, 2000
6
US
Im trying to program a PIC microcontroller. I have the lines

number
call zero
call one
call two
.
.
.
call ten
return

call nuber + i

where i is an integer. I want to call the adress of "number", plus the value of "i", but my program calls the adress of "number" plus the adress of "i". Is there a way around this?

Iv'e tried declaring i as a variable.
Thanks
 
Move the value of i into a register (a variable is simply an index into memory) and then do

call number + ax, or whatever your register reference is. As always, I hope that helped!

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
That worked! All I can say is, DUH!!
Thanks a bunch.
 
I spoke too soon. I'm still having trouble.
I have the following lines:

movf dec1
movwf PORTB
call number + PORTB

where dec1 holds the value 0..9, and PORTB is a register.
The interface that I'm using has a program memory window which displays these lines for the lines above:

movf 0x28,w
movwf 0x6 <----
call 0x191

When I call number + PORTB, it calls number + 0x6 (0x191) no matter what value is in PORTB. I want to be able to call number + the value stored in PORTB (not it's adress).
Any clues?
Thanks again
 
movf dec1
movwf PORTB
add number into PORTB (However you do this)
call PORTB
(If you need PORTB as it was, just subtract number PORTB now)

Does this work?


Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
How is PORTB a register? It sounds like a memory location
to me where you are storing a value.

I'm not exactly what your calling method is trying to do
but I'm guessing you are looking to use one call statement
to be able to call the correct place based on the value of
i... Correct? Well, you have to realize that when
Assembly programs are compiled, all memory locations are
compiled as constants, not variables. In order to
accomplish what you want to do, I can think of two things:

1. Make each chunk (call zero, call one...) the same #
bytes long and call location_call_zero + i chunks later
Like so (not knowing specific syntax):
mov ax, ;get value of i,(mov ax, i gets location)
;i is a word? byte?
mul constant_number_bytes_per_chunk
add ax, zero
;Thus, if zero is at mem 0x1000 and each chunk is 10 bytes
;and i=5 then it calls location 0x1000 + (5 * 10)

2. Use the xlat command to get the locations... This is
a little more complicated than i originally thought but
...
mov bx, table ;point to base of table b/c xlatb command
;makes al equal the byte at location
;ds:bx + al ...
xor ax, ax
mov al,
mul 2 ;multiply by two b/c xlatb command uses
;bytes but our table is in words
xlatb ;get low byte of location
mov cl, al ;save it
mov al,
mul 2
inc al ;next byte will be high byte of location
xlatb ;get high byte into al
mov ah, al ;move high byte to high end of ax register
mov al, cl mov low byte back
call ax

......

table dw zero, one, two, three, four, five ;ETC

This effectively makes a table of constant value locations
of the procedure calls at compilation time. Then, it calls
the correct location when the time comes

While number 1 is clearly more simple, it requires you to
keep your procedures to a constant number of bytes. You
could do this by adding sufficient db # commands after
each ret if they aren't already the same size or you could
use the more complicated second method.
 
Ok, oconnellb, I used your first method. Seems to work quite nicely, and not too complicated. Thanks a lot guys for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top