| English | 의미 |
|---|---|
| bit/bɪt/ | 비트 |
| mask/mæsk/ | 마스크 |
| logical shift/ˈlɒdʒɪkl ʃɪft/ | 논리 시프트 |
| sign bit/saɪn bɪt/ | 부호 비트 |
| arithmetic right shift/ˌærɪθˈmetɪk raɪt ʃɪft/ | 산술 우회전 |
| cyclic shift/ˈsaɪklɪk ʃɪft/ | 순환 시프트 |
Multiplying on a chip that cannot multiply
- The processor in the 1989 Game Boy had no multiply instruction at all. Every score, every coordinate that needed doubling was doubled by sliding its bits one place to the left.
- A shift takes one clock tick. Multiplication built from shifts and additions is how those games ran on a few kilobytes and a handful of milliwatts.
- The same tricks control single wires in an embedded device: one bit of a register per sensor or actuator, tested and set with a mask 掩码.
- This lesson is the three kinds of shift and the four mask operations, in the exam's own instructions.
Logical shifts
- A logical shift 逻辑移位 moves every bit left or right by some places and fills the vacated positions with 0.
LSL #1moves the bits left and a 0 enters on the right: for an unsigned number that is × 2.LSR #1moves them right and a 0 enters on the left: integer ÷ 2.- Shifting by $n$ places multiplies or divides by $2^{n}$.
00001011(11) afterLSL #1is00010110(22); afterLSR #1it is00000101(5, the remainder lost).

