1 / 13

Logical Operations

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.

mdowning
Download Presentation

Logical Operations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Logical Operations • bitwise logical operations • AND, OR, EOR, NOT • “mask” = setting specific bits to zero • e.g. mask high four bits in NUMNUM 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 $05or DOORS DC.B %00000101Are the even numbered doors closed? DOOR1 DC.B 1DOOR2 DC.B 0DOOR3 DC.B 1DOOR4 DC.B 0…DOOR8 DC.B 0 D1D3 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. Left: logical ≡ arithmetic Right: logical ≠ arithmetic Shift Operations 0 lsr C X asllsl C 0 C asr X X rol C ror C X X roxr C roxl C

  5. Utilization of Bits to Store Data- the case of 8 doors; 1 indicates door is open DOORS DC.B $05or DOORS DC.B %00000101How many doors are open? DOOR1 DC.B 1DOOR2 DC.B 0DOOR3 DC.B 1DOOR4 DC.B 0…DOOR8 DC.B 0

  6. Bit Operations • instructions operate on one bit in Dn or memory • bit numbering: Dn = (long) 31 … 1 0 memory 7 6 5 4 3 2 1 0 (byte)

  7. e.g. NUM1 DC.B $A2 D0=$0000F8AB Bit Operations • 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 $05or DOORS DC.B %00000101Is door 3 open? DOOR1 DC.B 1DOOR2 DC.B 0DOOR3 DC.B 1DOOR4 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. /***************************************************************/ /* 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: • 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

More Related