Address of a variable: Difference between revisions

Content deleted Content added
m →‎{{header|REXX}}: changed comment.
Mmphosis (talk | contribs)
Applesoft BASIC
Line 198:
z = PEEK(y)
z = z + (PEEK(y) * 256)</lang>
 
=={{header|Applesoft BASIC}}==
 
=== Get the address ===
Get the address of the last variable used.
<lang ApplesoftBasic>N = N : PRINT PEEK (131) + PEEK (132) * 256</lang>
Get (find) the address of a function.
<lang ApplesoftBasic>0 DEF FN F(X) = 0
1 FOR A = PEEK(105) + PEEK(106) * 256 TO PEEK(107) + PEEK(108) * 256 STEP 7 : IF PEEK(A) <> ASC("F") + 128 OR PEEK(A + 1) <> 0 THEN NEXT A : A = 0 : PRINT "FN F NOT FOUND"
2 IF A THEN ? A
</lang>
 
=== Set the address ===
Set the address where variables are stored, but clears all variables.
<lang ApplesoftBasic>LOMEM: 4096
I% = I% : PRINT PEEK (131) + PEEK (132) * 256
</lang>
Set the address and length of a string.
<lang ApplesoftBasic>S$ = "HELLO" : POKE 768, PEEK (131) : POKE 769, PEEK (132) : A = PEEK(768) + PEEK(769) * 256
PRINT S$ : PRINT A "- " PEEK(A) " " PEEK(A + 1) + PEEK(A + 2) * 256
POKE 768, ASC("H") : POKE 769, ASC("I") : POKE A, 2: POKE A + 1, 0 : POKE A + 2, 3
PRINT S$ : PRINT A "- " PEEK(A) " " PEEK(A + 1) + PEEK(A + 2) * 256
</lang>
Set the address of a function.
<lang ApplesoftBasic>0 DEF FN F(X) = 1
1 DEF FN B(X) = 2
2 N$ = "F" : GOSUB 8 : FA = A
3 N$ = "B" : GOSUB 8 : BA = A
4 ? FN F(0)
5 POKE FA, PEEK(BA) : POKE FA + 1, PEEK(BA + 1)
6 ? FN F(0)
7 END
8 FOR A = PEEK(105) + PEEK(106) * 256 TO PEEK(107) + PEEK(108) * 256 STEP 7 : IF PEEK(A) = ASC(LEFT$(N$,1)) + 128 AND PEEK(A + 1) = ASC(MID$(N$ + CHR$(0), 2, 1)) THEN A = A + 2 : RETURN
9 NEXT A : PRINT "FN F NOT FOUND"
</lang>
 
=={{header|BBC BASIC}}==