Files
simpleasm/frontend/src/lib/levels/06.yaml

54 lines
1.2 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
id: 6
title: 移位操作
subtitle: 位的舞蹈
description: 学习 LSL 和 LSR 指令
tutorial:
- title: LSL —— 逻辑左移
text: >
所有位向左移右边补0。**左移1位 = 乘以2**左移3位 = 乘以8
code: |
; 5 = 00000101
LSL R0, R0, #1 ; 00001010 = 10 (×2)
LSL R0, R0, #1 ; 00010100 = 20 (×2)
- title: LSR —— 逻辑右移
text: >
所有位向右移左边补0。**右移1位 = 除以2**
code: |
MOV R0, #40
LSR R0, R0, #1 ; 20 (÷2)
LSR R0, R0, #2 ; 5 (÷4)
- title: 程序员的技巧
text: >
在真实的 ARM 处理器中,移位比乘除快得多!
`LSL R0, R0, #3` 比 `MUL R0, R0, #8` 高效。
goal: R0 = **5**,只用**移位操作**把它变成 **40**40 = 5 × 8 = 5 ×
initialState:
registers:
R0: 5
testCases:
- init: {}
expected:
registers:
R0: 40
hints:
- "8 = 2³乘以8就是左移3位"
- "LSL R0, R0, #3"
- "就这一条指令!"
starThresholds: [2, 3, 5]
blockedOps: [MUL, DIV]
starterCode: |
; R0 = 5
; 用 LSL 让 R0 变成 40不能用 MUL
HLT
showMemory: false