Zero Flag is set when only MSB is zero?

-2

I'm taking a course in Microcontrollers, and have been stuck on the concept of flags for a while. The basic carry, overflow, and negative flags I more or less understand. However, zero flag seems to be vague in my assignments. To say that the zero flag is set when the result is zero would be acceptable enough...if the zero flag were set if the result were ABSOLUTELY zero. Here's an example from one of my assignments:

0x3A125407 + 0xC6224417 (which equals 0x0034981E with a carry of 1)

Carry is set, and so is zero (so says my assignment's answer results). So the most significant bit is zero, therefore the zero flag is set? Okay, I can understand that. However, in another one of my assignments:

MOV R6, #0xFFFFFFDD
MVN R2, R6
ADDS R7, R2, R6
SBCS R9, R7, R2

At the end of the code segment, the correct answers are that Carry and Zero are set. Here's what I got, step-by-step:

R6 = 0xFFFFFFDD
R2 = negated 0xFFFFFFDD = 0x22
R7 = R2 + R6 = 0xFFFFFFDD + 0x22 = 0xFFFFFFFF (Carry is clear)
R9 = R7 - R2 - NOT Carry = 0xFFFFFFFF - 0x22 - 1 = 0xFFFFFFDC

Where did I go wrong?

EDIT: I think the architecture is ARM. My course is only basic, so my professor doesn't mention it much. These examples are from quiz questions. There's no program actually involved. It's just identifying what flags are set. Answers I give are based on the grading software that decides what is right or wrong.

assembly
arm
microcontroller
flags
asked on Stack Overflow Sep 30, 2020 by Jsec99 • edited Oct 1, 2020 by Peter Cordes

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0