Is the Game Boy Sharp LR35902 object-compatible with the 8080/Z-80?How can I rejuvenate Game Boy contacts?Game Boy Sound System Unused Memory LocationsGame Boy DMG to VGAWhy did Pokémon Red have so many overflow bugs?Game Boy save problemIntel 8080 - Behaviour of the carry bit when comparing a value with 0How did the Game Boy Advance stretch Game Boy games to widescreen?Why is the unchangable Nintendo Game Boy logo in the cartridge?What does a Nintendo Game Boy do when turned on without a game cartridge inserted?How does Game Boy / Sharp LR35902 HRAM work?

What happens when two cards both modify what I'm allowed to do?

Why must API keys be kept private?

Why do people say "I am broke" instead of "I am broken"?

What happens if an IRB mistakenly approves unethical research?

Travelling from Venice to Budapest, making a stop in Croatia

Why has DC been so Democratic compared to other states in the last presidential election?

Is a sentence true for two substructures also true for their intersection?

How to Trust a Self-Signed Certificate

Sometimes you are this word with three vowels

What's the explanation for this joke about a three-legged dog that walks into a bar?

Are symplectomorphisms of Weil–Petersson symplectic form induced from surface diffeomorphisms?

Where is this photo of a group of hikers taken? Is it really in the Ural?

Short story where a flexible reality hardens to an unchanging one

Why did computer video outputs go from digital to analog, then back to digital?

Why is the UH-60 tail rotor canted?

What exactly makes a General Products hull nearly indestructible?

Monty Hall Problem with a Fallible Monty

What is the relationship between the theme songs in Sherlock Holmes (2009 movie) and Sherlock (BBC series)?

Found more old paper shares from broken up companies

Does Impedance Matching Imply any Practical RF Transmitter Must Waste >=50% of Energy?

Span command across LaTeX environments

The seven story archetypes. Are they truly all of them?

Character Frequency in a String

Is the apartment I want to rent a scam?



Is the Game Boy Sharp LR35902 object-compatible with the 8080/Z-80?


How can I rejuvenate Game Boy contacts?Game Boy Sound System Unused Memory LocationsGame Boy DMG to VGAWhy did Pokémon Red have so many overflow bugs?Game Boy save problemIntel 8080 - Behaviour of the carry bit when comparing a value with 0How did the Game Boy Advance stretch Game Boy games to widescreen?Why is the unchangable Nintendo Game Boy logo in the cartridge?What does a Nintendo Game Boy do when turned on without a game cartridge inserted?How does Game Boy / Sharp LR35902 HRAM work?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4















(Note: by "object-compatible" I mean that the opcodes and their following operands are the same—the assembler produces the same output for equivalant assembler mnemonics. This of course excludes calling conventions, etc., because these are determined by the code one chooses to write.)



The Game Boy uses a Sharp LR35902 CPU (sometimes called a GB-Z80) that's usually said to be similar to an 8080. However, looking at some of the opcodes they don't seem compatible.



For example, on the 8080 and Z-80 opcode 3A loads the contents of the memory address specified by the next two bytes into the A register: LDA nnnn in 8080 assembler or LD A,nnnn in Z-80 assembler. On the GBDevWiki opcode 3A is listed as ldd A,(HL), loading into A the address pointed to by HL and then decrementing HL. (This indexed decrement addressing mode doesn't seem to exist at all on the 8080 or Z-80.) This seems confirmed by the WLA DX assembler opcode table, which lists it as LDD A,(HL) (with alternatives LD A,(HL-) and LD A,(HLD)).



The direct load on the LR35902 seems to be opcode FA (ld A,(nnnn)), and 16 cycles instead of 13); FA is a JMP instruction on the 8080 and Z-80.



Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set? And perhaps; Z-80 assembly syntax: the freely available assemblers use this though I don't know if the Nintendo dev kits did.



If this is the case, it seems that I should study the LR35902 instruction set carefully before writing code for it because some of the very useful changes (indirect with postdecrement) wouldn't occur to an 8080 or Z-80 programmer.










share|improve this question
























  • Instead of trying to explain a difficult term, it may be more appropriate to switch to a less ambiguous one - like binary compatible in this case?

    – Raffzahn
    6 hours ago











  • @Raffzahn I don't think "object-compatible" is ambiguous, and I agree with Wilson that "binary-compatible" has a different meaning from what I described (i.e., that it covers calling conventions and APIs, as well) That said, though Wilson and I seem to think alike on this, Wikipedia doesn't seem to distinguish the two.

    – Curt J. Sampson
    6 hours ago











  • No doubt, we could talk about this in many ways, one would be the question if there's a mixup in the definition between binary compatible and ABI - the later does reflect a relation to a certain OS interface, the former not. But we can skip that, as the need to explain what object means here already points to it being misinterpreted easy, doesn't it? Maybe using some other term like opcode compatible, which would narrow it down to the binary representation of instructions, wouldn't it?

    – Raffzahn
    4 hours ago







  • 1





    They have differences that make the Z-80 and LR35902 incompatible in either direction. See this answer for details: stackoverflow.com/questions/52009005/…

    – George Phillips
    3 hours ago











  • @GeorgePhillips That's a great help, especially the chart of opcode differences.

    – Curt J. Sampson
    2 hours ago

















4















(Note: by "object-compatible" I mean that the opcodes and their following operands are the same—the assembler produces the same output for equivalant assembler mnemonics. This of course excludes calling conventions, etc., because these are determined by the code one chooses to write.)



