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
1
vote
2 answers

How are the carry and overflow flags used to calculate multiplication in x86

How are the two flags used to correctly calculate the answer when two numbers that are multiplied overflow the register? E.g. if al holds 0xff and is multiplied by 0x2, causing an overflow into ax, how do the flags help with this?
some_id
  • 29,466
  • 62
  • 182
  • 304
1
vote
1 answer

How does the subq instruction and cf flag work together?

I've encountered two possibilities for how the carry flag can be set with: 0x00_00_00_00_00_00_00_00 - 0x80_00_00_00_00_00_00_00 (underscores to show bytes) If I did this by subtraction, we would have to borrow from a bit we don't have, which…
Enigma22134
  • 532
  • 5
  • 12
1
vote
2 answers

How is the carry flag being set in this assembly code?

Given the following assembly code for a 16-bit PRNG function, $80/8111 E2 20 SEP #$20 ; set 8-bit mode accumulator $80/8113 AD E5 05 LDA $05E5 ; load low byte of last random number $80/8116 8D 02 42 STA $4202 $80/8119 A9 05 LDA…
Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145
1
vote
3 answers

how to set auxiliary flag for 16bits binary addition

I know that when performing an 8-bit binary addition, the auxiliary flag is set to 1 if there is a carry from 3rd bit to 4th bit; but what about the addition of 2 16-bit numbers? i can't see any clear answer on the web. I'm studying intel 8086…
Xsmael
  • 3,624
  • 7
  • 44
  • 60
1
vote
3 answers

Masm assembly 8086 carry flag between data word addition

So I have this problem I'm supposed to solve and I've spent hours trying to figure out the best way to do this, google hasn't been of much help. The problem is to create a subroutine that is given a list of words that you then add with another list…
Harrison
  • 319
  • 2
  • 14
1
vote
2 answers

Carry bit in msp430

I am writing simulator to microcontroller msp430. I cant understand when i should set carry bit. For example in add instruction: 1+0x7FFF setting carry bit or 1+0xFFFF?
user3191398
1
vote
2 answers

Calculating Carry Flag

I am writing an x86 interpreter in Java and have a Python script that tests my implementations of x86 instructions against its real counterparts using NASM. According to this test all flags are set correctly, besides the carry flag. The interesting…
Benjoyo
  • 413
  • 7
  • 13
1
vote
0 answers

Should 0xABCD - 0x1234 set the carry bit?

I was studying for my final when I came across this question here: After going through it, I got an answer of 0x9999 because when you perform the subtraction via 2's complement, there is a carry on the MSB, so the branch instruction would send the…
1
vote
2 answers

ASM8086: mul, imul, carry flag and overflow flag

I understood the logic of the carry flag and the overflow flag. But, when I read this program (wrote in MASM 8086) , I got perplexed a bit. The program intent is to tell if a quadratic equation has two distincts solutions, two equals solutions or no…
sl34x
  • 51
  • 2
  • 8
1
vote
1 answer

Intel 8080: multiplication overflow

I have a 8080 processor's emulator. I need write a program, which can multiple two two-digit numbers with operations of shifting and adding(as a result I can expect four-digit number) As I know, all mathematic operations in intel-8080 are made in…
dark
  • 167
  • 1
  • 6
  • 17
1
vote
1 answer

Calculating the sign of a carry-save number

Does anyone know how to calculate the sign of a number in carry-save format, i.e. with a virtual sum and virtual carry, without adding them together? A verilog example would be ideal. Thanks!
Tom Bell
  • 489
  • 2
  • 6
  • 15
1
vote
1 answer

Simple carry bit

Ok so I am revising for a test One of the revision questions is: If R4 = FEh R5 = DCh R6= ABh Carry = 0 What are the contents of A and Carry after the following code: MOV A,R6 SUBB A,R4 SUBB A,R5 The correct answer is Carry = 1 and A = D0h I…
Andeeh
  • 99
  • 1
  • 4
  • 12
1
vote
0 answers

Is the carry flag obsolete?

The carry flag seems to have two main uses. 1) it is useful for chaining addition/subtraction instructions to operate on numbers larger than native size. Adding 32bit ints on an 8-bit architecture for example. 2) it is used for conditional branches.…
phkahler
  • 5,687
  • 1
  • 23
  • 31
0
votes
2 answers

Does the carry in the ADCS value added before the flag is updated or after in ARM?

Let's say I have an initial flag condition of z=0, n=0,c=1, q=0,v=0; and the following registers r1=1000 0003 H r2=1000 0004 H and have the following instruction: ADCS r1,r2 Would the r1 be 2000 0007 H with the new updated carry set which is zero or…
0
votes
1 answer

How can I use arm adcs in loop?

In arm assembly language, the instruction ADCS will add with condition flags C and set condition flags. And the CMP instruction do the same things, so the condition flags will be recovered. How can I solve it ? This is my code, it is doing BCD adder…
xxxx
  • 33
  • 5