0% found this document useful (0 votes)
283 views2 pages

Upgradefor: MCS® Basic-52 (Part 1)

Elektor

Uploaded by

Ag Cristian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
283 views2 pages

Upgradefor: MCS® Basic-52 (Part 1)

Elektor

Uploaded by

Ag Cristian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UPGRADEFOR

MCS® BASIC-52
Vl.l
(Part 1)
The 8052AH-BASIC trom Intel is a versatile
microcontroller with a powerful BASIC
interpreter lurking in its on-board
mask-programmed ROM. The authors,
having worked with this IC tor so me time,
discovered certain tlaws in the BASIC
interpreter, and set out to produce a
better, taster version that can be run trom
EPROM.

by Dusan Mudric and Zoran


Stojsavljevic
ADDR CODE I NSTRUCTI ON

To be able to make changes to the MCS-


52 BASIC interpreter in the 8052AH·
BASIC microcontroller, it is necessary to first
19F2H 752M!
19F5H 71C8
~OV
ACALL
2AH,te0H
!8eBH
'0~0T

19F7H 7F04 MOV R7,!04H '004T


unload it from the Je. This is done basically 19F9H 7nE MOV Rl,12EH 'i4bT
as described in an earlier article on the MCS 19FBH 749E MOV A,19EH +159T
BASIC·52 Interpreter, Ref. 1. The result 01
19FOH C3 CLR C
reading the 8~KByte ROM is a file in Intel-
Hex format that contains the machine code 19FEH 9C SUSS A,R4
01 the MCS BASIC·52 Interpreter (version 19FFH 04 DA A
1.1). lA00H CC ICH A,R4
MCS BASIC~52 (Rel. 3), extracted from lA01H 7001 JNZ lA04H i I , 03H
the 8052AH~BASIC Vl.1 microcontroller, lA03H Fe MOV R4,A
was disassernbled and texts, tables and con- lA04H B45000 CJNE A,150H,IA07H i '080T I + eJH
stants were extracted in order to produce an lA07H 302318 JNB 23H,!A22H i I' 1St!
assembler version of the Interpreter. The size
lA0AH B3 CPL C
of this assembler file was approxirnately
4,000 lines. Studying the program, we found lA0BH5119 ACALL IAI9H
that the operanon of the interpreter could be lA0DH 5008 JNC lA17H I t 0AH
improved by rewriting certain lines of as- lA0FH 052A [NC 2AH
sembler code. Subsequently, a number of al-
gorithms were developed and substituted 910128·12
for theones originally implemented by InteL
Furthermore. errors found in a number of Fig. 1. Original tloatlnq-polnt nucleus In the MCSBASIC·52 interpreter.
routines were corrected.
produces 1.34E22 instead 01 1.3E22.
Floating point nucleus The disassembly listing 01 the original xyzwH = aD'10000D+ bD'1000D+ cD'100D
floating point nuc1eus developed by Intel is + dD'lOD + eD'1 D
One of the routines in the BASIC Interpreter given in Pig-t. and the version developed by
found to contain programming errors is the the authors in Fig. 2. When implemented in These possibilities are:
floating-point arithmetic nucleus. The errors the BASIC Interpreter. the nucleus shown in 1. successive extraction of BCD digits
can be demonstrated by running two small Hg. 2 produces the correct answers to the starting with the most significant digit, a;
programs: above subtractions. 2. successive extraction of BCD digits
10 a=.10000001E30 starting with the least significant digit, e.
20 b=.99999993E29
30 ?a-b Other corrections
If the original version of the hex-to-BCD con-
The result, 2.74E22, is erroneous, and should Further improvernents were made to the verter is studied, it is seen that the first pro-
be 1.7E22. Similarly, hex-to-BCD conversion routine, both in re- cedure is ernployed. The DPTR is used as a
10 a=.10000001E30 gard of efficien t programming and speed. 'weighted register', and the procedure is
20 b=.99999997E29 For exemple, two approaches are possible based on finding a suitably weighted sub-
30 "a-b for extracting BCD digits a, b, c, d, and e in traction nurnber frorn a variable value.

ELEKTOR ELECTRONICS OCTOBER 1991


UPGRADE FOR MCS BASIC-52 V 1.1 (Part I)

The second procedure is based on suc-


cessive division of the variable value by 10,
ADDR CODE INSTIIUCT!ON where, with each division, one BeD digit ap-
pears as the remainder.
19F~ 7S2AU !!OV FP-'!Sa-l! U~ ; preparatJon 01 l'qu~j upcr.ents
By sirnplifying the conversion to suc-
ms 7!::B ~CAlL SHIFT_R!6HT
19F? 7F84 ~<l'J i!7,ILENJ1TE cessive division-by-lO, the original code of
19~9 H~E 57\12 !'!cy rn, IFrjsa 72 bytes is reduced to 57 bytes. The im-
51113 proved hex-to-Br'D converter no Ionger re-
57tl4 :fPW'UPUPHPEFPEHEfPEfPEfF'HPEn'EFPEFPEFPEfPW'EFPEFPEFPEH'EFPHf'EFPE
S1t5
quires the DPTR contents to be stored,
57i1b ~lOlHIN6 POJ:~T ERRllRS, FOU~O B'f D.f'lUDRIC AND l.srOJSAVlJEY!C returned and incremented after the conver-
sm sion is finished. As a result, it is faster than
szes '0\' A,t9EH :ERROR NUi'lBEII 11
the original converter irnplemented by Intel.
sm
sm ; VALUE I~ R4 f'!\JST B~ COf'lPLE!IENTED '!11TH Hl0D !19f1I!I, IT ~UST BE THE Table ] shows a few 'bench-rnark' ex-
S?ll ; F;F;STCOnPlE!IEJlT amples.
5712

.
5713 CLFt C
5714 511SB ~,R4
Table 1_Hex-to-decimal conver-
sm
5716
"
leH A,A4 sion time
57i7 JNl 1+3
sm ~OV R4,A
5719 P (hex) P (dec) told (ms) toew (ms)
572t1 ERROR NU~8ER 12 0000 0000 141 56
5721
sm I/]TX SUBSTRAc:JON, AFTER REDUC\NS 80TH iHE ~IN!.IE/ID A~O THE
0009 0009 276 56
572-3 SUBTRAHE~~ TO lHE SA~E W'O~ENTS, WHEN R~ \) 01 IT 15 OSVlOU5 4000 16384 507 268
5724 THAT ONE AUIAVS HAS TO !'\AKt A HORROWIN6 FRO~ THE F:m H!GHER EA5F 59999 820 268
5725 posn:aN OF THE I'IINUEND1 NOT AS lT 15 STATED SV THE OP.ISINAL
\IllERE IT IS MD~ OIILY WHEN R~ =} 5eH