The Game Boy uses a Sharp LR35902 CPU (sometimes called a GB-Z80) that's usually said to be similar to an 8080. However, looking at some of the opcodes they don't seem compatible.



For example, on the 8080 and Z-80 opcode 3A loads the contents of the memory address specified by the next two bytes into the A register: LDA nnnn in 8080 assembler or LD A,nnnn in Z-80 assembler. On the GBDevWiki opcode 3A is listed as ldd A,(HL), loading into A the address pointed to by HL and then decrementing HL. (This indexed decrement addressing mode doesn't seem to exist at all on the 8080 or Z-80.) This seems confirmed by the WLA DX assembler opcode table, which lists it as LDD A,(HL) (with alternatives LD A,(HL-) and LD A,(HLD)).



The direct load on the LR35902 seems to be opcode FA (ld A,(nnnn)), and 16 cycles instead of 13); FA is a JMP instruction on the 8080 and Z-80.



Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set? And perhaps; Z-80 assembly syntax: the freely available assemblers use this though I don't know if the Nintendo dev kits did.



If this is the case, it seems that I should study the LR35902 instruction set carefully before writing code for it because some of the very useful changes (indirect with postdecrement) wouldn't occur to an 8080 or Z-80 programmer.










share|improve this question
























  • Instead of trying to explain a difficult term, it may be more appropriate to switch to a less ambiguous one - like binary compatible in this case?

    – Raffzahn
    6 hours ago











  • @Raffzahn I don't think "object-compatible" is ambiguous, and I agree with Wilson that "binary-compatible" has a different meaning from what I described (i.e., that it covers calling conventions and APIs, as well) That said, though Wilson and I seem to think alike on this, Wikipedia doesn't seem to distinguish the two.

    – Curt J. Sampson
    6 hours ago











  • No doubt, we could talk about this in many ways, one would be the question if there's a mixup in the definition between binary compatible and ABI - the later does reflect a relation to a certain OS interface, the former not. But we can skip that, as the need to explain what object means here already points to it being misinterpreted easy, doesn't it? Maybe using some other term like opcode compatible, which would narrow it down to the binary representation of instructions, wouldn't it?

    – Raffzahn
    4 hours ago







  • 1





    They have differences that make the Z-80 and LR35902 incompatible in either direction. See this answer for details: stackoverflow.com/questions/52009005/…

    – George Phillips
    3 hours ago











  • @GeorgePhillips That's a great help, especially the chart of opcode differences.

    – Curt J. Sampson
    2 hours ago













4












4








4








(Note: by "object-compatible" I mean that the opcodes and their following operands are the same—the assembler produces the same output for equivalant assembler mnemonics. This of course excludes calling conventions, etc., because these are determined by the code one chooses to write.)



The Game Boy uses a Sharp LR35902 CPU (sometimes called a GB-Z80) that's usually said to be similar to an 8080. However, looking at some of the opcodes they don't seem compatible.



For example, on the 8080 and Z-80 opcode 3A loads the contents of the memory address specified by the next two bytes into the A register: LDA nnnn in 8080 assembler or LD A,nnnn in Z-80 assembler. On the GBDevWiki opcode 3A is listed as ldd A,(HL), loading into A the address pointed to by HL and then decrementing HL. (This indexed decrement addressing mode doesn't seem to exist at all on the 8080 or Z-80.) This seems confirmed by the WLA DX assembler opcode table, which lists it as LDD A,(HL) (with alternatives LD A,(HL-) and LD A,(HLD)).



The direct load on the LR35902 seems to be opcode FA (ld A,(nnnn)), and 16 cycles instead of 13); FA is a JMP instruction on the 8080 and Z-80.



Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set? And perhaps; Z-80 assembly syntax: the freely available assemblers use this though I don't know if the Nintendo dev kits did.



If this is the case, it seems that I should study the LR35902 instruction set carefully before writing code for it because some of the very useful changes (indirect with postdecrement) wouldn't occur to an 8080 or Z-80 programmer.










share|improve this question
















(Note: by "object-compatible" I mean that the opcodes and their following operands are the same—the assembler produces the same output for equivalant assembler mnemonics. This of course excludes calling conventions, etc., because these are determined by the code one chooses to write.)



The Game Boy uses a Sharp LR35902 CPU (sometimes called a GB-Z80) that's usually said to be similar to an 8080. However, looking at some of the opcodes they don't seem compatible.



For example, on the 8080 and Z-80 opcode 3A loads the contents of the memory address specified by the next two bytes into the A register: LDA nnnn in 8080 assembler or LD A,nnnn in Z-80 assembler. On the GBDevWiki opcode 3A is listed as ldd A,(HL), loading into A the address pointed to by HL and then decrementing HL. (This indexed decrement addressing mode doesn't seem to exist at all on the 8080 or Z-80.) This seems confirmed by the WLA DX assembler opcode table, which lists it as LDD A,(HL) (with alternatives LD A,(HL-) and LD A,(HLD)).



The direct load on the LR35902 seems to be opcode FA (ld A,(nnnn)), and 16 cycles instead of 13); FA is a JMP instruction on the 8080 and Z-80.



Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set? And perhaps; Z-80 assembly syntax: the freely available assemblers use this though I don't know if the Nintendo dev kits did.



If this is the case, it seems that I should study the LR35902 instruction set carefully before writing code for it because some of the very useful changes (indirect with postdecrement) wouldn't occur to an 8080 or Z-80 programmer.







