Questions tagged [carryflag]

A carry flag usually indicates whether an arithmetic instruction (e.g. addition or subtraction) has resulted in a carry or borrow. This flag can then be used as the basis for a conditional branch or other conditional execution.

On x86 processors, the carry flag is denoted CF and is the low bit of the FLAGS (or EFLAGS or rFLAGS) register.

This tag is for questions about how the carry flag operates, how to use it, and related topics.

112 questions
2
votes
2 answers

Doing 64bit addition in HLSL, why is one of my implementations producing incorrect results?

I have 2 different implementations of a 64bit add in HLSL. If I want to set A += B, where al, ah, bl, and bh are the low and high 32 bits of A and B respectively, then I do either (1): #define pluseq64(al, ah, bl, bh) do {\ uint tadd0 = al >>…
MNagy
  • 423
  • 7
  • 20
2
votes
1 answer

Setting and Clearing the Carry Flag with Addition and Subtraction

I was having difficulty clearing the carry flag but I have come up with a way to clear it using subtraction but I was wondering if there was a better way someone could share with me on how to set and clear the carry flag using addition and…
Josefhu15
  • 83
  • 2
  • 11
2
votes
2 answers

auxiliary flag in X86 processor

The auxiliary flag becomes set when the lower nibble produces a carry to the higher order nibble. For example: 1001 9 1001 9 ---- ---- 1 0010 18 In this case the axillary carry is set. I also heard that this carry is used to add 0110 to…
Danny
  • 85
  • 1
  • 5
2
votes
2 answers

negative operation in assembly language and carryflag

when I am doing negative operation on A79CDB48h in assembly language,I am getting CF(carry flag ) to be set 1. Can someone please explain why this happen
Nikunj Kumar
  • 306
  • 6
  • 18
2
votes
1 answer

Overflow vs Carry flags, really basic terms

I've been trying to get my head around overflow vs carry (for ARM7, but basic enough that I mean the terms as applied to anything). I think I finally have it - but I want to check that my "real basic understanding" is correct, all complexity…
OJFord
  • 10,522
  • 8
  • 64
  • 98
2
votes
2 answers

Branch and carry added by compiler

I'm looking at a disassembly of an executable I just built, and I'm confused as to what this line can possibly mean: 00000000 : 0: e1a0100d mov r1, sp 4: e59fd090 ldr sp, [pc, #144] 8: e92d4002 push {r1, lr} …
MarkP
  • 4,168
  • 10
  • 43
  • 84
1
vote
1 answer

Carry flag in MSP430 is confused

"mov #10,r5\n" "sub #1,r5\n" //test value I run in hardware, when 'sub' exec, the Carry flag is set. why? enter image description here
Duo jia
  • 13
  • 2
1
vote
1 answer

What is the difference between “4 - 12” and “4 + (-12)”?

I try to compare the next expressions: 1) mov al, 4 mov bl, 12 sub al, bl ; CF == 1 0000 0100 (4) + 1111 0100 (-12) = 1111 1000 (-8 == 248) 2) mov al, 4 mov bl, -12 add al, bl ; CF == 0 0000 0100…
Danny
  • 126
  • 6
1
vote
1 answer

Why doesn't java use long[] in BigInteger's mag field?

I believe in 64-bit JVM long[] is much more efficient than int[], and it can significantly speed up RSA operations. Carry is a problem in long[], but we can use some native methods to force long as unsigned, e.g. long z = u64add(x, y, cr), here cr…
auntyellow
  • 2,423
  • 2
  • 20
  • 47
1
vote
1 answer

Associativity of ADC and SBB

The operation of ADC is DEST ← DEST + SRC + CF, and the operation of SBB is DEST ← (DEST – (SRC + CF)). What puzzles me is the effect on FLAGS that these instructions have. In the case of SBB, the associativity is clear, and I would therefore assume…
user2039981
1
vote
1 answer

Carry flag of the operation 0 - 1 in 8 bit register

I tried the following code in emu 80x86 IDE : mov al,0h sub al,1h In the output it displays in the emulator al=FF and I did understand it, but what I didn't understand is why in the flags section cf=1
smailys
  • 35
  • 4
1
vote
0 answers

Why are OF and CF flags set in this case when using IMUL r/m8 instruction

When using IMUL instruction with a single 8-bit operand, the result is stored in AX register. I have the following code mov eax, 0 mov ebx, 0 mov al, 48 mov bl, 4 call dumpregs imul bl call dumpregs 48 * 8 is 192(C0…
Tayyab Mazhar
  • 1,560
  • 10
  • 26
1
vote
2 answers

Overflow/carry flag in MIPS

I have searched a bit and didn't find anything that properly explained this. In MIPS you have add and addu to do additions. The main difference is that addu doesn't generate an overflow exceptions. Let's say we have this binary (I'm using four bits…
user4307777
1
vote
1 answer

Assembly x86-64 setting carry flag for sub instruction

I am working through Richard Detmer's Assembly Language book. The first chapter states: A borrow occurs in the subtraction a - b when b is larger than a as unsigned numbers. Computer hardware can detect a borrow in subtraction by looking at whether…
Tryer
  • 3,580
  • 1
  • 26
  • 49
1
vote
1 answer

ASSEMBLY X86 - how to prevent Clear Flag errors? (the jc command)

USING DOSBOX WITH TASM First of all, I want to sorry for the incomprehensible title, I didn't really know how to call it because I can't define the problem myself, that's why I need help. I'm trying to show a blinking picture on the screen, simply 2…
YUVAL RON
  • 47
  • 7