EUG PD


Viewing Memory

 
Author: Gus Donnachaidh
Published in EUG #20

A BASIC program can always be LISTed but sometimes it's necessary to actually examine it in memory, perhaps to see what has gone wrong.

There are three ways of doing this. Firstly, by disassembling it. Here you will get a screen full of opcodes looking somewhat like an assembly language program. Secondly, by listing it as ASCII and control codes. This will look rather like a screen full of HEX numbers. Thirdly, as actual ASCII characters. Control codes will usually appear as innocuous symbols.

This EUG features a program that does the second and third methods. To do the first would require a much larger program, not least because every opcode would need to be detailed in DATA statements.

If you have a program in memory, say at PAGE and you want to see it, it's no use LOADing this program because you will overwrite the start of the program you want to see.

You need instead to move PAGE to a high area of memory just below the screen area and then *LOAD and RUN this program from there. At the beginning of the program are definitions for the variables S and N. S is the point of memory where you want to start looking while N is the amount of memory you want to look at. For the moment, S has been set to &1D00 while S is &FF.

RUN the program and look at the screen. Where the hex number is &0F or below, only a single figure is produced. i.e. F

The first number is D. This is a control code for 'start of line'. All BASIC programs in memory start with &0D if they work. The second number is 0 while the third is A. This is the first line number. &0A=10, and the first line is indeed 10. The 0 is the high byte, in this case &00. Think of the meter in your car that tells you how far you have driven. If you have done ten miles, then the meter might show 0010. To prove this, enter RENUMBER 10000 (RETURN) then run the program. Now the second number will be &27 with the third 10 because &2710=10000.

The fourth number is the length of the line, here &12. If you count the number of places from the first &0D to the next you will find that there are indeed &12 or 18 places. Try to get used to using Hexadecimal. One tip I have is to thing of &15 as ampersand one five and not as 15, which it isn't in any case.

Next comes &F4. This is the control code for REM. While &20 is the control code for space. Then of course comes a series of ASCII (anyone seen Arthur) codes representing the letters D, I, S and so on.

Nothing to it really. ASCII codes are listed in the back of your Electron User Guide. The control codes I will give you now.

I worked these out some time ago by typing in all of the keywords listed in the User Guide and then looking at the memory. I then wrote them into the User Guide next to each of the keywords.

Some keywords have two codes, usually to indicate an extra symbol such as 23 for #. Five keywords don't appear to have any particular codes for some reason.

ABS ......... 94      LOAD ........ C8      
ASC ......... 95      LOCAL ....... EA              
ADVAL ....... 96      LOG ......... AB  
AND ......... 80      LOMEM ....... D2               
ASC ......... 97      MID$ ........ C1   
ASN ......... 98      MOD ......... 83              
ATN ......... 99      MODE ........ EB  
AUTO ........ C6      MOVE ........ EC              
BGET# ....... 9A 23   NEW ......... CA
BPUT# ....... D5 23   NEXT ........ ED
CALL ........ D6      NOT ......... AC
CHAIN ....... D7      OLD ......... CB
CHR$ ........ BD      ON .......... EE
CLEAR ....... D8      OPENIN ...... 8E
CLG ......... DA      OPENOUT ..... AE
CLOSE# ...... D9 23   OPENUP ...... AD
CLS ......... DB      OPT            
COLOUR ...... FB      OR .......... 84
COS ......... 9B      OSCLI ....... FF
COUNT ....... 9C      PAGE ........ D0
DATA ........ DC      PI .......... AF
DEF ......... DD      PLOT ........ F0
DEG ......... 9D      POINT ....... B0
DELETE ...... C7      POS ......... B1
DIM ......... DE      PRINT ....... F1
DIV ......... 81      PRINT# ...... F1 23           
DRAW ........ DF      PROC ........ F2 
ELSE ........ 8B      PTR# ........ CF 23          
END ......... E0      RAD ......... B2
ENDPROC ..... E1      READ ........ F3
ENVELOPE .... E2      REM ......... F4
EOF# ........ C5      RENUMBER .... CC
EOR ......... 82      REPEAT ...... F5          
EQUB                  REPORT ...... F6          
EQUD                  RESTORE ..... F7
EQUS                  RETURN ...... F8
EQUW                  RIGHT$ ...... C2  
ERL ......... 9E      RND ......... B3
ERR ......... 9F      RUN ......... F9
EVAL ........ A0      SAVE ........ CD
EXP ......... A1      SNG ......... B4
EXT# ........ A2      SIN ......... B5
FALSE ....... A3      SOUND ....... D4
FN .......... A4      SPC ......... 89
FOR ......... E3      SQR ......... B6
GCOL ........ E6      STEP ........ 88
GET ......... A5      STOP ........ FA
GET$ ........ BE      STR$ ........ C3
GOSUB ....... E4      STRING$ ..... C4
GOTO ........ E5      TAB ......... 8A
HIMEM ....... D3      TAN ......... B7
IF .......... E7      THEN ........ 8C
INKEY ....... A6      TIME ........ D1
INKEY$ ...... BF      TO .......... B8
INPUT ....... E8      TOP ......... B8 5D
INPUT# ...... E8 23   TRACE ....... FC
INSTR ....... A7      TRUE ........ B9
INT ......... A8      UNTIL ....... FD
LEFT$ ....... C0      USR ......... BA
LEN ......... A9      VAL ......... BB
LET ......... E9      VDU ......... EF
LIST ........ C9      VPOS ........ BC
LISTO ....... C9 4F   WIDTH ....... FE
LN .......... AA

Gus Donnachaidh, EUG #20

Gus Donnachaidh