8080 game-boy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago







Curt J. Sampson

















asked 10 hours ago









Curt J. SampsonCurt J. Sampson

1,4002 silver badges18 bronze badges




1,4002 silver badges18 bronze badges












  • Instead of trying to explain a difficult term, it may be more appropriate to switch to a less ambiguous one - like binary compatible in this case?

    – Raffzahn
    6 hours ago











  • @Raffzahn I don't think "object-compatible" is ambiguous, and I agree with Wilson that "binary-compatible" has a different meaning from what I described (i.e., that it covers calling conventions and APIs, as well) That said, though Wilson and I seem to think alike on this, Wikipedia doesn't seem to distinguish the two.

    – Curt J. Sampson
    6 hours ago











  • No doubt, we could talk about this in many ways, one would be the question if there's a mixup in the definition between binary compatible and ABI - the later does reflect a relation to a certain OS interface, the former not. But we can skip that, as the need to explain what object means here already points to it being misinterpreted easy, doesn't it? Maybe using some other term like opcode compatible, which would narrow it down to the binary representation of instructions, wouldn't it?

    – Raffzahn
    4 hours ago







  • 1





    They have differences that make the Z-80 and LR35902 incompatible in either direction. See this answer for details: stackoverflow.com/questions/52009005/…

    – George Phillips
    3 hours ago











  • @GeorgePhillips That's a great help, especially the chart of opcode differences.

    – Curt J. Sampson
    2 hours ago

















  • Instead of trying to explain a difficult term, it may be more appropriate to switch to a less ambiguous one - like binary compatible in this case?

    – Raffzahn
    6 hours ago











  • @Raffzahn I don't think "object-compatible" is ambiguous, and I agree with Wilson that "binary-compatible" has a different meaning from what I described (i.e., that it covers calling conventions and APIs, as well) That said, though Wilson and I seem to think alike on this, Wikipedia doesn't seem to distinguish the two.

    – Curt J. Sampson
    6 hours ago











  • No doubt, we could talk about this in many ways, one would be the question if there's a mixup in the definition between binary compatible and ABI - the later does reflect a relation to a certain OS interface, the former not. But we can skip that, as the need to explain what object means here already points to it being misinterpreted easy, doesn't it? Maybe using some other term like opcode compatible, which would narrow it down to the binary representation of instructions, wouldn't it?

    – Raffzahn
    4 hours ago







  • 1





    They have differences that make the Z-80 and LR35902 incompatible in either direction. See this answer for details: stackoverflow.com/questions/52009005/…

    – George Phillips
    3 hours ago











  • @GeorgePhillips That's a great help, especially the chart of opcode differences.

    – Curt J. Sampson
    2 hours ago
















Instead of trying to explain a difficult term, it may be more appropriate to switch to a less ambiguous one - like binary compatible in this case?

– Raffzahn
6 hours ago





Instead of trying to explain a difficult term, it may be more appropriate to switch to a less ambiguous one - like binary compatible in this case?

– Raffzahn
6 hours ago













@Raffzahn I don't think "object-compatible" is ambiguous, and I agree with Wilson that "binary-compatible" has a different meaning from what I described (i.e., that it covers calling conventions and APIs, as well) That said, though Wilson and I seem to think alike on this, Wikipedia doesn't seem to distinguish the two.

– Curt J. Sampson
6 hours ago





@Raffzahn I don't think "object-compatible" is ambiguous, and I agree with Wilson that "binary-compatible" has a different meaning from what I described (i.e., that it covers calling conventions and APIs, as well) That said, though Wilson and I seem to think alike on this, Wikipedia doesn't seem to distinguish the two.

– Curt J. Sampson
6 hours ago













No doubt, we could talk about this in many ways, one would be the question if there's a mixup in the definition between binary compatible and ABI - the later does reflect a relation to a certain OS interface, the former not. But we can skip that, as the need to explain what object means here already points to it being misinterpreted easy, doesn't it? Maybe using some other term like opcode compatible, which would narrow it down to the binary representation of instructions, wouldn't it?

– Raffzahn
4 hours ago






No doubt, we could talk about this in many ways, one would be the question if there's a mixup in the definition between binary compatible and ABI - the later does reflect a relation to a certain OS interface, the former not. But we can skip that, as the need to explain what object means here already points to it being misinterpreted easy, doesn't it? Maybe using some other term like opcode compatible, which would narrow it down to the binary representation of instructions, wouldn't it?

– Raffzahn
4 hours ago





1




1





They have differences that make the Z-80 and LR35902 incompatible in either direction. See this answer for details: stackoverflow.com/questions/52009005/…

– George Phillips
3 hours ago





They have differences that make the Z-80 and LR35902 incompatible in either direction. See this answer for details: stackoverflow.com/questions/52009005/…

– George Phillips
3 hours ago













@GeorgePhillips That's a great help, especially the chart of opcode differences.

– Curt J. Sampson
2 hours ago





@GeorgePhillips That's a great help, especially the chart of opcode differences.

– Curt J. Sampson
2 hours ago










2 Answers
2






active

oldest

votes


















6















However, looking at some of the opcodes they don't seem compatible.




There's your answer.



The LR35902, the Z80 and the 8080 really are different CPUs. They are similar in many ways, such as the register set and much of the programming model.



The Z80 does not have the HL postdecrement addressing mode you're talking about, and some things the Z80 has the LR35902 doesn't, for example a second register set.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




