Re: unsigned to signed integer convesion
- From: Dave Thompson <david.thompson1@xxxxxxxxxxxxxxxx>
- Date: Sun, 14 Aug 2005 08:18:03 GMT
On Mon, 8 Aug 2005 23:32:34 +0100, Chris Croughton
<chris@xxxxxxxxxxxx> wrote:
> On Tue, 9 Aug 2005 00:44:30 +0400, Alexei A. Frounze
> <alexfru@xxxxxxx> wrote:
<snip>
> But different people find different parts of [assembly] counter-intuitive,
> that's the problem, and same is true for all other programming
> languages. Including asssembler.
>
> NOT R1
> BIC R1, R0
>
> instead of
>
> AND R1, R0
>
> And many other oddities which only make sense if you know a particular
> processor in detail.
>
The only ISA I know with BIC is PDP-11, in which case the first insn
should be _COM_.
But on the PDP-8 (except models with EAE) you had AND but not IOR (or
XOR/EOR) so had to construct it with something like:
CLA ; clear accumulator (can omit in some cases where known clear)
TAD x ; 2sComplement add, the only kind available
AND y
CIA ; 1sComplement then increment accumulator = 2sC negate
TAD x
TAD y
; x plus y minus (x and y) = x ior y
or x plus y minus 2 times (x and y) = x xor y
(where the 2 times can be done using rotate-left)
<snip>
> > If I were to change C, I'd change the conversions/promotions to be more
> > math-like, not C-like. But that's not going to happen anytime soon. Sigh.
>
> And would confuse many more. C was written for systems programmers,
> largely, and so was designed tro do what you told it and nothing more.
> So if you want to do some conversions other than the default, you do
> them. C is not designed for mathematics (try FORTRAN -- "FORmula
> TRANslation"), so you get 1/2 == 0 because that is what is expected in
> integer arithmetic even though it isn't in mathematics, and if you then
> assign the result to a floating point variable it sets it to zero.
>
Although FORTRAN is the same here -- type of a (sub)expression
including a literal is independent of context. In fact 3 / 4 gives 0
is probably as frequently asked (relatively) on comp.lang.fortran as
here, although dblvar = 3.1415926536 ! loses precision is more
frequent, since floating literals default to single precision in Ftn
not double as in C, and _some_ Ftn compilers "helpfully" fix this in
_some_ (simpler) cases whereas I have heard of no C compilers that do.
- David.Thompson1 at worldnet.att.net
.
- Follow-Ups:
- Re: unsigned to signed integer convesion
- From: Alexei A. Frounze
- Re: unsigned to signed integer convesion
- References:
- unsigned to signed integer convesion
- From: junky_fellow
- Re: unsigned to signed integer convesion
- From: Alexei A. Frounze
- Re: unsigned to signed integer convesion
- From: Chris Croughton
- unsigned to signed integer convesion
- Prev by Date: Re: Array assignment via struct
- Next by Date: Re: strange problem with send() and recv()
- Previous by thread: Re: unsigned to signed integer convesion
- Next by thread: Re: unsigned to signed integer convesion
- Index(es):
Relevant Pages
|
|