carryflag

Incomprehensible behavior of the CF flag

北城余情 提交于 2020-12-23 17:58:26
问题 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 what we are giving it as input, be it signed or unsigned numbers, it just does its job. That is, the code above is equivalent to the following: Enter the value 12 into the al register, i.e. 0000 1100 Enter the value 4 into the bl register, i.e. 0000

Incomprehensible behavior of the CF flag

半腔热情 提交于 2020-12-23 17:53:20
问题 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 what we are giving it as input, be it signed or unsigned numbers, it just does its job. That is, the code above is equivalent to the following: Enter the value 12 into the al register, i.e. 0000 1100 Enter the value 4 into the bl register, i.e. 0000

gdb with assembler: Print status of carry flag

蓝咒 提交于 2020-06-09 08:39:07
问题 I've got an x86 assembler program which I'm debugging with gdb. Is there a way to print the status of the carry flag inside gdb with, like, "print $cf"? 回答1: You can use: info registers eflags to get the entire set of flags. You'll see a line like: eflags 0x41 [ CF ZF ] which means that the eflags register is set to 0x41 , with the carry and zero flags set. 回答2: I check the EFLAGS register using (gdb) p $eflags $3 = [ PF ZF IF ] where "p" is just short for the "print" command. I also find it

Fastest way to set a Carry Flag

好久不见. 提交于 2020-01-07 03:42:11
问题 I'm doing a cycle to sum two arrays. My objective is do it by avoiding carry checks c = a + b; carry = (c<a) . I lost the CF when I do the loop test, with the cmp instruction. Currently, i am using and the JE and STC to test and set the previously saved state of CF . But the jump takes more less 7 cycles, what it is a lot for what I want. //This one is working asm( "cmp $0,%0;" "je 0f;" "stc;" "0:" "adcq %2, %1;" "setc %0" : "+r" (carry), "+r" (anum) : "r" (bnum) ); I already tried use the

Carry flag in substraction

纵然是瞬间 提交于 2020-01-01 11:33:51
问题 I am using MASM32. With this code: mov eax,5 sub eax,10 CF status flag will be set. But using my pencil and paper, I actually see that there is no any carry from MSB. Yes, I know that from subtraction from less number great number set CF. But I want to know why? Because using this code: mov eax,5 mov ebx,10 not ebx add ebx,1 add eax,ebx CF flag won't be ever set. 回答1: 5 - 10 = 5 + (-10) = 0x05 + (0xF5 + 1) = 0x05 + 0xF6 = 0xFB 00000101 -- 0x05 11110101 -- 0xF5 + 00000001 -- 0x01 ==========

auxiliary carry and carry flags in 8085

南笙酒味 提交于 2019-12-31 03:14:07
问题 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.

ADC instruction in asm

随声附和 提交于 2019-12-22 08:14:36
问题 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.) 回答1: 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 )

Masm assembly 8086 carry flag between data word addition

不羁岁月 提交于 2019-12-20 05:09:33
问题 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 that becomes the output. Its basically a method of working with large numbers. My code works fine for carry flags within words, but for carry flag from one full word to another it does not work. The first 16 bit word (0005 in the example below) is

Access the flags without inline assembly?

ぃ、小莉子 提交于 2019-12-12 15:47:21
问题 I have the following method in C that takes two 16-bit short ints and: Adds the two integers If the carry flag is set, add 1 to the result Negate (NOT) all the bits in the final results Return the result: short __declspec(naked) getchecksum(short s1, short s2) { __asm { mov ax, word ptr [esp+4] mov bx, word ptr [esp+8] add ax, bx jnc skip_add add ax, 1 skip_add: not ax ret } } I had to write this in inline assembly because I do not know any way to test the carry flag without using assembler.

how to set auxiliary flag for 16bits binary addition

陌路散爱 提交于 2019-12-11 13:59:45
问题 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 microprocessor... For example, when i add these 2 numbers, 0x30a2 and 0xf1ac 0011 0000 1010 0010 + 1111 0001 1010 1100 CF=1 ZF=0 PF=1 SF=0 OF=1 AF=? I'm not sure where to check it 回答1: From "Programming the 8086/8088" by James W. Coffron: AF auxiliary