carryflag

big integer addition without carry flag

a 夏天 提交于 2019-12-10 10:17:00
问题 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 efficiently in C or C++ where I don't have access to the carry flag? It should work on several compilers and architectures, so I cannot simply use inline assembly or such. 回答1: You can use "nails" (a term from GMP): rather than using all 64 bits of a

ADC instruction in asm

匆匆过客 提交于 2019-12-05 13:10:18
In the following code, MOV AL,NUMBER1 ADD AL,NUMBER2 MOV AH, 00H ADC AH, 00H what are lines 3 and 4 for? What do they do? Also, why does the code clear AH? (I assume because AL's "ADD" operation may produce carry.) To figure this out, start by looking up what each instruction does: MOV AH, 00H This MOV instruction will set the AH register to 0 without affecting flags. ADC AH, 00H This ADC instruction will add the source operand (0), the carry flag (CF), and the destination operand ( AH ), storing the result in the destination operand ( AH ). Symbolically, then, it does: AH = AH + 0 + CF

auxiliary carry and carry flags in 8085

一曲冷凌霜 提交于 2019-12-02 01:09:24
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 same goes for carry flag. When i performed 2's complement operation, i found carry=1 (which is not taken into consideration in 2's complement) and i also found carry of 1 shifting from lower nibble to upper and so i thought auxiliary carry to be 1. But i found just the opposite for both of them. Similarly in the second case shown below, manually i got

What actually happens when a Byte overflows?

雨燕双飞 提交于 2019-12-01 02:36:32
What actually happens when a Byte overflows? Say we have byte byte1 = 150; // 10010110 byte byte2 = 199; // 11000111 If we now do this addition byte byte3 = byte1 + byte2; I think we'll end up with byte3 = 94 but what actually happens? Did I overwrite some other memory somehow or is this totally harmless? It's quite simple. It just does the addition and comes off at a number with more than 8 bits. The ninth bit (being one) just 'falls off' and you are left with the remaining 8 bits which form the number 94. (yes it's harmless) In C# if you have checked { byte byte3 = byte1 + byte2; } It will

What actually happens when a Byte overflows?

南笙酒味 提交于 2019-11-30 22:03:29
问题 What actually happens when a Byte overflows? Say we have byte byte1 = 150; // 10010110 byte byte2 = 199; // 11000111 If we now do this addition byte byte3 = byte1 + byte2; I think we'll end up with byte3 = 94 but what actually happens? Did I overwrite some other memory somehow or is this totally harmless? 回答1: It's quite simple. It just does the addition and comes off at a number with more than 8 bits. The ninth bit (being one) just 'falls off' and you are left with the remaining 8 bits which

carry/overflow & subtraction in x86

本小妞迷上赌 提交于 2019-11-27 20:15:55
I'm trying to wrap my head around overflow & carry flags in x86. As I understand it, for addition of signed 2's complement numbers, the flags can only be generated in one of four ways (my examples are 4-bit numbers): pos+pos = neg (overflow) 0111 + 0001 = 1000 (7 + 1 = -8) pos+neg = pos (carry) 0011 + 1110 = 0001 (3 + -2 = 1) neg+neg = neg (carry) 1111 + 1111 = 1110 (-1 + -1 = -2) neg+neg = pos (overflow & carry) 1000 + 1001 = 0001 (-8 + -7 = 1) So, in x86 assembly, does subracting B from A generate the same flags as adding A and -B? Here's a reference table that might help. This shows an

Efficient 128-bit addition using carry flag

心不动则不痛 提交于 2019-11-26 18:49:26
I'm using a 128 bit integer counter in the very inner loops of my C++ code. (Irrelevant background: The actual application is evaluating finite difference equations on a regular grid, which involves repetitively incrementing large integers, and even 64 bits isn't enough precision because small rounding accumulates enough to affect the answers.) I've represented the integer as two 64 bit unsigned longs. I now need to increment those values by a 128 bit constant. This isn't hard, but you have to manually catch the carry from the low word to the high word. I have working code something like this:

carry/overflow & subtraction in x86

耗尽温柔 提交于 2019-11-26 16:09:45
问题 I'm trying to wrap my head around overflow & carry flags in x86. As I understand it, for addition of signed 2's complement numbers, the flags can only be generated in one of four ways (my examples are 4-bit numbers): pos+pos = neg (overflow) 0111 + 0001 = 1000 (7 + 1 = -8) pos+neg = pos (carry) 0011 + 1110 = 0001 (3 + -2 = 1) neg+neg = neg (carry) 1111 + 1111 = 1110 (-1 + -1 = -2) neg+neg = pos (overflow & carry) 1000 + 1001 = 0001 (-8 + -7 = 1) So, in x86 assembly, does subracting B from A

Efficient 128-bit addition using carry flag

这一生的挚爱 提交于 2019-11-26 06:37:14
问题 I\'m using a 128 bit integer counter in the very inner loops of my C++ code. (Irrelevant background: The actual application is evaluating finite difference equations on a regular grid, which involves repetitively incrementing large integers, and even 64 bits isn\'t enough precision because small rounding accumulates enough to affect the answers.) I\'ve represented the integer as two 64 bit unsigned longs. I now need to increment those values by a 128 bit constant. This isn\'t hard, but you