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
3
votes
2 answers

Adding Arrays of Digits as if They Represented Numbers

I have the following problem. Suppose I have to arrays X and Y whose entries consist of integers in the range 0 through 9 like X = [1 2 3] Y = [7 0 9] I want to think of these arrays as being the digits of base-10 numbers, so X represents the…
user1679672
3
votes
4 answers

big integer addition without carry flag

In assembly languages, there is usually an instruction that adds two operands and a carry. If you want to implement big integer additions, you simply add the lowest integers without a carry and the next integers with a carry. How would I do that…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
2
votes
1 answer

Binary addition/subtraction

I am having a bit of trouble understanding Carry Flag (CF) and Overflow Flag (OF). Here are some sample problems I am working on: 1. 1011 1111 2. 1111 0111 3. 0111 1110 --> 0111 1110 + 1011 0111 + 1101 1101 - 1011 0000 --> +…
raphnguyen
  • 3,565
  • 18
  • 56
  • 74
2
votes
2 answers

Count of negative numbers in assembly

dosseg .model small .stack 100h .data array db -1, -2, -3, -4, 1,2, 3, -5 .code main PROC mov ax, @data mov ds, ax xor ax, ax xor dx, dx ; reset dx lea si, array mov cx, 8 back: mov bl, [si] cmp al, bl …
learner
  • 111
  • 9
2
votes
0 answers

How to get the value of the carry flag in Rust

I want to get the value of the carry flag after performing a bit-shift. Rust has stable functions that check for overflow like so: pub fn add_with_carry(foo : &mut u8, bar : u8, cf : &mut u8) { let(result, overflow) = foo.overflowing_add(bar); …
BreadFish64
  • 33
  • 1
  • 3
2
votes
2 answers

How can i add two numbers with 12 bytes each-one?

I want to add two numbers that have 12 bytes and to store the result in a 16 bytes var. How can i do this? section .data big_num1 dd 0x11111111, 0x22222222, 0x33333333 big_num2 dd 0xffffffff, 0x22222222, 0x33333333 section .bss …
ssrvz
  • 33
  • 1
  • 6
2
votes
1 answer

auxiliary carry and carry flags in 8085

It is said that the subtraction is performed in 2's complement in 8085 and so the flags must be set according to the operation. However,in the figure shown, i am unable to figure out the reason behind auxiliary carry flag being set to '0' and the…
nishant nalin
  • 55
  • 2
  • 6
2
votes
2 answers

How to access the carry flag while adding two 64 bit numbers using asm in C

Yeah thanks that works. @PeterCordes. Also __int128 works. But one more thing as you said using the intrinsics of multiprecision arithmetic that is _addcarry_u64 in C, using the header file immintrin.h I have the following code #include…
2
votes
1 answer

How to set carry flag on ARM to 0 or 1?

I couldn't find any tutorial on how to set the flags for the Carry on ARM to 1 or to 0. Can anybody help me out with that?
2
votes
4 answers

Checking for overflow and/or carry flags, getting an integer code of which happened

First, I want to point out that this isn't really x86, it's msx88 which is a sort of simplified version of x86 for learning purposes. I need to make a function that checks for arithmetic errors (carry, overflow) and I know that I can use jo and jc…
Aviar
  • 23
  • 1
  • 3
2
votes
1 answer

16-bit adder from 4-bit Carry Look Ahead (CLA) - Cout from Block Generate and Propagate

I'm new to Verilog. Here's what I have done so far and the 4-bit CLA works. However, the 16-bit (using instances of 4-bit CLA) doesn't. The problem is definitely in setting the Cout_itermed (intermediate carries) values from block propagate (BP) and…
user5104026
  • 678
  • 1
  • 6
  • 22
2
votes
2 answers

CUDA - PTX carry propagation

I want to add two 32-bit unsigned integers in CUDA PTX and I also want to take care of the carry propagation. I am using the code below to do that, but the result is not as expected. Acording to the documentation, the add.cc.u32 d, a, b performs…
Dani Grosu
  • 544
  • 1
  • 4
  • 22
2
votes
1 answer

Carry flag addition instruction different to adc $0?

Is the adc $0 instruction the only way to add the Carry Flag to %rdx on x86/64? add %rax,%rcx adc $0 ,%rdx
2
votes
4 answers

Intel x86 Assembly - Reading and copying the carry flag

I am currently creating a program to convert an decimal into binary. I am currently using the shifting method in order to get the 0's and 1's. I have looked at other threads which leads to using LAHF and PUSHF to access the flags and set it;…
Andrew Nguyen
  • 115
  • 3
  • 10
2
votes
1 answer

use slt to check unsigned integer addition carry flag mips

I'm new to Assembly and I know this is a fair easy question. I supposed to do unsigned integer addition for $a0 and $a2 and store the result in $v0 by checking the carry flag. The assignment says: Use only addu, not add, for adding and use slt…
Serena Qi
  • 121
  • 1
  • 3
  • 11