this post was submitted on 28 Oct 2025
25 points (93.1% liked)

Ask Lemmy

35443 readers
1228 users here now

A Fediverse community for open-ended, thought provoking questions


Rules: (interactive)


1) Be nice and; have funDoxxing, trolling, sealioning, racism, and toxicity are not welcomed in AskLemmy. Remember what your mother said: if you can't say something nice, don't say anything at all. In addition, the site-wide Lemmy.world terms of service also apply here. Please familiarize yourself with them


2) All posts must end with a '?'This is sort of like Jeopardy. Please phrase all post titles in the form of a proper question ending with ?


3) No spamPlease do not flood the community with nonsense. Actual suspected spammers will be banned on site. No astroturfing.


4) NSFW is okay, within reasonJust remember to tag posts with either a content warning or a [NSFW] tag. Overtly sexual posts are not allowed, please direct them to either !asklemmyafterdark@lemmy.world or !asklemmynsfw@lemmynsfw.com. NSFW comments should be restricted to posts tagged [NSFW].


5) This is not a support community.
It is not a place for 'how do I?', type questions. If you have any questions regarding the site itself or would like to report a community, please direct them to Lemmy.world Support or email info@lemmy.world. For other questions check our partnered communities list, or use the search function.


6) No US Politics.
Please don't post about current US Politics. If you need to do this, try !politicaldiscussion@lemmy.world or !askusa@discuss.online


Reminder: The terms of service apply here too.

Partnered Communities:

Tech Support

No Stupid Questions

You Should Know

Reddit

Jokes

Ask Ouija


Logo design credit goes to: tubbadu


founded 2 years ago
MODERATORS
 

I figured one of y'all would just know seeing how ubiquitous the 6502 is. I'm not following any tutorial at the moment and it has been too long since I last mucked around in assembly. I have the programming manual but it is convoluted between the 6502 and 65C816 stuff.

I'm messing with the little Easy 6502 emulator (Flatpak/FlatHub). I want to nest a couple of loops. I should probably just use the stack, but I went down this rabbit hole and damn it I want to find the rabbit!

I want something like (crude):

define lineL $1000
define lineH $1001

LDA $00
STA $lineL
LDA $02
STA $lineH

Hopefully I have that endian right... So now I have a 2 byte word starting at address 0×1000 and loaded with 0x0200. I want to increment this value as a 16 bit variable up to 0x05FF. What I am struggling with is which addressing mode indexes like this or if this must be manually implemented (– which does not seem right to me).

I'll figure it out on my own in the next couple of hours regardless. It is more fun to chat and see the spectrum of knowledge here, or maybe not, either way, ya don't know if ya don't try. Skool me Woz

top 7 comments
sorted by: hot top controversial new old
[–] FigMcLargeHuge@sh.itjust.works 8 points 1 week ago* (last edited 1 week ago) (1 children)

~~It has been a while for me, but I think you are going to have to do this all manually. The 6502 is 8bit and you can't load a 16bit word into the accumulator. Load A $lineL, increment A, store A, then compare it to 0 and beq a routine to increment $lineH, and then also compare that to your ending number. If you are wanting to end in 0x05FF you might also have to put in a compare when $lineL gets to 05 to see if $lineH is FF. I would have to find my atari books, or do some googling.~~

Edit: see my reply.

[–] FigMcLargeHuge@sh.itjust.works 4 points 1 week ago (1 children)

Just going to reply to myself here. I think I am completely wrong on my original reply. You should use ADC. If the byte overflows the carry bit will be set, and then you can test with BCC or BCS.

http://www.6502.org/users/obelisk/6502/reference.html#ADC

"ADC - Add with Carry

This instruction adds the contents of a memory location to the accumulator together with the carry bit. If overflow occurs the carry bit is set, this enables multiple byte addition to be performed."

[–] j4k3@lemmy.world 2 points 1 week ago (1 children)

Yeah this is the answer I found too.

I was thinking about it, and since you want to count to 05FF, it might be better to load 05FF into the two bytes and use SBC and count down until you hit 0000. Then the 05 isn't causing more code to test for.

[–] abbadon420@sh.itjust.works 3 points 1 week ago

I watched a whole lot of Ben Eater and Usagi Electrics, but I still can't write any assembly. It's more fun to watch than to do imho.

[–] nettie@lemmy.world 2 points 1 week ago (1 children)

Sorry, I can't offer any help, it's been 40 years since I did 6052, on a BBC B!! Would love to know what your interest in it is?

[–] j4k3@lemmy.world 2 points 1 week ago

FORTH, and as a stepping stone into more complex hardware... again. I kinda did this once before and am getting back into it.

I am just goofing around with the emulator. I would actually like to try breadboarding something without any external connection and build it up into an interpreter. Basically try to build my own basic FORTH like threaded language from scratch. It is ambitious for my skill level. I actually have the chips to build this with a 6502, 65C816, Z80, 6809, 68010, 68008, and 8085, along with a bunch of peripherals. I also have several chips running various embedded versions of FORTH. I never managed to pick up stack programming well enough. I got so caught up in just getting FORTH onto the various chips and then getting a sensor or two working, but never built anything complex or beyond tutorial scopes. Now I am thinking in terms of the fundamentals without all the extra overhead... or trying to. There are a bunch of questions in the back of my head that I would like to answer with a functional understanding. Like what are the real limits of fuzzing for unknown hidden instructions and registers, how some red team exploits work in practice, or reasons bare metal programming is uncommon on current CPU hardware... and several other lingering curiosities.

I wish I could just jump into some 3k page documentation for a modern SoC and have a chance of doing anything useful, but it seems one needs to understand a great deal of implied context and methodologies. So I go to the source of the hardware that the present leaders played with as kids, figuring I might follow the breadcrumbs to understand them.