http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&feed=atom&action=history
Number output in 6502 machine code - Revision history
2024-03-19T07:01:44Z
Revision history for this page on the wiki
MediaWiki 1.30.0-rc.0
http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&diff=3132&oldid=prev
Jgharston: Improved multiple-byte decimal output routines.
2018-06-30T05:13:28Z
<p>Improved multiple-byte decimal output routines.</p>
<a href="http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&diff=3132&oldid=2685">Show changes</a>
Jgharston
http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&diff=2685&oldid=prev
Jgharston: Updated Obelisk URL.
2016-01-14T01:11:33Z
<p>Updated Obelisk URL.</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr style="vertical-align: top;" lang="en">
<td colspan="2" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="2" style="background-color: white; color:black; text-align: center;">Revision as of 01:11, 14 January 2016</td>
</tr><tr><td colspan="2" class="diff-lineno" id="mw-diff-left-l21" >Line 21:</td>
<td colspan="2" class="diff-lineno">Line 21:</td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Print value in A in hexadecimal padded with zeros.</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Print value in A in hexadecimal padded with zeros.</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>(I used http://www.obelisk.<del class="diffchange diffchange-inline">demon.co</del>.uk/6502/algorithms.html to refresh my memory.)</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>(I used http://www.obelisk.<ins class="diffchange diffchange-inline">me</ins>.uk/6502/algorithms.html to refresh my memory.)</div></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr>
<tr><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     \ On entry, A=value to print</div></td><td class='diff-marker'> </td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>     \ On entry, A=value to print</div></td></tr>
</table>
Jgharston
http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&diff=1630&oldid=prev
WikiSysop: 1 revision
2015-03-08T18:12:44Z
<p>1 revision</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="en">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Revision as of 18:12, 8 March 2015</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
WikiSysop
http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&diff=396&oldid=prev
WikiSysop: 1 revision
2015-03-08T00:13:10Z
<p>1 revision</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="en">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Revision as of 00:13, 8 March 2015</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
WikiSysop
http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&diff=6&oldid=prev
WikiSysop: Created page with "Category:6502 ==Print 8-bit Hexadecimal== Print value in A in hexadecimal padded with zeros. \ On entry, A=value to print \ On exit, A corrupted .PrHex ..."
2015-03-07T23:06:49Z
<p>Created page with "<a href="/Category:6502" title="Category:6502">Category:6502</a> ==Print 8-bit Hexadecimal== Print value in A in hexadecimal padded with zeros. \ On entry, A=value to print \ On exit, A corrupted .PrHex ..."</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="en">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Revision as of 23:06, 7 March 2015</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
WikiSysop
http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&diff=1629&oldid=prev
WikiSysop: 1 revision
2013-08-28T22:58:19Z
<p>1 revision</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr style="vertical-align: top;" lang="en">
<td colspan="1" style="background-color: white; color:black; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: white; color:black; text-align: center;">Revision as of 22:58, 28 August 2013</td>
</tr><tr><td colspan="2" style="text-align: center;" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
WikiSysop
http://beebwiki.mdfs.net/index.php?title=Number_output_in_6502_machine_code&diff=395&oldid=prev
Jgharston: Much better 32-bit Decimal Printout
2011-12-25T07:51:58Z
<p>Much better 32-bit Decimal Printout</p>
<p><b>New page</b></p><div>[[Category:6502]]<br />
==Print 8-bit Hexadecimal==<br />
Print value in A in hexadecimal padded with zeros.<br />
<br />
\ On entry, A=value to print<br />
\ On exit, A corrupted<br />
<br />
.PrHex<br />
PHA :\ Save A<br />
LSR A:LSR A:LSR A:LSR A :\ Move top nybble to bottom nybble<br />
JSR PrNybble :\ Print this nybble<br />
PLA :\ Get A back and print bottom nybble<br />
.PrNybble<br />
AND #15 :\ Keep bottom four bits<br />
CMP #10:BCC PrDigit :\ If 0-9, jump to print<br />
ADC #6 :\ Convert ':' to 'A'<br />
.PrDigit<br />
ADC #ASC"0":JMP OSWRCH :\ Convert to character and print<br />
<br />
==Print 8-bit Hexadecimal (more cunning)==<br />
Print value in A in hexadecimal padded with zeros.<br />
<br />
(I used http://www.obelisk.demon.co.uk/6502/algorithms.html to refresh my memory.)<br />
<br />
\ On entry, A=value to print<br />
\ On exit, A corrupted<br />
<br />
.PrHex<br />
PHA :\ Save A<br />
LSR A:LSR A:LSR A:LSR A :\ Move top nybble to bottom nybble<br />
JSR PrNybble<br />
PLA<br />
AND #15 :\ Mask out original bottom nybble<br />
.PrNybble<br />
SED<br />
CLC<br />
ADC #&90 :\ Produce &90-&99 or &00-&05<br />
ADC #&40 :\ Produce &30-&39 or &41-&46<br />
CLD<br />
JMP OSWRCH :\ Print it<br />
<br />
==Print 8-bit Decimal==<br />
Print value in A in decimal padded with zeros.<br />
<br />
\ On entry, A=value to print<br />
\ On exit, A corrupted<br />
<br />
.PrDec<br />
LDX #&FF:SEC :\ Prepare for subtraction<br />
.PrDec100<br />
INX:SBC #100:BCS PrDec100 :\ Count how many 100s<br />
ADC #100:JSR PrDecDigit :\ Print the 100s<br />
LDX #&FF:SEC :\ Prepare for subtraction<br />
.PrDec10<br />
INX:SBC #10:BCS PrDec10 :\ Count how many 10s<br />
ADC #10:JSR PrDecDigit :\ Print the 10s<br />
TAX :\ Pass 1s into X<br />
.PrDecDigit<br />
PHA:TXA :\ Save A, pass digit to A<br />
ORA #ASC"0":JSR OSWRCH :\ Convert to character and print it<br />
PLA:RTS :\ Restore A and return<br />
<br />
==Print 32-bit Decimal==<br />
Print 32-bit value in decimal with no padding or specified character<br />
padding. Smaller numbers can be printed by entering at PrDec32lp with<br />
Y set to an appropriate number of digits, eg <code>LDY #5</code> for<br />
printing a 16-bit number.<br />
<br />
\ -------------------------------------<br />
\ PrDec32 - Print 32-bit decimal number<br />
\ Originally from HADFS ROM source<br />
\ -------------------------------------<br />
\ On entry, num..num+3=number<br />
\ flg =pad character or zero for no padding<br />
\ sub..sub+3=division workspace<br />
\ On exit, A,X,Y,num,sub,flg corrupted<br />
\ ---------------------------------------------------------<br />
.PrDec32<br />
LDY #9 :\ 9+1 digits<br />
.PrDec32lp<br />
TYA:PHA :\ Save Y=power of ten<br />
JSR PrComma :\ Print a comma if needed<br />
LDX #3:LDA #0<br />
.Power10lp1<br />
STA sub,X:DEX:BPL Power10lp1 :\ sub=0<br />
INC sub:LDX #sub :\ sub=1<br />
.Power10lp2<br />
JSR Times10X:DEY:BNE Power10lp2:\ sub=10^Y<br />
JSR DivideNum:JSR PrDigit :\ Divide, print digit or pad character<br />
PLA:TAY:DEY:BNE PrDec32lp :\ Loop through digits<br />
LDA num:BPL PrDig1 :\ Print final digit<br />
:<br />
.PrDigit<br />
BNE PrDig1 :\ Non-zero, print digit<br />
LDA flg:BEQ PrDig2 :\ No pad character, return<br />
JMP OSWRCH :\ Pad character, print it<br />
.PrDig1<br />
ORA #ASC"0":JSR OSWRCH :\ Print digit<br />
LDA #ASC"0":STA flg :\ Print zeros from now on<br />
.PrDig2<br />
RTS<br />
:<br />
\ Print a comma every three digits<br />
\ Omit this code and JSR PrComma if no commas required<br />
\ ----------------------------------------------------<br />
.PrComma<br />
CPY #2:BEQ PrComma1<br />
CPY #5:BEQ PrComma1<br />
CPY #8:BEQ PrComma1<br />
.PrComma0<br />
RTS<br />
.PrComma1<br />
LDX flg:LDA #ASC"," :\ Prepare a comma<br />
CPX #ASC"0":BEQ PrComma2 :\ Zeros being printed, print comma<br />
TXA :\ Otherwise print pad character<br />
.PrComma2<br />
TAX:BEQ PrComma0:JMP OSWRCH :\ Print if not null pad character<br />
:<br />
\ -------------------------------------<br />
\ DivideNum - Divide num by sub<br />
\ -------------------------------------<br />
\ On entry, num=32-bit number<br />
\ sub=32-bit divisor<br />
\ On exit, A=num DIV sub, Z=(A=0)<br />
\ num=num MOD sub<br />
\ Y preserved, X corrupted<br />
\ ----------------------------------------<br />
.DivideNum<br />
LDX #255:SEC<br />
.DivLp<br />
INX<br />
LDA num+0:SBC sub+0:STA num+0<br />
LDA num+1:SBC sub+1:STA num+1<br />
LDA num+2:SBC sub+2:STA num+2<br />
LDA num+3:SBC sub+3:STA num+3<br />
BCS DivLp<br />
LDA num+0:ADC sub+0:STA num+0<br />
LDA num+1:ADC sub+1:STA num+1<br />
LDA num+2:ADC sub+2:STA num+2<br />
LDA num+3:ADC sub+3:STA num+3<br />
TXA:RTS<br />
:<br />
\ -------------------------------<br />
\ Times10 - Multiple number by 10<br />
\ -------------------------------<br />
\ On entry, X=>zero page number<br />
\ On exit, X,Y preserved, A,F corrupted<br />
\ -------------------------------------<br />
.Times10X<br />
JSR TimesTwo :\ n*2<br />
LDA 3,X:PHA:LDA 2,X:PHA :\ save n*2<br />
LDA 1,X:PHA:LDA 0,X:PHA<br />
JSR TimesTwo:JSR TimesTwo :\ n*8<br />
PLA:ADC 0,X:STA 0,X :\ n*8+n*2 = n*10<br />
PLA:ADC 1,X:STA 1,X<br />
PLA:ADC 2,X:STA 2,X<br />
PLA:ADC 3,X:STA 3,X<br />
RTS<br />
:<br />
.TimesTwo<br />
ASL 0,X:ROL 1,X :\ n=n*2<br />
ROL 2,X:ROL 3,X:RTS<br />
:<br />
[[User:Jgharston|Jgharston]] 07:51, 25 December 2011 (UTC)</div>
Jgharston