Skip to content

Clarify that LD HL,SP+e8 does not modify SP in gbz80 man page - #2254

Merged
Rangi42 merged 2 commits into
gbdev:masterfrom
qewer33:master
Nov 25, 2026
Merged

Rangi42 merged 2 commits into
gbdev:masterfrom
qewer33:master

Conversation

@qewer33

@qewer33 qewer33 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Description

I am currently using the gbz80 reference while developing my own hobby Game Boy emulator (https://rgbds.gbdev.io/docs/master). While implementing the LD HL, SP-e8 instruction (https://rgbds.gbdev.io/docs/master/gbz80.7#LD_HL,SP+e8) in my CPU implementation, the docs lead me to believe that the instruction modifies SP along with HL with it's phrasing. Then Blargg's 03-op sp,hl.gb test ROM didn't pass and I realized the instruction shouldn't actually modify SP.

This PR clarifies that the instruction doesn't modify SP in a new sentence, it's a 2 line change in the gbz80 man page. The new description for LD HL, SP-e8 reads:

Add the signed value e8 to SP and copy the result in HL. SP remains unchanged.

@ISSOtm

ISSOtm commented Nov 25, 2026

Copy link
Copy Markdown
Member

Just to be sure, have you checked out https://gbdev.io/aipolicy ?

As for the wording itself, that sounds more confusing so I'd rather go with “Set HL to the value of SP plus/minus the signed offset e8.”

@ISSOtm
ISSOtm requested review from ISSOtm and Rangi42 November 25, 2026 13:35
@ISSOtm ISSOtm added enhancement Typically new features; lesser priority than bugs docs This affects the documentation (web-specific issues go to rgbds-www) labels Nov 25, 2026
@qewer33

qewer33 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Yes I have seen it, I'm sorry if the wording sounds like AI but both the addition and the PR description was written by me and not an AI 😅 and I don't use AI while developing my emulator either.

As I said, I just misunderstood the explanation which caused me around 15 minutes of debugging in my emulator. I thought clarifying it would be helpful to others in the future. Your suggested wording also makes sense, I can edit the PR.

Comment thread man/gbz80.7 Resolved

@Rangi42 Rangi42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For symmetry with all the other LD command descriptions, we could phrase this as "Copy the value in register SP, plus the signed offset e8, into register HL." But LD HL, SP is an unusual instruction that already has an inconsistent description, so it's fine the way you wrote it too.

@Rangi42

Rangi42 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Just to be sure, have you checked out https://gbdev.io/aipolicy ?

I think gbdev's own issue template is to blame. :P That's where the ## Description heading comes from.

@ISSOtm ISSOtm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I like this! Thank you both :)

@ISSOtm
ISSOtm requested a review from Rangi42 November 25, 2026 16:46

@Rangi42 Rangi42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Rangi42
Rangi42 merged commit 40343f7 into gbdev:master Nov 25, 2026
23 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs This affects the documentation (web-specific issues go to rgbds-www) enhancement Typically new features; lesser priority than bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants