emulator101 | Source code to all the tutorials on emulator101.com | Emulator library
kandi X-RAY | emulator101 Summary
kandi X-RAY | emulator101 Summary
Source code to all the tutorials on emulator101.com.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of emulator101
emulator101 Key Features
emulator101 Examples and Code Snippets
Community Discussions
Trending Discussions on emulator101
QUESTION
I'm working on a personal project to improve my knowledge on how a CPU works. So I'm doing a Intel 8080 emulator, which is a 8 bits microprocessor.
In the implementation of a RRC instruction, which example is this:
...ANSWER
Answered 2017-Sep-27 at 21:16Lets study the steps in order:
uint8_t x = state->a;
Use a temporary variable for the current value of theA
register;(x & 1) << 7
shift the low order bit to the high order bit;(x & 1)
is the value of the low order bit as all other bits ofx
are masked off.(x >> 1)
shift the other bits one place to the right (towards the lower bits).state->a = ((x & 1) << 7) | (x >> 1);
combine the bits from the previous 2 steps and store as the new value of theA
register;state->cc.cy = (1 == (x&1));
store the low order bit from the original value into the carry bit (this is the bit that was rotated into the high order bit).
The effect of these steps is a rotation of the 8 bits one step to the right, with the low order bit landing into the carry flag. The 8080 reference card describes this as Rotate Accumulator Right thru Carry
.
Note that the steps can be simplified:
state->a = ((x & 1) << 7) | (x >> 1);
is the same asstate->a = (x << 7) | (x >> 1);
becausestate->a
is auint8_t
.state->cc.cy = (1 == (x&1))
is the same asstate->cc.cy = x & 1;
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install emulator101
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