6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 2:48 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Jan 17, 2019 10:11 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 325
I don't know what I was dreaming last night, but this came to me just as I was waking up:

Add two 16 bit numbers, using no instruction more than once. Different addressing modes count as the same instruction.


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 17, 2019 11:03 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
How about?
Code:
 ldx #1
 clc
.loop
 lda A,x
 adc B,x
 sta R,x
 dex
 bpl .loop

Does 'using no instruction more than once' mean only once in the source or only once during execution?

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 17, 2019 11:54 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 325
Only once in the source is fine. Only once during execution is a little more of a challenge. Using 65816 instructions is considerably less of a challenge :-)


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 17, 2019 12:07 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1467
Location: Scotland
Code:

r0 = $80
r1 = $82
; 6502 code to put numbers into r0, r1
jsr sweet16
add r1
rtn
; result is in r0


-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 17, 2019 12:14 pm 
Offline

Joined: Thu Mar 03, 2011 5:56 pm
Posts: 284
6502 or 65C02 instruction set?


Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 17, 2019 12:40 pm 
Offline

Joined: Thu Mar 03, 2011 5:56 pm
Posts: 284
I came up with this:

Code:

lda Op2
eor #$ff
sta Res
ldx Op1
txa
clc
sbc Res
tax
stx Res
ldy Op1+1
tya
adc Op2+1
tay
sty Res+1



Top
 Profile  
Reply with quote  
PostPosted: Thu Jan 17, 2019 1:08 pm 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 325
That's quite similar to my one:
Code:
CLC
LDA a
ADC b
STA result
LDX b+1
TXA
EOR #$FF
TAX
STX tmp
LDY a+1
TYA
SBC tmp
TAY
STY result+1


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 26 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: