---
# System prepended metadata

title: Lab1 Note
tags: [NCTU, MPSL]

---

# Lab1 Note

###### tags: `NCTU` `MPSL`

### Question 實驗課問題

#### Question 1 (for lab 3-1):  
- **What is the IT-block for ARM Assembly? ARM 組合語言中的 IT-block 指的是甚麽？**

    The `IT` (If-Then) instruction makes up to four following instructions (the *IT block*) conditional. The conditions can be all the same, or some of them can be the logical inverse of the others.

    With IT instruction, you can specify condition code for up to 4 instructions. For each instruction, you specify if it's part of the If (T) or Else (E).

    #### For example:

    ```c
    ITTET EQ
    ADD r0,r0,r0
    ADD r1,r0,r0
    ADD r2,r0,r0
    ADD r3,r0,r0
    ```

    #### Will actually translate to:

    ```c
    ADDEQ r0,r0,r0  (Always if for 1st one)
    ADDEQ r1,r0,r0  (T for 2nd one)
    ADDNE r2,r0,r0  (E for 3rd one)
    ADDEQ r3,r0,r0  (T for 4th one)
    ```

      #### APSR - Application Program Status Register ( N Z C V ) 

- **What are the condition code suffixes of ARM instruction? ARM 指令的條件碼後綴是什麼？**

        ADDS、LDRB、BEQ、BVS

- **What is the difference between instruction ADD and ADDS?  指令ADD與ADDS之間有何差別？**

        ADD是一般的加法，ADDS會更新N, Z, C and V 4個 flags

#### Question 2 (for lab 3-2):

- **How to detect overflow by software? That is, using an algorithm or logical operation to detect overflow. 
    如何通過軟體檢測溢位？即使用演算法或是邏輯判斷的方式偵測溢位。**

    ```
    BVS 、 Signed bit
    ```

- **Question 3 (for lab 3-2): Does ARMv7-M provide any hardware support on overflow detection?
    ARMv7-M 是否在溢出檢測方面提供任何硬體支持？**

    ```
    V flag 
    ```

### Demo Question

#### **Question (3-1)**

>請使用 asm code 回答下述問題

1. **請說明如何計算變數 X, Y 之間的漢明距離，如何統計有幾個相異的 bits?**
         ```
        eor (xor) 然後計算有幾個1        
        ```
2. 請說明程式是如何從 hamm 函數跳回到 main 函數中

    ```
    bl hamm 在branch的同時將下筆指令的address存在LR暫存器，
    bx lr 即可跳回來。
    ```

---

#### **Question (3-2)**

> 請說明實作方式或以 asm code 回答下述問題

1. 請說明程式是如何計算 Fn

    ```R3 = R1 + R2 ...```

2. 請說明如何判斷 N 值是否超出範圍 (100<N or N<0)

    ```用 cmp    ```

---