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
0
votes
1 answer

assembly 8086 carry flag - signed number how minus equals plus

I dont understood something. This the question: mov al,-128d mov ah,40d add al,ah ;result is out of 8 bit unsigned range? why carry flag dont turn on? it's need to be 88, 88 don't in the range of 0-255! why the number little d in the end and not…
user5592500
0
votes
2 answers

AT&T Assembly carry flag

I need some help in AT&T assembly again, I've load some data into memory like below (hex and dec). (gdb) x/8xb &buffer_in 0x8049096: 0x03 0x02 0x10 0x27 0xe8 0x03 0x64 0x00 (gdb) x/8db &buffer_in 0x8049096: 3 2 …
Barcys
  • 1
  • 1
  • 3
0
votes
1 answer

How to assign the value of a register to the CF?

Say I need to save and restore the value in CF. I know one technique is to use pushfand popf. But this is way too expensive for me, as I only need CF. I am trying to use one single register to do this. For saving, I used setc %r12b. However, I don't…
JrZ
  • 9
  • 2
0
votes
2 answers

How does a processor(esp. ARM) interpret an overflow result at later stage in execution when the result is wirtten back to memory

Since processors follow the convention of representing numbers as 2's complement how do they know whether the number resulted from an addition of two positive numbers is still positive and not negative. For example if I add two 32bit numbers: Let r2…
Arvind
  • 198
  • 2
  • 11
0
votes
1 answer

Assembly Language Shift into Carry Flags

I currently got an assignment where I have to code in assembly language where you take user input to get a 4 digit hexadecimal value and convert it into binary and then after you get the binary value you have to convert it into a month day and year,…
jbr012
  • 13
  • 3
0
votes
2 answers

Fastest way to set a Carry Flag

I'm doing a cycle to sum two arrays. My objective is do it by avoiding carry checks c = a + b; carry = (c
0
votes
1 answer

Doing 64bit addition with 2 high 32bit integers and 2 low 32bit integers. Are there more efficient ways of getting the carry bit?

Let's say that A and B are my lower 32bit integers, and T is a 32bit integer that I want to represent the carry from adding A and B. I threw together some quick logic to get T: T = (A >> 1) + (B >> 1); T += A & B & 1; T >>= 31; It works, but I'm…
MNagy
  • 423
  • 7
  • 20
0
votes
1 answer

Rotate and Rotate through carry usage

I'm designing a processor, and have created a list of frequently used ALU operations. Rotate and rotate through carry are found in almost all processors, and I would like to know why. Besides some obscure mention of cryptography, I don't see what…
tayfun2150
  • 23
  • 4
0
votes
1 answer

Detect overflow and carry when working with 16b values

I'm working with signed 16 bit wide variables. When adding, subtracting etc, can i detect the carry and overflow the following way: I store the result in a 32bit wide variable, and then check the 17th bit (bits from 0-16 represent the value, and if…
idjuradj
  • 1,355
  • 6
  • 19
  • 31
0
votes
2 answers

How to determine if carry out occuurs in C

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…
akalikin
  • 1,071
  • 12
  • 35
0
votes
1 answer

OpenCL assembly optimization for "testing carry flag after adding"

In my OpenCL kernel, I find this: error += y; ++y; error += y; // The following test may be implemented in assembly language in // most machines by testing the carry flag after adding 'y' to // the value of 'error' in the previous step, since…
l33t
  • 18,692
  • 16
  • 103
  • 180
0
votes
2 answers

java short how can I tell if a carry is needed

if I add or subtract two short values, how can I tell if I would need to flag a carry condition
Chris Camacho
  • 1,164
  • 1
  • 9
  • 31
-1
votes
2 answers

Connection between the BT instruction and the carry flag CF

I know that for example BT BX, 0 transfers the first bit of the BX register to the carry flag CF. Isn't the carry flag restricted to only have values of 0 and 1, because it's a flag? Does BT change the CF value from the first bit of the register…
-1
votes
2 answers

Incomprehensible behavior of the CF flag

Let's say there is a piece of code: mov al, 12 mov bl, 4 sub al, bl In this case, the CF = 0 flag, but in my opinion it should be equal to 1, since the subtraction operation is implemented on an addition operation and the processor does not know…
Danny
  • 126
  • 6
-1
votes
1 answer

What is the alternate way of doing "add" and "carry" operation in Assembly Language?

Hye! I have a question regarding Assembly Language. The instruction adc eax, ebx adds register eax, register ebx, and the contents of the carry flag, and then store the result back to eax. My question is that assume adc instructions are not allowed,…