CJNE A,i5~H,H3 ; deat ~ith roundlng


JNB FRESER,FP JUBB j tes t for subtr~chon utenuen tc {.nyl

513: ; FmPEf ~EF PEFrEFP[F PEFf'EFPEFPt:F PEFPEFPEFPEFPEFPEFf'EFP~m F~EFPE FPE~f'fFPE Action!


; PROPER ROUNO!ti!J, DEVEUIPED BY D,~UDR!C
If you are interested in the i.mprovements
made to the MCS BASIC-52 interpreter as
!Qf~ ,m MOV ~, I9AH described here, unload the Interpreter from a
mo C3 CLR C 8052AH-BASIC, modify it, put it back into an
: 9FE qc SUBB A,Q4
:9FF N DA •
EPROM and run it either with an 80C32, or
lAII~ ce (eH A,R4 as a turnkey-EPROM with an 8052AH-
lAat J~2JIE m FRESER,H' _SUFF BASIC. All this is pretty straightforward and
tfl.1I4 a4sm CJNE A,t5gH,Hb
described at length in Refs. 1 and 2. First,
!M? .0~ ~B 0,0,0
j~ge 011 copy the interpreter into an EPROM. Next,
lA2~ U use the OLD function of the EPROM pro-
5HJ grammer on the BASIC computer (Refs. 4, 5)
57H
1AfA S3 CPL C
to make sure that an exact copy is available.
:A9E s: l~' ACKL ADD_·.mISS~ Then load the contents of the EPROM into an
lA~C ~m JNC J~~_COPY)O_TOS EPROM programmer, and use the edit func-
! A~E 0S2A ,Ne FP_~SP-! tion to make the changes indicated in Fig. 3.
Ftnally, program a new EPROM with the
910128 ·13
modified BASIC interpreter. The EPROM
used may be a 27C64, a 27C128 or a 27C256.
Fig. 2. Assembly listing of the improved ttoatrnq-potnt nucleus. Altematively, you may want to use an EE-
PROM Type 2864A. 0
OLO:
References:
02 06 9F 12 0' 73 7B 00 79 07 '3 11 I' 12
1080
\090
OE
"
05 60 12 19 '3 12 OE '5 '3 B9 00 00 40 22 '3 '0 1. "CMOS replacement for 8052AH-BASIC",
Elektor Electronics January 1990.
19FO 7F 0' 75 2A 00 71 eB 7F 04 79 2' 74 9' e3 ge 04 2. "ROM-copy for 8052 BASIC computer".
IAOO ee 70 01 Fe B4 50 00 30 23 IB B3 51 19 50 OB 05
3. "MCS BASIC-52 Users Manual", Intel
lFOO E4 3B FB 22 E4 90 27 10 FI 21 90 03 '8 F1 21 90 Corp.. 1986.
lFIO 00 64 FI 21 90 00 DA F1 21 90 00 01 Fl 21 60 20
lF20 22 7E FF OE CA B5 83 00 CA 40 12 C8 95 82 C8 CA 4. "BASIC computer", Elektor Electronics
IF30 95 83 CA 50 EE C8 25 82 C8 CA 35 83 CA 4E 60 EO November 1987.
IF40 74 30 2E 8B AO F3 09 B9 00 01 08 22, D 1 Al Al 36
5. "8032/8052 Single-board computer".
Elektor Electronics May 1991.
NEW·
® MCS BASIC-52 is a registered trademark
1080 OE A5 02 06 9F 12 05 73 7B 00 79 07 A3 12 05 6D of Intel Corp.
1090 12 19 A3 00 00 00 00 00 00 B9 OD 00 40 22 A3 EO

19FO 7F DA 75 2A 00 71 C8 7F 04 79 2E 74 9A C3 9C 04
lAOO ce 30 23 1E 84 50 03 00 00 00 83 51 19 50 oa os
Fig. 3. Overview of address locations 10 be
tFOO E4 3B FB 22 7D 00 EA 15 FO DA 84 FA E8 54 FO 45 modified in the 8-KByte interpreter. Remem-
IFIO FO C4 75 FO DA 84 C4 FE E8 54 OF C4 45 FO C4 75
lF20 FO DA 84 4E F8 ES FO 24 30 OD CO EO EA 48 70 .D6 ber, you can not overwrite data just like that
IFJO DO EO 8B AO F3 09 B9 00 01 OB DU F4 22 00 00 00 in an EPROM-a 0 will remain aO unlessyou
IF40 00 00 00 00 00 00 00 00 00 00 00 00 D1 Al Al 36 erasethe EPROMusing uttra-vlctet light. The
modified version of 1he interpreter must,
910128 ·11
theretore, be loaded in a blank EPROM.

ELEKTOR ELECTRONICS OCTOBER 1991

You might also like