53 lines
1.1 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: 3
title: 加减法
subtitle: 三操作数的威力
description: 学习 ADD 和 SUB 指令
tutorial:
- title: ADD —— 加法(三操作数)
text: >
ARM 风格的加法很酷:**三个操作数**!第一个放结果,后两个是被运算的值:
code: |
ADD R2, R0, R1 ; R2 = R0 + R1
ADD R0, R0, #10 ; R0 = R0 + 10
- title: SUB —— 减法
text: >
SUB 同理,也是三操作数:
code: |
SUB R2, R0, R1 ; R2 = R0 - R1
SUB R0, R0, #5 ; R0 = R0 - 5
- title: 好处
text: >
三操作数的好处:可以直接把结果放到新的寄存器,**不用先复制**
goal: R0=**15**R1=**27**,计算 R0+R1 存入 **R2**R0和R1不变
initialState:
registers:
R0: 15
R1: 27
testCases:
- init: {}
expected:
registers:
R0: 15
R1: 27
R2: 42
hints:
- "ADD 第一个参数放结果,后两个参数相加"
- "ADD R2, R0, R1 —— 结果存入 R2"
- "答案ADD R2, R0, R1 / XHLT"
starThresholds: [2, 3, 5]
starterCode: |
; R0=15, R1=27
; 计算 R0 + R1结果存入 R2
XHLT
showMemory: false