delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/05/10:18:53

Date: Mon, 5 Oct 1998 15:18:33 +0100 (BST)
From: George Foot <george DOT foot AT merton DOT oxford DOT ac DOT uk>
To: Craig Rothwell <craig AT cdworld DOT co DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: converting 2 numbers into one
In-Reply-To: <3618B080.ED38C4C@cdworld.co.uk>
Message-ID: <Pine.OSF.4.05.9810051515170.18005-100000@sable.ox.ac.uk>
MIME-Version: 1.0

On Mon, 5 Oct 1998, Craig Rothwell wrote:

> how can I join 2 sets of binary
> to make one?
> 
> eg:
> 
> turn '11111111' and '00000000'
> (as 2 variables)
> 
> into '1111111100000000'? (as one
> variable)

Shift the first one left by 8 bits, then add on the second:

    (a << 8) + b

> A bit like using the Z80's HL
> register, where you could treat
> each variable seprate but also
> as one big number.

The 80x86 have that sort of system too.  Assume `a' and `b' are
global or static 32-bit integer variables:

    xorl %eax, %eax
    movb _a, %ah
    movb _b, %al
    movl %eax, _a

That puts the bottom byte of `a' into the second byte of `a' and
the bottom byte of `b' into the bottom byte of `a'.  The rest of
`a' is zeroed.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

xu do tavla fo la lojban  --  http://xiron.pc.helsinki.fi/lojban/lojban.html

- Raw text -


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