Comus for obtaining carry flag?
Author Message
Comus for obtaining carry flag?

Is there a method in common usage for obtaing the carry flag from the
most recent arithmetic operation?

--
George Morrison
Aberdeen, Scotland

Sat, 08 Nov 2003 02:18:57 GMT
Comus for obtaining carry flag?

Quote:
> Is there a method in common usage for obtaing the carry flag from the
> most recent arithmetic operation?

Not in standard Forth.  Chuck included the carry bit in the
top of the stack in his chips which means that one can test
for carry not only in the last operation, but in any operation
from the past.  Chuck included an opcode to test for carry in the
instruction set, C-zero, which branches on no-carry.  This
then maps to the words -IF -WHILE and -UNTIL in Machine
Forth which work, more or less, like IF WHILE UNTIL.

If you don't have the extra bit on the stack, an unusual
architectural feature, one could test for carry in the
processor's carry flag from the last operation in some
CODE inside of your own -IF -WHILE -UNTIL words.  This has
been the practice for a decade in Machine Forth.

Sat, 08 Nov 2003 02:35:36 GMT
Comus for obtaining carry flag?
: Is there a method in common usage for obtaing the carry flag from the
: most recent arithmetic operation?

Effectively, yes.  M+ saves the carry on top of the stack, as does M*.

Andrew.

Sat, 08 Nov 2003 03:10:14 GMT
Comus for obtaining carry flag?

Quote:

> : Is there a method in common usage for obtaing the carry flag from the
> : most recent arithmetic operation?

> Effectively, yes.  M+ saves the carry on top of the stack, as does M*.

Yes, but only for the mixed math operations.  In those words the carry
flag
gets a whole cell.  I was thinking of the reading the processor's carry
flag after any math operation.

But of course that is the standard way to do extended precision
math operations.  There is also M*/ and with these words you get
doubles.  One can treat the high word as a flag, but it is more
than just a carry flag.

Sat, 08 Nov 2003 03:41:46 GMT
Comus for obtaining carry flag?

Quote:

> Is there a method in common usage for obtaing the carry flag from the
> most recent arithmetic operation?

> --
> George Morrison
> Aberdeen, Scotland

There can be no portable method. The instructions that affect carry
differ among processors, and there are some without one. (I never
thought much about how such a one might be programmed.) The code to get
carry into a flag probably has to be close to the low-level arithmetic
operation itself, because subsequent operations can change it.

Does anyone know of a high-level language that includes access to flags
like carry and overflow? I don't.

Jerry
--
Engineering is the art of making what you want from things you can get.
-----------------------------------------------------------------------

Sat, 08 Nov 2003 05:50:34 GMT
Comus for obtaining carry flag?

Quote:

> : Is there a method in common usage for obtaing the carry flag from the
> : most recent arithmetic operation?

> Effectively, yes.  M+ saves the carry on top of the stack, as does M*.

> Andrew.

SwiftForth 2.00.3 19may2000
1. 2 m+ .s
3 0 <-Top  ok
d. 3  ok

Where is carry?

Jerry
--
Engineering is the art of making what you want from things you can get.
-----------------------------------------------------------------------

Sat, 08 Nov 2003 05:55:16 GMT
Comus for obtaining carry flag?

Quote:
> Does anyone know of a high-level language that includes access to
> flags like carry and overflow? I don't.

Occam? Maybe aph still remembers.

-marcel

Sat, 08 Nov 2003 06:34:16 GMT
Comus for obtaining carry flag?

Quote:

> Does anyone know of a high-level language that includes access to flags
> like carry and overflow? I don't.

If you ask Chuck Moore he will say Forth.  But not in the first
20 years of its history.

Sat, 08 Nov 2003 07:15:04 GMT
Comus for obtaining carry flag?

Quote:

>Where is carry?

Right here:

Quote:
>1. 2 m+ .s
>3 0 <-Top  ok

^
|

( in GForth this works, at least )

HEX FFFFFFFF. M+ DECIMAL .S

You'll find the result to be 1 1<-top, where the top-most 1 is the carry.

--
KC5TJA/6, DM13, QRP-L #1447
Samuel A. Falvo II
Oceanside, CA

Sat, 08 Nov 2003 07:21:40 GMT
Comus for obtaining carry flag?

Quote:

>> Is there a method in common usage for obtaing the carry flag from the
>> most recent arithmetic operation?

>> --
>> George Morrison
>> Aberdeen, Scotland

> There can be no portable method. The instructions that affect carry
> differ among processors, and there are some without one. (I never
> thought much about how such a one might be programmed.) The code to get
> carry into a flag probably has to be close to the low-level arithmetic
> operation itself, because subsequent operations can change it.

Quite true.  The tests for carry and overflow should be easy to do
in low-level, but that's not portable.

Quote:
> Does anyone know of a high-level language that includes access to flags
> like carry and overflow? I don't.

: +CARRY  ( x y -- z carry )  0 TUCK D+ ;

Check for overflow is done by saving an operand and comparing the result
unsigned. I'm too tired to remember or program how.

(
--

)

Sat, 08 Nov 2003 08:45:05 GMT
Comus for obtaining carry flag?

Quote:
>( in GForth this works, at least )

>HEX FFFFFFFF. M+ DECIMAL .S

You know, someone is editing my posts.  I really think this is true, because
I *KNOW* I typed the following :) :

HEX FFFFFFFF. 1 M+ DECIMAL .S

--
KC5TJA/6, DM13, QRP-L #1447
Samuel A. Falvo II
Oceanside, CA

Sat, 08 Nov 2003 13:42:17 GMT
Comus for obtaining carry flag?

Quote:
>You know, someone is editing my posts.  I really think this is true, because
>I *KNOW* I typed the following :) :

>HEX FFFFFFFF. 1 M+ DECIMAL .S

If you expect this to return 1 1 , then you must have been thinking
wrong.

--
Bart.

Sat, 08 Nov 2003 16:43:45 GMT
Comus for obtaining carry flag?
:>

:> : Is there a method in common usage for obtaing the carry flag from the
:> : most recent arithmetic operation?
:>
:> Effectively, yes.  M+ saves the carry on top of the stack, as does M*.

: Yes, but only for the mixed math operations.  In those words the
: carry flag gets a whole cell.

Correct.  An add with carry is a mixed math operation, isn't it?

Andrew.

Sat, 08 Nov 2003 18:38:18 GMT
Comus for obtaining carry flag?

:> Does anyone know of a high-level language that includes access to
:> flags like carry and overflow? I don't.

: Occam? Maybe aph still remembers.

Not Occam, no.

Which reminds me: in one of my rare encounters with the great and the
modern programming languages in this regard.  We'd been talking about
high speed implementations of cryptographic algorithms and how hard it
is to write efficient primitives in high-level languages.

Andrew.

Sat, 08 Nov 2003 18:43:53 GMT
Comus for obtaining carry flag?
:>

:> : Is there a method in common usage for obtaing the carry flag from the
:> : most recent arithmetic operation?
:>
:> Effectively, yes.  M+ saves the carry on top of the stack, as does M*.

: Yes, but only for the mixed math operations.  In those words the
: carry flag gets a whole cell.  I was thinking of the reading the
: processor's carry flag after any math operation.

What carry flag?  Lots of processors don't have one.

Andrew.

Sat, 08 Nov 2003 18:45:09 GMT

 Page 1 of 4 [ 59 post ] Go to page: [1] [2] [3] [4]

Relevant Pages
 12. ANEW Comus