-2

i got two numbers by using read_int, and added two numbers. And finally i checked the EFLAGS (dump_regs).

So, to set carry flag, I tried "4,294,967,295 + 1" but, carry flag didn't set.('CF' didn't show in screen )

What numbers do i need if i want to set carryflag?

    call read_int
    mov ebx, eax

    call read_int
    mov ecx, eax

    mov edx, ebx             ; add the two numbers, edx = ebx - ecx
    add edx, ecx

    mov eax, edx
    call print_int
    call print_nl
    dump_regs 1

And i entered 4294967295 and 1

Forestellar
  • 23
  • 1
  • 5
  • What asm instructions did you actually use? `mov eax, 4294967295 + 1` is evaluated at assemble time into `mov eax, 0` (hopefully with a warning about the value not fitting in a 32-bit immediate). You say you were using `read_int`? Did your input literally include commas? IDK if `read_int` will parse commas, and certainly not a `+` character, if you're talking about Irvine32. So anyway, this is very much not a [mcve]. – Peter Cordes Nov 09 '18 at 01:15
  • 4
    Do `print_int` and `print_nl` preserve CF? In most calling conventions, flags are call-clobbered. Use a debugger to single-step your code and look at EFLAGS and integer register values. If the operands to `add` are actually `4294967295` and `1`, then yes it will set CF. – Peter Cordes Nov 09 '18 at 02:17
  • doing `add` with two values "4294967295 + 1" will set CF. If you are telling "no CF" by that "dump_regs 1", then obviously, the CF is highly likely long gone when the code does `dump_regs`, also who knows how `dump_regs` is implemented and if it is supposed to show flags correctly. Debugging by using debug-outputs in assembly is somewhat tricky and it is often source of the debug-output bugs, so even seasoned asm programmer has to debug the debugging code a bit to make sure it works as needed. Use debugger in the beginning, when you are just learning asm, to avoid such problems. – Ped7g Nov 09 '18 at 13:12

1 Answers1

0

You can convince yourself of the carry flag getting set, if you run the following code:

call read_int    ;Input say 150
mov ebx, eax
call read_int    ;Input say 180

add al, bl       ;This produces a carry because 150+180=330 DOESN'T FIT the 8-bit register AL

setc al          ;AL becomes 1
movzx eax, al    ;EAX becomes 1
call print_int   ;Show it

Verify with numbers that don't produce a carry:

call read_int    ;Input say 80
mov ebx, eax
call read_int    ;Input say 125

add al, bl       ;This produces NO carry because 80+125=205 DOES FIT the 8-bit register AL

setc al          ;AL becomes 0
movzx eax, al    ;EAX becomes 0
call print_int   ;Show it
Sep Roland
  • 33,889
  • 7
  • 43
  • 76