No, you are completely correct. It's a rather different CPU. The Z80 is almost completely backward compatible with the 8080, excepting some undocumented bits and bobs, but the LR35902 has some opcodes remapped, some bits added or removed. So it's a Z80 "inspired" CPU, intended to be binary compatible with neither!






share|improve this answer




















  • 1





    But the Z-80 is fully binary-compatible with the 8080 (as documented), right? That makes it a different kind of "different" from the LR35902, where running 8080 code would utterly fail, in my book.

    – Curt J. Sampson
    10 hours ago







  • 1





    No, the Z-80 has at least one documented difference. Arithmetic operations like ADD A,5 put signed overflow into the parity/overflow flag on the Z-80 but the 8080 puts in parity information. Admittedly this is rarely consequential.

    – George Phillips
    3 hours ago











  • @GeorgePhillips I wasn't aware of that, thanks for pointing it out. So I just inserted the word "almost" ☺

    – Wilson
    3 hours ago











  • So there's a subset of opcodes that are identical for both, and a binary with only that subset will run correctly on both CPUs?

    – snips-n-snails
    3 hours ago






  • 1





    @snips yes. And that subset is almost the entire documented 8080 instruction set

    – Wilson
    3 hours ago



















2















Is the Game Boy Sharp LR35902 object-compatible with the 8080/Z-80?




Depends what you call object-compatible. It that's about some object formt than it depends more about the toolchain you're using.



If the question is about one being a direct upward compatible of either on opcode level, then it's a rather not.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




Yes ... and no. It is a CPU build on base of the 8080 design, much like the Z80 is. But unlike the Z80 it isn't fully compatible as many operations got dropped to make room for 'new' operations. Many of them looking like inspired by the Z80, but rescheduled to improve performance.



One issue with extending the 8080 is that its opcode space is already quite filled up, leaving only a few code points to be used. To cramp in all extension the Z80 added they had to use two byte opcodes (*1). Which did add a full fetch penalty - rendering many of them way less efficient than they could have been.



Nintendo (Sharp) avoided this by simply dropping many nice but lesser used instruction as well as Sign and Parity bits with their corresponding 12 test operations (JP/CALL/RET) to make room for what they though to be great extensions that needed to be fast. At the same time they as well implemented some 'complex' opcodes which look a bit like Z80 two byte opcodes, even encoded as CBxxh like some Z80, but they are all fixed opcodes ot two bytes with no additional parameters, executing in 8 cycles.



Some of the confusion about being a Z80 or alike may come from their usage of Z80 mnemonics for this 8080ish CPU. My guess would be that at that point of time programmers were more familiar with Zilog's codes than classic Intel mnemonics.



Bottom line, the Game Boy CPU is a true descent of an 8080 in the sense that it takes its basic recipe from it, as well as the Z80 by borrowing some of their instruction variations and iceing it over with its own changes, like no I/O address space, High Page and auto increment, making it a superb cake of it's own.




*1 - It doesn't matter how some documentation tries to make them look better by calling it escape codes or alike, for all practical purpose they are two byte opcodes, adding another fetch penalty to execution.






share|improve this answer




















  • 1





    It seems, at a quick glance, as if it might be more than just "dropping" instructions to make room for new ones; why would they keep LDA direct but just change the opcode for it? And I hadn't realized that they'd changed the flags so drastically! (3 flags dropped, 2 new ones added.)

    – Curt J. Sampson
    8 hours ago







  • 1





    "object compatibility" usually means "can run all the same object files", i.e. is binary compatible, excluding things like syscalls or timing differences.

    – Wilson
    8 hours ago











  • @CurtJ.Sampson I can't see how they moved the opcode for MVI. It was and still is 3Eh. Flagwise they didnt drop 3/added two but 'only' dopped two flags (P,S) (thus 2x2x3 instructions removed) and added one new new flag (N), but no direct tests added.

    – Raffzahn
    8 hours ago






  • 2





    I usually understand binary compatibility includes things like syscalls and calling conventions which are obviously not important for this discussion.

    – Wilson
    8 hours ago






  • 1





    I didn't say they moved MVI (load immediate), I said they moved LDA (load direct, from 3A to FA).

    – Curt J. Sampson
    8 hours ago













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "648"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fretrocomputing.stackexchange.com%2fquestions%2f11816%2fis-the-game-boy-sharp-lr35902-object-compatible-with-the-8080-z-80%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









6















However, looking at some of the opcodes they don't seem compatible.




There's your answer.



The LR35902, the Z80 and the 8080 really are different CPUs. They are similar in many ways, such as the register set and much of the programming model.



The Z80 does not have the HL postdecrement addressing mode you're talking about, and some things the Z80 has the LR35902 doesn't, for example a second register set.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




No, you are completely correct. It's a rather different CPU. The Z80 is almost completely backward compatible with the 8080, excepting some undocumented bits and bobs, but the LR35902 has some opcodes remapped, some bits added or removed. So it's a Z80 "inspired" CPU, intended to be binary compatible with neither!






