![](/squares_tiny/publisher/0/0/0/0/0/5/5/0/pcn.jpg)
Personal Computer News
![](/themeForest/images/clock.png)
Published in Personal Computer News #076
Convert Beeb's 16-Bit Binary Code To Hex
Q. I am trying to write a machine code monitor for the BBC Micro, but how do I convert a 16-bit binary number, whose address is stored in &70, and &71 to a four digit hex string, stored in the contents of &72 and &73? Could you also recommend a machine code debugging tool in ROM?
Simon Spruzen, Woburn Sands, Milton Keynes
A. The solution is fairly easy except that you can't get four bytes into two memory locations. A hex string, such as &AF12, can only be stored in four bytes, one for each character. The following program uses two post-indexed indirect loads to get the appropriate numbers from the address held in &70 and &71.
These are then stored in &72 and &73, and then each high and low nibble is converted into an ASCII code and stored in &75, &74, &77, &76 appropriately. If the codes are in the STA locations in lines 150, 180, 210 and 240.
One oddity of the BBC's 6502 assembler is the instruction ROR. To rotate the accumulator, use the mnemonic ROR A but, if the variable A has been assigned to a location or label (same thing), there could well be some confusion since the assembler takes ROR A as rotate the accumulator and not rotate the location specified by A.
The program can be used as demonstrated, but it is also possible to use JSR &FFEE to print out the hex string held in &74 to &77.
10 DIM CODE 100
20 FOR T=0 TO 3 STEP 3
30 P%=CODE
40 [OPT T
50 .GO
60 LDY #0
70 LDA (&70),Y
80 STA &72
90 INY
100 LDA (&70),Y
110 STA &73
130 LDA &72
140 JSR LOW
150 STA &77
160 LDA &72
170 JSR HIGH
180 STA &76
190 LDA &73
200 JSR LOW
210 STA &75
220 LDA &73
230 JSR HIGH
240 STA &74
250 RTS
270 .CONVERT
280 CMP #9
290 BMI NUMBER
300 CLC
310 ADC #55
320 RTS
330 .NUMBER
340 CLC
350 ADC #48
360 RTS
370 .LOW
380 AND #15
390 JSR CONVERT
400 RTS
410 .HIGH
420 CLC
430 ROR A:ROR A:ROR A:ROR A
435 AND#15
440 JSR CONVERT
450 RTS
460 ]
470 NEXT
480 ?&4000=&A2
490 ?&4001=&F0
500 ?&70=00
510 ?&71=&40
520 CALL CODE
530 FOR T=&74 TO &77
540 PRINT;CHR$(?T);
550 NEXT
One of the best ROM monitors we have come across is the SPY2 ROM from System Software, Dept. A 12, Collegiate Crescent, Sheffield.