Question

I'm writing an ARM11 emulator and now I'm trying to set CPRS flags which are N(negative result), Z(zero), C(carry out) and V(overflow)

this is what the spec says:

The C bit in logical operations (and, eor, orr, teq, tst and mov) will be set to the carry out from any shift operation (i.e.the result from the barrel shifter). In arithmetic operations (add, sub, rsb and cmp) the C bit will be set to the carry out of the bit 31 of the ALU.

My question is, how do I determine the carry out from logical and arithmetic operations? Operations work on two uint32_t, e.g. my eor operation simply returns x ^ y, and after that I need to set CPRS flags.

EDIT: For addition, C is set to 1 if the addition produced a carry (unsigned over ow), it is set to 0 otherwise. For subtraction (including comparison), the bit C is set to 0 if the subtraction produced a borrow, otherwise is set to 1.

Was it helpful?

Solution

Logical operations are a bit of a red herring here - obviously eor r0, r1, r2 isn't going to produce overflow or carry. However, it's not the logical operations themselves that we care about:

The C bit in logical operations (and, eor, orr, teq, tst and mov) will be set to the carry out from any shift operation (i.e.the result from the barrel shifter).

Remember that optional shift on any data processing instruction? Given eor r0, r1, r2 lsl #3, the carry you care about is whatever r2 lsl #3 generates. However you're implementing flag-setting for shifts*, do that.

* if you're stuck on that too, I saw plenty of good ideas in a quick flick through the related questions over there -->

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top