Download presentation
Presentation is loading. Please wait.
Published byGloria Giusti Modified over 6 years ago
1
Logical Operations bitwise logical operations AND, OR, EOR, NOT
“mask” = setting specific bits to zero e.g. mask high four bits in NUM NUM DC.B $4C for bit operations, could mask out all the bits you are not interested in testing
2
Utilization of Bits to Store Data - the case of 8 doors; 1 indicates door is open
DOORS DC.B $05 or DOORS DC.B % Are the even numbered doors closed? DOOR1 DC.B 1 DOOR2 DC.B 0 DOOR3 DC.B 1 DOOR4 DC.B 0 … DOOR8 DC.B 0 D1 D3 D5 D7 D2 D4 D6 D8 hallway
3
Shift Operations directions: left, right
types: logical, arithmetic, circular length: 1 bit, > 1 bit flags: Z, N, C, sometimes X
4
Shift Operations Right: logical ≠ arithmetic
Left: logical ≡ arithmetic C lsr X asl lsl C C asr X X rol C C ror roxl X X C C roxr
5
Utilization of Bits to Store Data - the case of 8 doors; 1 indicates door is open
DOORS DC.B $05 or DOORS DC.B % How many doors are open? DOOR1 DC.B 1 DOOR2 DC.B 0 DOOR3 DC.B 1 DOOR4 DC.B 0 … DOOR8 DC.B 0
6
Bit Operations instructions operate on one bit in Dn or memory
bit numbering: Dn = (long) … memory (byte)
7
Bit Operations e.g. NUM1 DC.B $A2 D0=$0000F8AB
Bit Test BTST #$F,D0 z ← ~(<bit number>) of destination Bit Set = test a bit then set BSET #3,NUM z ← ~(<bit number>) of destination <bit number> of destination ← 1 Bit Clear = test a bit then clear BCLR #8,D0 z ← ~(<bit number>) of destination <bit number> of destination ← 0 Bit Change = test a bit then toggle BCHG #1,NUM z ← ~(<bit number>) of destination <bit no> of dest ← ~<bit no> of dest * source operand could be Dn (contains bit position)
8
Utilization of Bits to Store Data - the case of 8 doors; 1 indicates door is open
DOORS DC.B $05 or DOORS DC.B % Is door 3 open? DOOR1 DC.B 1 DOOR2 DC.B 0 DOOR3 DC.B 1 DOOR4 DC.B 0 … DOOR8 DC.B 0
9
Set according to condition
used primarily to set/clear flags Scc = set a byte according to condition cc if (condition true) then destination ← $FF ; set to “true” else destination ← $00 ; set to “false” endif e.g. SEQ Flag … Flag DC.B $00
10
Note: Aliases are set elsewhere. We will see this code again later.
/***************************************************************/ /* 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 addx.l d1,d1 l1: dbf d2,l0 move.l RESULT,a0 move.l d0,RESULT_LO move.l d1,RESULT_HI rts } Note: Aliases are set elsewhere. We will see this code again later.
11
/***************************************************************/
/* 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 }
12
/***************************************************************/
/* 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 }
13
Reading, Expectations Reading: Expectations:
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.