share|improve this answer




















  • 1





    But the Z-80 is fully binary-compatible with the 8080 (as documented), right? That makes it a different kind of "different" from the LR35902, where running 8080 code would utterly fail, in my book.

    – Curt J. Sampson
    10 hours ago







  • 1





    No, the Z-80 has at least one documented difference. Arithmetic operations like ADD A,5 put signed overflow into the parity/overflow flag on the Z-80 but the 8080 puts in parity information. Admittedly this is rarely consequential.

    – George Phillips
    3 hours ago











  • @GeorgePhillips I wasn't aware of that, thanks for pointing it out. So I just inserted the word "almost" ☺

    – Wilson
    3 hours ago











  • So there's a subset of opcodes that are identical for both, and a binary with only that subset will run correctly on both CPUs?

    – snips-n-snails
    3 hours ago






  • 1





    @snips yes. And that subset is almost the entire documented 8080 instruction set

    – Wilson
    3 hours ago
















6















However, looking at some of the opcodes they don't seem compatible.




There's your answer.



The LR35902, the Z80 and the 8080 really are different CPUs. They are similar in many ways, such as the register set and much of the programming model.



The Z80 does not have the HL postdecrement addressing mode you're talking about, and some things the Z80 has the LR35902 doesn't, for example a second register set.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




No, you are completely correct. It's a rather different CPU. The Z80 is almost completely backward compatible with the 8080, excepting some undocumented bits and bobs, but the LR35902 has some opcodes remapped, some bits added or removed. So it's a Z80 "inspired" CPU, intended to be binary compatible with neither!






share|improve this answer




















  • 1





    But the Z-80 is fully binary-compatible with the 8080 (as documented), right? That makes it a different kind of "different" from the LR35902, where running 8080 code would utterly fail, in my book.

    – Curt J. Sampson
    10 hours ago







  • 1





    No, the Z-80 has at least one documented difference. Arithmetic operations like ADD A,5 put signed overflow into the parity/overflow flag on the Z-80 but the 8080 puts in parity information. Admittedly this is rarely consequential.

    – George Phillips
    3 hours ago











  • @GeorgePhillips I wasn't aware of that, thanks for pointing it out. So I just inserted the word "almost" ☺

    – Wilson
    3 hours ago











  • So there's a subset of opcodes that are identical for both, and a binary with only that subset will run correctly on both CPUs?

    – snips-n-snails
    3 hours ago






  • 1





    @snips yes. And that subset is almost the entire documented 8080 instruction set

    – Wilson
    3 hours ago














6












6








6








However, looking at some of the opcodes they don't seem compatible.




There's your answer.



The LR35902, the Z80 and the 8080 really are different CPUs. They are similar in many ways, such as the register set and much of the programming model.



The Z80 does not have the HL postdecrement addressing mode you're talking about, and some things the Z80 has the LR35902 doesn't, for example a second register set.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




No, you are completely correct. It's a rather different CPU. The Z80 is almost completely backward compatible with the 8080, excepting some undocumented bits and bobs, but the LR35902 has some opcodes remapped, some bits added or removed. So it's a Z80 "inspired" CPU, intended to be binary compatible with neither!






share|improve this answer
















However, looking at some of the opcodes they don't seem compatible.




There's your answer.



The LR35902, the Z80 and the 8080 really are different CPUs. They are similar in many ways, such as the register set and much of the programming model.



The Z80 does not have the HL postdecrement addressing mode you're talking about, and some things the Z80 has the LR35902 doesn't, for example a second register set.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




No, you are completely correct. It's a rather different CPU. The Z80 is almost completely backward compatible with the 8080, excepting some undocumented bits and bobs, but the LR35902 has some opcodes remapped, some bits added or removed. So it's a Z80 "inspired" CPU, intended to be binary compatible with neither!







share|improve this answer














share|improve this answer



share|improve this answer








edited 3 hours ago

























answered 10 hours ago









WilsonWilson

14k6 gold badges65 silver badges156 bronze badges




14k6 gold badges65 silver badges156 bronze badges







  • 1





    But the Z-80 is fully binary-compatible with the 8080 (as documented), right? That makes it a different kind of "different" from the LR35902, where running 8080 code would utterly fail, in my book.

    – Curt J. Sampson
    10 hours ago







  • 1





    No, the Z-80 has at least one documented difference. Arithmetic operations like ADD A,5 put signed overflow into the parity/overflow flag on the Z-80 but the 8080 puts in parity information. Admittedly this is rarely consequential.

    – George Phillips
    3 hours ago











  • @GeorgePhillips I wasn't aware of that, thanks for pointing it out. So I just inserted the word "almost" ☺

    – Wilson
    3 hours ago











  • So there's a subset of opcodes that are identical for both, and a binary with only that subset will run correctly on both CPUs?

    – snips-n-snails
    3 hours ago






  • 1





    @snips yes. And that subset is almost the entire documented 8080 instruction set

    – Wilson
    3 hours ago













  • 1





    But the Z-80 is fully binary-compatible with the 8080 (as documented), right? That makes it a different kind of "different" from the LR35902, where running 8080 code would utterly fail, in my book.

    – Curt J. Sampson
    10 hours ago







  • 1





    No, the Z-80 has at least one documented difference. Arithmetic operations like ADD A,5 put signed overflow into the parity/overflow flag on the Z-80 but the 8080 puts in parity information. Admittedly this is rarely consequential.

    – George Phillips
    3 hours ago











  • @GeorgePhillips I wasn't aware of that, thanks for pointing it out. So I just inserted the word "almost" ☺

    – Wilson
    3 hours ago











  • So there's a subset of opcodes that are identical for both, and a binary with only that subset will run correctly on both CPUs?

    – snips-n-snails
    3 hours ago






  • 1





    @snips yes. And that subset is almost the entire documented 8080 instruction set

    – Wilson
    3 hours ago








