Professional Documents
Culture Documents
Logical Operations: 1's Complement
Logical Operations: 1's Complement
1 operand
$0C
for bit operations, could mask out all the bits you
are not interested in testing
DOORS DC.B $05 ;1 indicates door is open
00000101
flags: Z, N, C, sometimes X
Shift Operations
1 shift = divide by two
Left: Right:
logical ≡ arithmetic logical ≠ arithmetic
X2 (shift) 0 C lsr
X
asl C 0
lsl C asr
X Preserves sign
X
rol C C ror
roxl C X X C roxr
memory 7 6 5 4 3 2 1 0
(byte)
....
1010 0010
Bit 15 Bit 0
1. Bit Test BTST #$F,D0
z ← ~(<bit number>) of destination
Z <~ (1)
<~ 0
Bit 15
ALWAYS SET TO 1
2. Bit Set = test a bit then set BSET #3,NUM
z ← ~(<bit number>) of destination 1010 0010 Z<~(0)
<bit number> of destination ← 1 1010 1010 <- 1
Bit Clear = test a bit then clear BCLR #8,D0 Z <~ (0)
ALWAYS SET TO 0
3.
z ← ~(<bit number>) of destination <- 1
<bit number> of destination ← 0 Do no change
/***************************************************************/
/* Purpose..: Compute result = left << right */
/* Input....: pointer to result */
/* Input....: left operand */
/* Input....: shift count */
/* Return...: pointer to result */
/***************************************************************/
extern asm CInt64* __rt_shl64(CInt64 *result,CInt64 left,short count)
{
move.l LEFT_LO,d0
move.l LEFT_HI,d1
move.w SHIFT_COUNT,d2
and.w #0x003F,d2
bra.s l1
l0: add.l d0,d0 Take left side and add it to itself, same as doing shift
addx.l d1,d1
l1: dbf d2,l0
This limits the shift to
move.l RESULT,a0 less than 64
move.l d0,RESULT_LO
Straight counting move.l d1,RESULT_HI
loop rts
}
Note: Aliases are set elsewhere. We will see this code again later.
/***************************************************************/
/* Purpose..: Compute result = left >> right (signed) */
/* Input....: pointer to result */
/* Input....: left operand */
/* Input....: shift count */
/* Return...: pointer to result */
/***************************************************************/
extern asm CInt64* __rt_shrs64(CInt64 *result,CInt64 left,short count)
{
move.l LEFT_LO,d0
move.l LEFT_HI,d1
move.w SHIFT_COUNT,d2
and.w #0x003F,d2
bra.s l1
l0: lsr.l #1,d0
asr.l #1,d1
bcc.s l1
bset #31,d0
l1: dbf d2,l0
move.l RESULT,a0
move.l d0,RESULT_LO
move.l d1,RESULT_HI
rts
}
/***************************************************************/
/* Purpose..: Compute result = __rol(left,right) */
/* Input....: pointer to result */
/* Input....: left operand */
/* Input....: shift count */
/* Return...: pointer to result */
/***************************************************************/
extern asm CInt64* __rt_rotl64(CInt64 *result,CInt64 left,short count)
{
move.l LEFT_LO,d0
move.l LEFT_HI,d1
move.w SHIFT_COUNT,d2
and.w #0x003F,d2
bra.s l1
l0: add.l d0,d0
addx.l d1,d1
bcc.s l1
addq.w #1,d0
l1: dbf d2,l0
move.l RESULT,a0
move.l d0,RESULT_LO
move.l d1,RESULT_HI
rts
}
Reading, Expectations
Reading:
M68000 Assembly Language [pdf, 92p; N. Znotinas]
review operation of instructions covered in presentation
examples were taken from the PalmOS 64 bit arithmetic
library, LongLong68K.c
Expectations:
you can explain the operation of and the differences
between the various shifts and rotates
you can read/write code that uses all of the above
instructions, eg. the PalmOS 64 bit arithmetic library
Data area
Prompt