delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2003/05/22/11:12:08

X-Sybari-Space: 00000000 00000000 00000000 00000000
From: Martin Stromberg <eplmst AT epl DOT ericsson DOT se>
Message-Id: <200305221512.RAA06143@lws256.lu.erisoft.se>
Subject: Re: Add with carry
To: djgpp-workers AT delorie DOT com
Date: Thu, 22 May 2003 17:12:02 +0200 (MET DST)
In-Reply-To: <0b3001c3206f$a20aeeb0$0600000a@broadpark.no> from "Gisle Vanem" at May 22, 2003 04:37:12 PM
X-Mailer: ELM [version 2.5 PL3]
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp-workers AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> 
> In libc/crt0/crt0.s (line 250):
> 
> /* Maybe lock the initial block, expects BX:CX */
>         movl    %ecx,%ebx
>         movl    %edx,%ecx
>         addw    $4096,%cx                       /* Skip null page */
>         adcl    $0,%ebx
> 
> -----------
> 
> What happens if carry was set prior to the 'addw' ?

It's cleared or reset by addw (depending on the input to addw).

> I was just hit by this elsewhere in some 16-bit nasm code. 
> To increment a 32-bit variable I used
>   inc word [di]
>   adc word [di+2], 0
> 
> Seems resonable, but got wrong result cause the carry
> was already set. Adding a 'clc' before the 'inc' fixed it.

inc and dec don't affect the carry flag. add, adc, sub etc. do.

So what happens when [di] == 0xffff and [di+2] == X. You don't want
[di] == 0 and [di+2] == X+1 in that case?

Try
	add	word [di], 1	; Needed for setting CF.
	adc	word [di+2], 0

instead or
	inc	word [di]
	jnz	skip_upper_inc
	inc	word [di+2]
skip_upper_inc:

I'd use the first alternative (unless the second is shorter and I'm
desperate for code size).


Right,

						MartinS

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019