Re: unsigned to signed integer convesion



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
.



Relevant Pages

  • Re: What *is* design?
    ... >> it's a full-fledged programming language, which can be used for all ... who'se seen a rowing boat, but the same object can be used also for all ... I think they are heuristic qualities and that is all there ...
    (talk.origins)
  • Re: What *is* design?
    ... >> it's a full-fledged programming language, which can be used for all ... who'se seen a rowing boat, but the same object can be used also for all ... I think they are heuristic qualities and that is all there ...
    (talk.origins)
  • Re: [EGN] Variable hoisting
    ... >>no idea of my programming abilities, ... >>be made by manually hoisting loop invariants. ... inversely correlated in common instances. ...
    (comp.programming)
  • Re: Theodore Adorno, a prophet of data systems design
    ... I wasn't trying to interpret Adorno's passage, ... Yes, when I started programming at Princeton, ... Shirley you had 7-track tapes. ...
    (comp.programming)
  • Re: Multithreading / Scalability
    ... of divide pretty neatly into two camps -- shared-memory model ... IBM's playstation chip -- the only multicore chip I know ... a different programming model altogether. ...
    (comp.lang.java.programmer)