1




1





But the Z-80 is fully binary-compatible with the 8080 (as documented), right? That makes it a different kind of "different" from the LR35902, where running 8080 code would utterly fail, in my book.

– Curt J. Sampson
10 hours ago






But the Z-80 is fully binary-compatible with the 8080 (as documented), right? That makes it a different kind of "different" from the LR35902, where running 8080 code would utterly fail, in my book.

– Curt J. Sampson
10 hours ago





1




1





No, the Z-80 has at least one documented difference. Arithmetic operations like ADD A,5 put signed overflow into the parity/overflow flag on the Z-80 but the 8080 puts in parity information. Admittedly this is rarely consequential.

– George Phillips
3 hours ago





No, the Z-80 has at least one documented difference. Arithmetic operations like ADD A,5 put signed overflow into the parity/overflow flag on the Z-80 but the 8080 puts in parity information. Admittedly this is rarely consequential.

– George Phillips
3 hours ago













@GeorgePhillips I wasn't aware of that, thanks for pointing it out. So I just inserted the word "almost" ☺

– Wilson
3 hours ago





@GeorgePhillips I wasn't aware of that, thanks for pointing it out. So I just inserted the word "almost" ☺

– Wilson
3 hours ago













So there's a subset of opcodes that are identical for both, and a binary with only that subset will run correctly on both CPUs?

– snips-n-snails
3 hours ago





So there's a subset of opcodes that are identical for both, and a binary with only that subset will run correctly on both CPUs?

– snips-n-snails
3 hours ago




1




1





@snips yes. And that subset is almost the entire documented 8080 instruction set

– Wilson
3 hours ago






@snips yes. And that subset is almost the entire documented 8080 instruction set

– Wilson
3 hours ago














2















Is the Game Boy Sharp LR35902 object-compatible with the 8080/Z-80?




Depends what you call object-compatible. It that's about some object formt than it depends more about the toolchain you're using.



If the question is about one being a direct upward compatible of either on opcode level, then it's a rather not.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




Yes ... and no. It is a CPU build on base of the 8080 design, much like the Z80 is. But unlike the Z80 it isn't fully compatible as many operations got dropped to make room for 'new' operations. Many of them looking like inspired by the Z80, but rescheduled to improve performance.



One issue with extending the 8080 is that its opcode space is already quite filled up, leaving only a few code points to be used. To cramp in all extension the Z80 added they had to use two byte opcodes (*1). Which did add a full fetch penalty - rendering many of them way less efficient than they could have been.



Nintendo (Sharp) avoided this by simply dropping many nice but lesser used instruction as well as Sign and Parity bits with their corresponding 12 test operations (JP/CALL/RET) to make room for what they though to be great extensions that needed to be fast. At the same time they as well implemented some 'complex' opcodes which look a bit like Z80 two byte opcodes, even encoded as CBxxh like some Z80, but they are all fixed opcodes ot two bytes with no additional parameters, executing in 8 cycles.



Some of the confusion about being a Z80 or alike may come from their usage of Z80 mnemonics for this 8080ish CPU. My guess would be that at that point of time programmers were more familiar with Zilog's codes than classic Intel mnemonics.



Bottom line, the Game Boy CPU is a true descent of an 8080 in the sense that it takes its basic recipe from it, as well as the Z80 by borrowing some of their instruction variations and iceing it over with its own changes, like no I/O address space, High Page and auto increment, making it a superb cake of it's own.




*1 - It doesn't matter how some documentation tries to make them look better by calling it escape codes or alike, for all practical purpose they are two byte opcodes, adding another fetch penalty to execution.






share|improve this answer




















  • 1





    It seems, at a quick glance, as if it might be more than just "dropping" instructions to make room for new ones; why would they keep LDA direct but just change the opcode for it? And I hadn't realized that they'd changed the flags so drastically! (3 flags dropped, 2 new ones added.)

    – Curt J. Sampson
    8 hours ago







  • 1





    "object compatibility" usually means "can run all the same object files", i.e. is binary compatible, excluding things like syscalls or timing differences.

    – Wilson
    8 hours ago











  • @CurtJ.Sampson I can't see how they moved the opcode for MVI. It was and still is 3Eh. Flagwise they didnt drop 3/added two but 'only' dopped two flags (P,S) (thus 2x2x3 instructions removed) and added one new new flag (N), but no direct tests added.

    – Raffzahn
    8 hours ago






  • 2





    I usually understand binary compatibility includes things like syscalls and calling conventions which are obviously not important for this discussion.

    – Wilson
    8 hours ago






  • 1





    I didn't say they moved MVI (load immediate), I said they moved LDA (load direct, from 3A to FA).

    – Curt J. Sampson
    8 hours ago















2















Is the Game Boy Sharp LR35902 object-compatible with the 8080/Z-80?




Depends what you call object-compatible. It that's about some object formt than it depends more about the toolchain you're using.



If the question is about one being a direct upward compatible of either on opcode level, then it's a rather not.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




Yes ... and no. It is a CPU build on base of the 8080 design, much like the Z80 is. But unlike the Z80 it isn't fully compatible as many operations got dropped to make room for 'new' operations. Many of them looking like inspired by the Z80, but rescheduled to improve performance.



