bdff basic4-89dd
     ×   Main Menu ALL The 8BS News Manuals (New menu) Links Worth a Look Tools Disc and Basic Webring Site Map 8BS Guestbook Old Guest Book Me The Barnsley Rovers   
8-Bit Software

The BBC and Master Computer Public Domain Library



89DD '[' Begin Assembly

Submitted by Steve Fewell

Description:

Get the next non-space character.
If the character is ']' (end assembly character) then [&89D7] Decrement A (to #&FF), set the OPT flag (location
&28) to A (#&FF) and jump to &900B to process the next BASIC language statement.

Call &9C80 to add Y (the BASIC Text pointer A offset) to the BASIC text pointer address (&0A-&0B) and reset
the PTR A offset to 1; and then check whether an ESCAPE keypress condition has occurred, and process it if it has.
Decrement the PTR A offset to 0.

Call routine &8AA8 to analyse, validate and assemble the current Assembly Statement (pointed to by BASIC text pointer A).

Decrement the PTR A offset so that BASIC text pointer A points to the Statement terminator character.
If bit 0 of the OPT flag (&28) is clear then no listing is required, so skip the listing routine and jump to &8A6B.

[&89F3] Produce a listing for the Assembled statement
The line listing will have the following layout:
EXEC B1 B2 B3 LABEL---- TEXT

Where:
* EXEC is the execution address (4 hex digits)
* B1 is the first 6502 Machine Code byte (usually the Instruction Opcode (unless an EQU-command is used)) (2 hex digits)
   (or 2 spaces if the statement doesn't assemble into any actual Machine Code bytes).
* B2 is the second 6502 Machine Code byte (or 2 spaces if no second byte is present) (2 hex digits)
* B3 is the third 6502 Machine Code byte (or 2 spaces if no third byte is present) (2 hex digits)
* LABEL is any label (e.g. '.xxx') that preceeded the assembly statement (minimum of 9 characters wide - right padded with
   spaces, but the LABEL field will be longer if the label name is more than 9 characters wide).
* TEXT is the actual unassembled text (e.g. 'LDA#SIN(2.345)') (this field has no width limit).

Note that the EQUS and EQUD assembly mnemonics may use more than 3 bytes, and as such, the bytes will be listed in groups
of 3, each group being displayed on a new line. The execution address will only be output on the first line. The label and
text will be shown on the last line.

Set location &3F to the value of COUNT (&1E) + 5. This stores what the position on the current output line would be
after the execution address (below) has been printed.

The (EXEC) Execution address (&37-&38) is output as follows:
* Set A to the Execution address MSB (from location &38) and call routine &BD6C to output the 2-digit value (in A).
* Set A to the Execution address LSB (from location &37) and call routine &BD8F to output the 2-digit value (in A)
  followed by a space.

Set X to #&FC.
Set location &38 to the length of the Assembly Mnemonic (in number of bytes); as follows:
* Set &38 to the value of &39 (number of bytes used by Assembly Statement (which is usually 1, 2, 3, 4 or &FF))
* If &39 is a negaive value then a the Mnemonic was a String value ('EQUS'), so set the length (&38) to the SWA
  length (&36).

If &38 is not 0 then the Assembly statement contains some bytes (B1, B2, B3, etc...), which are displayed as follows:
Set Y (physical location byte number) to 0.
[&8A11] Increment X
If X has reached 0 (i.e. after 3 bytes have been displayed) then output a new line followed by &3F number of spaces
   (This positions the position on the new line to line up with the first byte (after address) of the previous
   line and reset X to #&FD (so that another 3 bytes can be output).
Load the next byte located at the Physical location [(&3A-&3B) + Y] and call routine &BDCF to output
  the 2-digit hex value of the byte (in A) followed by a space
Increment Y to point to the next byte
Decrement &38 (bytes to output)
If &38 is not 0 then jump back to &8A11 to output the next byte value
[&8A28] Now each hex byte of the assembled statement has been output (with 3 bytes output per line).
Set Y to X (i.e. the number of spare printable bytes (is byte is printed as 2 hex digits followed by a space) on the screen).
If Y is not &FF then we need to output some spaces, as not all 3 byte positions (B1, B2, B3) contained a value, so:
* [&8A2A] Increment Y
* If Y is not 0 then output 3 spaces and jump back to &8A2A
[&8A34] Set X to #&0A (minimum length of label + 1 space).
Set A to the first byte of the Statement line (from BASIC Text pointer A (&0B,&0C)).
[Note: Y is initially zero].
If A is '.' then the label is output as follows:
* [&8A3C] Call routine &BD77 to output the character/token in A
* Decrement the length of the label field (X)
* If X is 0 then set X to 1 (as will must output 1 space after a label name)
* Increment Y (the current byte offset at the BASIC Text Pointer A address)
* Set A to the next byte from the BASIC Text Pointer A address (with the byte offset in Y)
* If Y is not equal &4E (the offset to the end of the label name in BASIC Text Pointer A, as stored by the assembly
    routine (&8AA8)) then jump back to &8A3C to output the next character of the label name.
[&8A4B] Output X number of spaces (if a label was printed then X will be any used spaces in the 9-character label
field, or 1 if the label exceeded 8 characters in width; otherwise X will be 10).

Decrement Y (to point to the first character after the label name - which must be a space character).
[&8A4F] Skip any spaces after the label name by: incrementing Y until the character at the BASIC Text pointer A
location plus Y offset, is not the same as the character in A (which will be a space).

[&8A54] Output the statement text as follows:
* Set A to the character at BASIC Text Pointer A plus offset (Y)
* If the character is ':' then:
# If Y is less that the BASIC Text Pointer A offset (location &0A), i.e. the position that routine &8AA8
  stopped processing, then we are not at the end of the statement (i.e. the statement is a statement like
  'LDA#ASC(":")' which contains a ':' prior to the end of statement) then jump to &8A5E to output the
  character and then continue outputting the statement text.
# Otherwise, Output a new line (line break) and jump to &8A6B to Check and skip the end of the statement/program
  line.
* If the character is '<cr>' then output a new line and jump to &8A6B to check and skip the end of the program line
* [&8A5E] call routine &BD37 to output the character
* Increment Y (BASIC Text Pointer A offset)
* Jump back to &8997 to output the next character of the statement text

[&8A6B] Check and skip end of statement/program line
Set Y to the BASIC Text pointer A offset value (location &0A), i.e. the position that routine &8AA8 stopped
processing; and decrement Y (to point to the last character, which should either be ':' or '<cr>').

[&8A6E] Load the next character at the BASIC Text pointer A location + the Y offset value.
If the character is not ':' or '<cr>' then jump back to &8A6E to check the nexct character. This will skip any
program comment that is located between the end of the Assembly statement and the end of statement marker (note that any
such comments [which do not have to be preceeded by a '\' character!] will still be output in the assembly listing, but
they will not be processed - as all characters are skipped until a ':' or '<cr>' character is found).
This means that problems could occur in such cases as follows:
     'CMP#ASC("9") \ Was ASC(":")'
which will not work, as BASIC will assume that the ':' is an end of statement marker and start processing '")' as the next
assembly statement - resulting in a 'Syntax error'.

Call routine &9C6C to check for the end of statement (and add Y to the BASIC Text Pointer A address).
If the character pointed to by BASIC text pointer A (i.e. the last character of the statement) is ':' then jump to
&89DD to assemble the next statement on the program line.

Otherwise, the character is '<cr>', so check the BASIC Text pointer A MSB address (&0C). If the MSB address
of the statement text is &07, then we are not currently executing a program, instead we are executing a command line
command, so jump to &904B to return to the command line prompt.
Otherwise, we are executing a program, so call routine &9CA2 to Check the next program line, returning to the command
line prompt if no more lines were found, and to skip and display (if TRACE is on) the Line Number.
Jump back to &89DD to assemble the statement on this new program line, or to exit if a ']' character is found.


Disassembly for the '[' Begin Assembly routine

89D7 : 58 3A DEC A
89D8 ( 133 040 85 28 STA &28
89DA L 076 208 144 4C D0 90 JMP &90D0 Process next BASIC program statement
89DD   032 157 143 20 9D 8F JSR &8F9D Get next non-space character pointed to by Ptr A
89E0 I] 073 093 49 5D EOR#&5D
89E2   240 243 F0 F3 BEQ -13 --> &89D7
89E4   032 128 156 20 80 9C JSR &9C80 Add Y to Text pointer A & then reset offset to 1) & check for Escape condition
89E7   198 010 C6 0A DEC &0A
89E9   032 168 138 20 A8 8A JSR &8AA8 Assemble Assembly instruction/statement
89EC   198 010 C6 0A DEC &0A
89EE ( 165 040 A5 28 LDA &28
89F0 J 74 4A LSR A
89F1 x 144 120 90 78 BCC 120 --> &8A6B
89F3   165 030 A5 1E LDA &1E
89F5 i 105 004 69 04 ADC#&04
89F7 ? 133 063 85 3F STA &3F
89F9 8 165 056 A5 38 LDA &38
89FB   032 172 189 20 AC BD JSR &BDAC Output the 2-digit Hexadecimal number stored in A
89FE 7 165 055 A5 37 LDA &37
8A00   032 207 189 20 CF BD JSR &BDCF Output the 2-digit Hexadecimal number stored in A followed by a space
8A03   162 252 A2 FC LDX#&FC
8A05 9 164 057 A4 39 LDY &39
8A07   016 002 10 02 BPL 2 --> &8A0B
8A09 6 164 054 A4 36 LDY &36
8A0B 8 132 056 84 38 STY &38
8A0D   240 025 F0 19 BEQ 25 --> &8A28
8A0F   160 000 A0 00 LDY#&00
8A11   232 E8 INX
8A12   208 010 D0 0A BNE 10 --> &8A1E
8A14   032 194 186 20 C2 BA JSR &BAC2 Output a new line
8A17 ? 166 063 A6 3F LDX &3F
8A19   032 255 189 20 FF BD JSR &BDFF Output X number of Spaces
8A1C   162 253 A2 FD LDX#&FD
8A1E : 177 058 B1 3A LDA (&3A),Y
8A20   032 207 189 20 CF BD JSR &BDCF Output the 2-digit Hexadecimal number stored in A followed by a space
8A23   200 C8 INY
8A24 8 198 056 C6 38 DEC &38
8A26   208 233 D0 E9 BNE -23 --> &8A11
8A28   138 8A TXA
8A29   168 A8 TAY
8A2A   200 C8 INY
8A2B   240 007 F0 07 BEQ 7 --> &8A34
8A2D   162 003 A2 03 LDX#&03
8A2F   032 255 189 20 FF BD JSR &BDFF Output X number of Spaces
8A32   128 246 80 F6 BRA -10 --> &8A2A
8A34   162 010 A2 0A LDX#&0A
8A36   178 011 B2 0B LDA (&0B)
8A38 . 201 046 C9 2E CMP#&2E
8A3A   208 015 D0 0F BNE 15 --> &8A4B
8A3C w 032 119 189 20 77 BD JSR &BD77 Output Character/Token on screen
8A3F   202 CA DEX
8A40   208 002 D0 02 BNE 2 --> &8A44
8A42   162 001 A2 01 LDX#&01
8A44   200 C8 INY
8A45   177 011 B1 0B LDA (&0B),Y
8A47 N 196 078 C4 4E CPY &4E
8A49   208 241 D0 F1 BNE -15 --> &8A3C
8A4B   032 255 189 20 FF BD JSR &BDFF Output X number of Spaces
8A4E   136 88 DEY
8A4F   200 C8 INY
8A50   209 011 D1 0B CMP (&0B),Y
8A52   240 251 F0 FB BEQ -5 --> &8A4F
8A54   177 011 B1 0B LDA (&0B),Y
8A56 : 201 058 C9 3A CMP#&3A
8A58   240 010 F0 0A BEQ 10 --> &8A64
8A5A   201 013 C9 0D CMP#&0D
8A5C   240 010 F0 0A BEQ 10 --> &8A68
8A5E w 032 119 189 20 77 BD JSR &BD77 Output Character/Token on screen
8A61   200 C8 INY
8A62   128 240 80 F0 BRA -16 --> &8A54
8A64   196 010 C4 0A CPY &0A
8A66   144 246 90 F6 BCC -10 --> &8A5E
8A68   032 194 186 20 C2 BA JSR &BAC2 Output a new line
8A6B   164 010 A4 0A LDY &0A
8A6D   136 88 DEY
8A6E   200 C8 INY
8A6F   177 011 B1 0B LDA (&0B),Y
8A71 : 201 058 C9 3A CMP#&3A
8A73   240 004 F0 04 BEQ 4 --> &8A79
8A75   201 013 C9 0D CMP#&0D
8A77   208 245 D0 F5 BNE -11 --> &8A6E
8A79 l 032 108 156 20 6C 9C JSR &9C6C Check end of Statement
8A7C   178 011 B2 0B LDA (&0B)
8A7E : 201 058 C9 3A CMP#&3A
8A80   240 012 F0 0C BEQ 12 --> &8A8E
8A82   165 012 A5 0C LDA &0C
8A84   201 007 C9 07 CMP#&07
8A86   208 003 D0 03 BNE 3 --> &8A8B
8A88 LK 076 075 144 4C 4B 90 JMP &904B Read & execute command line input
8A8B   032 162 156 20 A2 9C JSR &9CA2 Skip Program Line Number
8A8E L 076 221 137 4C DD 89 JMP &89DD Assemble next assembly statement

 


 Back to 8BS
Or