Logical Operations n n n bitwise logical operations
Logical Operations n n n bitwise logical operations AND, OR, EOR, NOT “mask” = setting specific bits to zero e. g. mask high four bits in NUM DC. B $4 C for bit operations, could mask out all the bits you are not interested in testing
Utilization of Bits to Store Data - the case of 8 doors; 1 indicates door is open DOORS or DOORS DC. B $05 DC. B %00000101 Are the even numbered doors closed? DOOR 1 DOOR 2 DOOR 3 DOOR 4 … DOOR 8 DC. B 1 0 DC. B 0 D 1 D 3 D 5 D 7 hallway D 2 D 4 D 6 D 8
Shift Operations n directions: left, right n types: logical, arithmetic, circular n length: 1 bit, > 1 bit n flags: Z, N, C, sometimes X
Shift Operations Right: Left: logical ≡ arithmetic logical ≠ arithmetic 0 C lsr X asl C lsl X 0 C X rol C roxl C asr X X C ror C roxr
Utilization of Bits to Store Data - the case of 8 doors; 1 indicates door is open DOORS or DOORS DC. B $05 DC. B %00000101 How many doors are open? DOOR 1 DOOR 2 DOOR 3 DOOR 4 … DOOR 8 DC. B 1 0 DC. B 0
Bit Operations instructions operate on one bit in Dn or memory n bit numbering: n Dn = (long) 31 … memory 7 6 5 4 3 2 1 0 (byte) 10
Bit Operations e. g. NUM 1 DC. B $A 2 D 0=$0000 F 8 AB 1. Bit Test BTST z ← ~(<bit number>) of destination 2. Bit Set = test a bit then set BSET #3, NUM z ← ~(<bit number>) of destination <bit number> of destination ← 1 3. Bit Clear = test a bit then clear BCLR #8, D 0 z ← ~(<bit number>) of destination <bit number> of destination ← 0 4. 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) #$F, D 0
Utilization of Bits to Store Data - the case of 8 doors; 1 indicates door is open DOORS or DOORS DC. B $05 DC. B %00000101 Is door 3 open? DOOR 1 DOOR 2 DOOR 3 DOOR 4 … DOOR 8 DC. B 1 0 DC. B 0
Set according to condition n n used primarily to set/clear flags Scc = set a byte according to condition cc if (condition true) then destination ← $FF else destination ← $00 endif e. g. Flag SEQ … DC. B Flag $00 ; set to “true” ; set to “false”
/********************************/ /* Purpose. . : Compute result = left << right */ /* Input. . : pointer to result */ /* Input. . : left operand */ /* Input. . : shift count */ /* Return. . . : pointer to result */ /********************************/ extern asm CInt 64* __rt_shl 64(CInt 64 *result, CInt 64 left, short count) { move. l LEFT_LO, d 0 move. l LEFT_HI, d 1 move. w SHIFT_COUNT, d 2 and. w #0 x 003 F, d 2 bra. s l 1 l 0: add. l d 0, d 0 addx. l d 1, d 1 l 1: dbf d 2, l 0 move. l RESULT, a 0 move. l d 0, RESULT_LO move. l d 1, RESULT_HI 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 CInt 64* __rt_shrs 64(CInt 64 *result, CInt 64 left, short count) { move. l LEFT_LO, d 0 move. l LEFT_HI, d 1 move. w SHIFT_COUNT, d 2 and. w #0 x 003 F, d 2 bra. s l 1 l 0: lsr. l #1, d 0 asr. l #1, d 1 bcc. s l 1 bset #31, d 0 l 1: dbf d 2, l 0 move. l RESULT, a 0 move. l d 0, RESULT_LO move. l d 1, 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 CInt 64* __rt_rotl 64(CInt 64 *result, CInt 64 left, short count) { move. l LEFT_LO, d 0 move. l LEFT_HI, d 1 move. w SHIFT_COUNT, d 2 and. w #0 x 003 F, d 2 bra. s l 1 l 0: add. l d 0, d 0 addx. l d 1, d 1 bcc. s l 1 addq. w #1, d 0 l 1: dbf d 2, l 0 move. l RESULT, a 0 move. l d 0, RESULT_LO move. l d 1, RESULT_HI rts }
Reading, Expectations Reading: n n M 68000 Assembly Language [pdf, 92 p; N. Znotinas] ¨ review operation of instructions covered in presentation examples were taken from the Palm. OS 64 bit arithmetic library, Long 68 K. c Expectations: n n 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 Palm. OS 64 bit arithmetic library
- Slides: 13