One issue with extending the 8080 is that its opcode space is already quite filled up, leaving only a few code points to be used. To cramp in all extension the Z80 added they had to use two byte opcodes (*1). Which did add a full fetch penalty - rendering many of them way less efficient than they could have been.



Nintendo (Sharp) avoided this by simply dropping many nice but lesser used instruction as well as Sign and Parity bits with their corresponding 12 test operations (JP/CALL/RET) to make room for what they though to be great extensions that needed to be fast. At the same time they as well implemented some 'complex' opcodes which look a bit like Z80 two byte opcodes, even encoded as CBxxh like some Z80, but they are all fixed opcodes ot two bytes with no additional parameters, executing in 8 cycles.



Some of the confusion about being a Z80 or alike may come from their usage of Z80 mnemonics for this 8080ish CPU. My guess would be that at that point of time programmers were more familiar with Zilog's codes than classic Intel mnemonics.



Bottom line, the Game Boy CPU is a true descent of an 8080 in the sense that it takes its basic recipe from it, as well as the Z80 by borrowing some of their instruction variations and iceing it over with its own changes, like no I/O address space, High Page and auto increment, making it a superb cake of it's own.




*1 - It doesn't matter how some documentation tries to make them look better by calling it escape codes or alike, for all practical purpose they are two byte opcodes, adding another fetch penalty to execution.






share|improve this answer




















  • 1





    It seems, at a quick glance, as if it might be more than just "dropping" instructions to make room for new ones; why would they keep LDA direct but just change the opcode for it? And I hadn't realized that they'd changed the flags so drastically! (3 flags dropped, 2 new ones added.)

    – Curt J. Sampson
    8 hours ago







  • 1





    "object compatibility" usually means "can run all the same object files", i.e. is binary compatible, excluding things like syscalls or timing differences.

    – Wilson
    8 hours ago











  • @CurtJ.Sampson I can't see how they moved the opcode for MVI. It was and still is 3Eh. Flagwise they didnt drop 3/added two but 'only' dopped two flags (P,S) (thus 2x2x3 instructions removed) and added one new new flag (N), but no direct tests added.

    – Raffzahn
    8 hours ago






  • 2





    I usually understand binary compatibility includes things like syscalls and calling conventions which are obviously not important for this discussion.

    – Wilson
    8 hours ago






  • 1





    I didn't say they moved MVI (load immediate), I said they moved LDA (load direct, from 3A to FA).

    – Curt J. Sampson
    8 hours ago













2












2








2








Is the Game Boy Sharp LR35902 object-compatible with the 8080/Z-80?




Depends what you call object-compatible. It that's about some object formt than it depends more about the toolchain you're using.



If the question is about one being a direct upward compatible of either on opcode level, then it's a rather not.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




Yes ... and no. It is a CPU build on base of the 8080 design, much like the Z80 is. But unlike the Z80 it isn't fully compatible as many operations got dropped to make room for 'new' operations. Many of them looking like inspired by the Z80, but rescheduled to improve performance.



One issue with extending the 8080 is that its opcode space is already quite filled up, leaving only a few code points to be used. To cramp in all extension the Z80 added they had to use two byte opcodes (*1). Which did add a full fetch penalty - rendering many of them way less efficient than they could have been.



Nintendo (Sharp) avoided this by simply dropping many nice but lesser used instruction as well as Sign and Parity bits with their corresponding 12 test operations (JP/CALL/RET) to make room for what they though to be great extensions that needed to be fast. At the same time they as well implemented some 'complex' opcodes which look a bit like Z80 two byte opcodes, even encoded as CBxxh like some Z80, but they are all fixed opcodes ot two bytes with no additional parameters, executing in 8 cycles.



Some of the confusion about being a Z80 or alike may come from their usage of Z80 mnemonics for this 8080ish CPU. My guess would be that at that point of time programmers were more familiar with Zilog's codes than classic Intel mnemonics.



Bottom line, the Game Boy CPU is a true descent of an 8080 in the sense that it takes its basic recipe from it, as well as the Z80 by borrowing some of their instruction variations and iceing it over with its own changes, like no I/O address space, High Page and auto increment, making it a superb cake of it's own.




*1 - It doesn't matter how some documentation tries to make them look better by calling it escape codes or alike, for all practical purpose they are two byte opcodes, adding another fetch penalty to execution.






share|improve this answer
















Is the Game Boy Sharp LR35902 object-compatible with the 8080/Z-80?




Depends what you call object-compatible. It that's about some object formt than it depends more about the toolchain you're using.



If the question is about one being a direct upward compatible of either on opcode level, then it's a rather not.




Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set?




Yes ... and no. It is a CPU build on base of the 8080 design, much like the Z80 is. But unlike the Z80 it isn't fully compatible as many operations got dropped to make room for 'new' operations. Many of them looking like inspired by the Z80, but rescheduled to improve performance.



One issue with extending the 8080 is that its opcode space is already quite filled up, leaving only a few code points to be used. To cramp in all extension the Z80 added they had to use two byte opcodes (*1). Which did add a full fetch penalty - rendering many of them way less efficient than they could have been.



Nintendo (Sharp) avoided this by simply dropping many nice but lesser used instruction as well as Sign and Parity bits with their corresponding 12 test operations (JP/CALL/RET) to make room for what they though to be great extensions that needed to be fast. At the same time they as well implemented some 'complex' opcodes which look a bit like Z80 two byte opcodes, even encoded as CBxxh like some Z80, but they are all fixed opcodes ot two bytes with no additional parameters, executing in 8 cycles.



