half-car | Vehicle half-car suspension model animated in matplotlib
kandi X-RAY | half-car Summary
kandi X-RAY | half-car Summary
Vehicle half-car suspension model animated in matplotlib
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Update animation
- Calculate the length of a curve
- Returns the transformation matrix
- Simulate the robot
- Update the state
- Set the horizontal acceleration
- Animate the animation
half-car Key Features
half-car Examples and Code Snippets
Community Discussions
Trending Discussions on half-car
QUESTION
Like so many others, I am writing a Game Boy emulator and I have a couple of questions regarding the instruction 0xE8 (ADD SP, n
with an 8-bit immediate).
It is claimed here that in 16-bit instructions the half-carry flag is set if a carry occurs from bit 7 to bit 8, whereas here it is said that the half-carry flag indicates carry from bit 11 to bit 12. In this Reddit thread there seems to be a bit of confusion regarding the issue, and the (notoriously flawed, I hear) Game Boy CPU manual doesn't seem to have anything useful to say either.
My questions are the following:
- How does the half-carry flag behave in opcode 0xE8?
- How is the opcode 0xE8 implemented in the physical hardware?
- Which is right, that half-carry occurs from bit 7 to bit 8 or that half-carry occurs from bit 11 to bit 12 (in the case of 16-bit instructions)?
ANSWER
Answered 2019-Sep-17 at 17:35TL;DR: For ADD SP,n
, the H-flag is set when carry occurs from bit 3 to bit 4.
I decided to test this on real hardware, so I wrote a simple test ROM in GB-Z80 assembly that tests the following scenarios:
[SP = $000F]
ADD SP,$01
[SP = $00F0]
ADD SP,$10
[SP = $0FF0]
ADD SP,$10
For each case I store the value of register F
after the ADD
in memory, and I later display bit 5 (the H-flag) of each of those bytes on the screen.
I ran this on 3 different models (Gameboy Pocket, Gameboy Color, and Gameboy Advance SP), and got the following output on all 3 devices: 1 0 0
. So a carry from bit 3->4 caused H to be set, while a carry from 7->8 or 11->12 did not.
For ADD HL,rr
(where rr
is BC/DE/HL/SP
) it appears to be a different story. Based on my testing, H is set if carry occurs from bit 11 to bit 12.
QUESTION
How is the Auxiliary Flag calculated in x86 Assembly?
The majority of the resources I can find explain that, the Auxiliary Flag is set to '1' if there is a carry from bit 3 to bit 4.
It indicates when a carry or borrow has been generated out of the least significant four bits of the accumulator register following the execution of an arithmetic instruction.
Example:
...ANSWER
Answered 2018-Jul-14 at 16:46The sub
instruction on x86 CPUs is "real" instruction since the first chip 8086, i.e. it's not some kind of assembler convenience, which gets translated as negation + add, but it has it's own binary opcode and the CPU itself will be aware it should produce result of subtraction.
That instruction has definition from Intel, how it does affect flags, and the flags in this case are modified "as if" real subtraction is calculated. That's all you need to know when you are focusing on programming algorithm or reviewing correctness of some code. Whether the chip itself implements it as addition, and has some extra transistors converting flags to the "subtraction" variant, is "implementation detail", and as long as you want to know only result, it's not important.
The implementation details become important while you are tuning particular piece of code for performance, then considering the inner architecture of the chip and implementation of particular opcodes may give you ideas how rewrite particular code in somewhat more unintuitive/non-human way, often even with more instructions than "naive" version, but the performance will be better, due to better exploitation of the inner implementation of the chip.
But the result is well defined, and can't change by some implementation detail, that would be "bug in CPU", like the first Pentium chips did calculate wrong results for certain divisions.
That said the definitions of assembly instructions are already leaking implementation details like no other language, because the assembly instructions while designed are half-way on the path "what is simple to create in HW transistors" and half-way "what makes some programming sense", while other higher level programming languages are lot more biased toward "what makes sense", only reluctantly imposing some cumbersome limits from the HW implementation, like for example value ranges for particular bit-size of variable types.
So being curious about the implementation and why certain things are defined as they are (like for example why dec xxx
does NOT update CF flag, while otherwise it is just sub xxx,1
) will often give you new insights into how certain tasks can be written more effectively in assembly and how chips did evolve and which tasks are easier to compute than others.
But basics first. The sub
instruction updates flags as if subtraction was calculated, and the sub
instruction is not aware of any context of the values it is processing, all it gets is just the binary patterns of the values, in your case: 1111_0010 – 0111_1110
which is when interpreted in signed 8bit math "-14 - +126" (-130 doesn't fit into 8 bits, so it got truncated to +126, good assembler will emit warning/error there), or when interpreted in unsigned 8b math "242 - 126". In case of signed math the result should be -140, which gets truncated (overflow happens, OF=1) to 8b value +116, in case of unsigned math the result is +116 without unsigned overflow (carry/borrow CF=0).
The subtraction itself is well defined per-bit, i.e.
QUESTION
Hello I'm writing an emulator for Game Boy.
And I'm struggling with SUB intruction
...ANSWER
Answered 2017-Jan-02 at 14:24You can find the answers to how add/sub work and carry/overflow flags are set here:
My answer to: Overflow and Carry flags on Z80
My answer to: How does an adder perform unsigned integer subtraction?
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install half-car
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page