Logical left (× 2), logical right (÷ 2) and arithmetic right (keeps the sign bit)
바이트의 비트를 이동하고 마스크로 선택한다
연산자를 선택하고 각 결과 비트를 확인하라. 왼쪽 이동(<<) moves every bit up one place (×2); a right shift (>>)은 값을 아래로 내린다(÷2); mask와 AND 연산으로 원치 않는 비트를 지운다.
8비트 값 00001011 (11)을 1만큼 왼쪽 이동하면(LSL #1), 새로운 진수 값은?
난이도 2/5 · 140 코인 + 오늘 첫 완료 시 소액 보너스
1만큼 왼쪽 이동하면 2배가 되므로: $11 \times 2 = 22$ (00010110).
부호 없는 수를 3자리 왼쪽 이동하면 몇 배가 되는가?
난이도 2/5 · 140 코인 + 오늘 첫 완료 시 소액 보너스
$n$자리 이동하면 $2^n$배가 되므로, 3자리 이동하면 $2^3 = 8$배가 된다.
Worked example: when × 4 stops being true
- Bits shifted off the end are lost, so the multiplication is only correct while they were zeros.
LSL #2on the two's complement byte11001010gives00101000. The two 1s that fell off the left are gone, the sign bit has changed, and the result is no longer four times the original.LSL #2on00001011(11) gives00101100(44), which is correct, because only zeros were lost.- The exam asks for both: the shifted pattern, and a comment on whether the value is still right.
Arithmetic right shift
- A plain logical right shift puts a 0 in the top bit, which would turn a negative two's complement number positive.
- An arithmetic right shift 算术右移 copies the sign bit 符号位 into each vacated place, so a negative number stays negative and the shift still divides by 2.
10011110shifted arithmetically right by 3 places is11110011;01011100gives00001011.

Logical and arithmetic right shift on the same byte: only the entering bit differs
산술 오른쪽 이동과 논리적 오른쪽 이동의 차이는 다음과 같다:
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
부호 비트를 보존하므로, 부호가 있는 음수를 2의 거듭제곱으로 나누어도 여전히 음수가 된다.
논리적 오른쪽 이동은 항상 최상위 비트에 0을 넣으므로, 부호가 있는 음수를 양수로 만들 수 있다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
부호 있는 나눗셈이 산술 오른쪽 이동을 사용하는 정확한 이유이다. 이는 부호 비트를 복사하기 때문이다.
10011110을 3자리 오른쪽 산술 이동하면 8비트 패턴 ____이 된다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
왼쪽에 빈 3개 위치는 부호 비트 1의 복사본으로 채워지고, 오른쪽 끝 3개 비트 110은 사라진다.
Cyclic shifts
- A cyclic shift 循环移位, or rotate, feeds the bit that drops off one end back in at the other end, so no bits are lost.
- A cyclic left shift of 1 on
10000110gives00001101: the leading 1 reappears on the right. - Logical shifts fill with zeros, arithmetic shifts fill with the sign bit, cyclic shifts fill with the bit that left. That is the whole difference between the three.
10000110에 1자리 순환 왼쪽 이동을 적용하면 결과는?
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
최상위 1이 왼쪽으로 빠져나와 오른쪽으로 다시 들어오므로 비트가 잃어지지 않는다. 00001100은 논리적 이동이었다면 resultant이一样了。
Worked example: 240 or minus 16?
- Take
11110000. Read as unsigned it is 240; read as two's complement it is −16. LSR #1brings in a 0 and gives01111000= 120, the correct half of 240.ASR #1copies the sign bit and gives11111000= −8, the correct half of −16.- Neither is wrong. Each halves the value under one reading, which is why a processor needs both instructions.
바이트 11110000에 대한 다음 중 올바른 설명은? 모두 선택하시오.
난이도 2/5 · 140 코인 + 오늘 첫 완료 시 소액 보너스
두 결과의 차이는 왼쪽으로 들어오는 비트 뿐이다: 논리적 이동은 0, 산술 이동은 부호 비트이다.
Bit masking
- Embedded devices often use one bit 位 of a register per signal. A mask is a pattern combined with the register so that only the chosen bit changes.
- Set bit $n$:
ORwith a mask that has a 1 in position $n$. Clear bit $n$:ANDwith a mask that has a 0 there and 1s everywhere else. - Toggle bit $n$:
XORwith a mask that has a 1 there. Test bit $n$:ANDwith that mask, thenCMP #0: not equal means the bit was set.

Set with OR, clear with AND, toggle with XOR, each using a mask
각 비트 연산을 수행하는 비트 위 연산자(및 mask)와 매칭하시오.
난이도 2/5 · 140 코인 + 오늘 첫 완료 시 소액 보너스
OR는 설정하고, AND는 clear하며, XOR은 toggle하고, AND + 0이 아닌 테스트는 비트를 읽는다 — 네 가지 masking 방법이다.
특정 비트를 1로 set하려면 레지스터와 mask를 다음 연산자로 결합해야 한다:
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
해당 비트가 1인 mask와 OR 연산은 해당 비트를 1로 강제하고 나머지는 unchanged한다.
Worked example: the instructions on one byte
- The ACC holds
10101100. The mask may be written#ndenary,Bnbinary or&nhexadecimal. AND B00001111gives00001100: only the low four bits survive.OR #1gives10101101: the least significant bit is set and nothing else moves.XOR &FFgives01010011: every bit inverted.AND B00001000thenCMP #0tests bit 3; the result00001000is not zero, so bit 3 was set.LSL #2gives10110000, losing the top two bits;LSR #3gives00010101.
ACC의 least significant bit를 1로 set하고 나머지 비트는 unchanged하는 지시어는 OR ____이다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
마지막 자리에만 1이 있는 mask와 OR 연산. 진수 #1, 이진 B00000001, hex &1은 동일한 mask이다.
ACC의 bit 3이 set되었는지 테스트하는 단계를 순서대로 배치하시오.
난이도 3/5 · 200 코인 + 오늘 첫 완료 시 소액 보너스
Mask, compare, jump. AND 연산은 00001000 또는 00000000을 남기고, 0과의 비교로 이를 구분한다.
Monitoring and control, one bit at a time
- In a monitoring device one bit of a register per sensor means a single
ANDchecks whether a particular sensor is on. - In a control device one
ORswitches an actuator's control bit on without disturbing the others, and oneANDswitches it off. - It is fast, it uses almost no memory, and one byte holds eight independent on/off states. That is the "why" the exam asks for.
Marks that slip away
- A left shift is × 2 per place only while the bits that fall off are zeros. Say so when a 1 is lost.
- A logical right shift brings in 0; an arithmetic right shift copies the sign bit. Choose by whether the number is signed.
- To clear a bit the mask needs a 0 at that bit and 1s everywhere else. A mask of all zeros clears the whole register.
XORtoggles; it does not set. To set useOR, to test useANDand compare with zero.
You've got it
- logical shift fills with 0: left × 2 per place, right ÷ 2, and lost 1s break the arithmetic
- arithmetic right shift copies the sign bit; a cyclic shift wraps the bit round
- masks: OR sets · AND clears · XOR toggles · AND then CMP #0 tests
- one bit per sensor or actuator makes monitoring and control fast and tiny; masks are written
#n,Bnor&n