Some of the confusion about being a Z80 or alike may come from their usage of Z80 mnemonics for this 8080ish CPU. My guess would be that at that point of time programmers were more familiar with Zilog's codes than classic Intel mnemonics.



Bottom line, the Game Boy CPU is a true descent of an 8080 in the sense that it takes its basic recipe from it, as well as the Z80 by borrowing some of their instruction variations and iceing it over with its own changes, like no I/O address space, High Page and auto increment, making it a superb cake of it's own.




*1 - It doesn't matter how some documentation tries to make them look better by calling it escape codes or alike, for all practical purpose they are two byte opcodes, adding another fetch penalty to execution.







share|improve this answer














share|improve this answer



share|improve this answer








edited 8 hours ago

























answered 9 hours ago









RaffzahnRaffzahn

65k6 gold badges160 silver badges269 bronze badges




65k6 gold badges160 silver badges269 bronze badges







  • 1





    It seems, at a quick glance, as if it might be more than just "dropping" instructions to make room for new ones; why would they keep LDA direct but just change the opcode for it? And I hadn't realized that they'd changed the flags so drastically! (3 flags dropped, 2 new ones added.)

    – Curt J. Sampson
    8 hours ago







  • 1





    "object compatibility" usually means "can run all the same object files", i.e. is binary compatible, excluding things like syscalls or timing differences.

    – Wilson
    8 hours ago











  • @CurtJ.Sampson I can't see how they moved the opcode for MVI. It was and still is 3Eh. Flagwise they didnt drop 3/added two but 'only' dopped two flags (P,S) (thus 2x2x3 instructions removed) and added one new new flag (N), but no direct tests added.

    – Raffzahn
    8 hours ago






  • 2





    I usually understand binary compatibility includes things like syscalls and calling conventions which are obviously not important for this discussion.

    – Wilson
    8 hours ago






  • 1





    I didn't say they moved MVI (load immediate), I said they moved LDA (load direct, from 3A to FA).

    – Curt J. Sampson
    8 hours ago












  • 1





    It seems, at a quick glance, as if it might be more than just "dropping" instructions to make room for new ones; why would they keep LDA direct but just change the opcode for it? And I hadn't realized that they'd changed the flags so drastically! (3 flags dropped, 2 new ones added.)

    – Curt J. Sampson
    8 hours ago







  • 1





    "object compatibility" usually means "can run all the same object files", i.e. is binary compatible, excluding things like syscalls or timing differences.

    – Wilson
    8 hours ago











  • @CurtJ.Sampson I can't see how they moved the opcode for MVI. It was and still is 3Eh. Flagwise they didnt drop 3/added two but 'only' dopped two flags (P,S) (thus 2x2x3 instructions removed) and added one new new flag (N), but no direct tests added.

    – Raffzahn
    8 hours ago






  • 2





    I usually understand binary compatibility includes things like syscalls and calling conventions which are obviously not important for this discussion.

    – Wilson
    8 hours ago






  • 1





    I didn't say they moved MVI (load immediate), I said they moved LDA (load direct, from 3A to FA).

    – Curt J. Sampson
    8 hours ago







1




1





It seems, at a quick glance, as if it might be more than just "dropping" instructions to make room for new ones; why would they keep LDA direct but just change the opcode for it? And I hadn't realized that they'd changed the flags so drastically! (3 flags dropped, 2 new ones added.)

– Curt J. Sampson
8 hours ago






It seems, at a quick glance, as if it might be more than just "dropping" instructions to make room for new ones; why would they keep LDA direct but just change the opcode for it? And I hadn't realized that they'd changed the flags so drastically! (3 flags dropped, 2 new ones added.)

– Curt J. Sampson
8 hours ago





1




1





"object compatibility" usually means "can run all the same object files", i.e. is binary compatible, excluding things like syscalls or timing differences.

– Wilson
8 hours ago





"object compatibility" usually means "can run all the same object files", i.e. is binary compatible, excluding things like syscalls or timing differences.

– Wilson
8 hours ago













@CurtJ.Sampson I can't see how they moved the opcode for MVI. It was and still is 3Eh. Flagwise they didnt drop 3/added two but 'only' dopped two flags (P,S) (thus 2x2x3 instructions removed) and added one new new flag (N), but no direct tests added.

– Raffzahn
8 hours ago





@CurtJ.Sampson I can't see how they moved the opcode for MVI. It was and still is 3Eh. Flagwise they didnt drop 3/added two but 'only' dopped two flags (P,S) (thus 2x2x3 instructions removed) and added one new new flag (N), but no direct tests added.

– Raffzahn
8 hours ago




2




2





I usually understand binary compatibility includes things like syscalls and calling conventions which are obviously not important for this discussion.

– Wilson
8 hours ago





I usually understand binary compatibility includes things like syscalls and calling conventions which are obviously not important for this discussion.

– Wilson
8 hours ago




1




1





I didn't say they moved MVI (load immediate), I said they moved LDA (load direct, from 3A to FA).

– Curt J. Sampson
8 hours ago





I didn't say they moved MVI (load immediate), I said they moved LDA (load direct, from 3A to FA).

– Curt J. Sampson
8 hours ago

















draft saved

draft discarded
















































Thanks for contributing an answer to Retrocomputing Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fretrocomputing.stackexchange.com%2fquestions%2f11816%2fis-the-game-boy-sharp-lr35902-object-compatible-with-the-8080-z-80%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480