---
# System prepended metadata

title: Assembly midterm
tags: [Assembly]

---

Assembly midterm
================
###### tags: `Assembly`

![](https://i.imgur.com/gp4bWU3.jpg)
```
1. R13 : 堆疊指標 R14：連結暫存器(Link Register)  R15：程式計數器(Program Counter)

2. 有兩種指令1.正常指令下尾巴帶有S的 2.跟比較有關的指令 Answer: BCF

3. r0 = r1 and ~(r2)
-> 0xFF and 0xFC = 0xFC

4. r0 = 0x26 r8 = 0x23  r3 = 0x100

5. (1) 0x100 (2) 0x104 (3) 0x108

6. (1) 0x03 (2) 0xFFFFFC06 (3) 0xFF03FC06

7. MOV r0 , #0x10; = ADD r0 , #0x10, #0; 
   程式可讀性較高
   
8.
 ADD r1 , #0 , #0
 SUB r1 , #0 , #0
 STR  #0 , [r1]
 MUL r1, #0, #r2
```

![](https://i.imgur.com/TFyZvGN.jpg)

```
9. 
(a) 
CMP r0 , #0
BGE LABEL
SUB r0, #0 , r0
LABEL:
ADD r1 , r0 , #0
(b)
CMP r0 , #0
SUBLT  r0 , #0 , r0
ADD r1 , #0 , r0

10.
(1). r0=0xFE1F1020 r1=0xAD1C3620 r2=FF112233 r5=0x108
(2). r0=0x20101FFE r1=0x20361CAD r2=FF112233 r5=0x104
(3). r0=0xAD1C3620 r2=0xFE1F1020 r3=0x110
(4). [0x10C]=0x33 [0x10D]=0x22 [0x110]=0x10 [0x111]=0x01
```

![](https://i.imgur.com/ctwVGB3.png)

1.
> 有比較關係或者指令結尾有s
> _Ans_ (B.)(C.)(E.)
> [name=張聖岳][time=Mon, Nov 4, 2019 10:40 AM]


2.
> B
> [name=張聖岳][time=Tue, Nov 5, 2019 2:49 AM]

3.
> (1) 
> | r1 | r3 |
> |:--:|:--:|
> |0xFFFFFF00+mem~8~[0x204]|0x200|
> (2) 
> | r1 | r3 |
> |:--:|:--:|
> |mem~32~[0x200]|0x204|
> (3) 
> | r1 | r3 |
> |:--:|:--:|
> |mem~16~[0x200]|0x208|
> [name=張聖岳][time=Tue, Nov 5, 2019 2:51 AM]

4.
> (1) 0xFFFFFF06
> (2) 0xFFFFFC06
> (3) 0xFF03FC06
> (4) 0x06
> [name=張聖岳][time=Tue, Nov 5, 2019 2:54 AM]

5.
> (1) 0x06
> (2) 0x06FC
> (3) 0x06FC03FF
> (4) 0x06
> [name=張聖岳][time=Tue, Nov 5, 2019 2:56 AM]

6.
> MOV r1, #8 (=ADD r1, #8, #0)
> 簡化程式碼，增加可讀性
> [name=張聖岳][time=Tue, Nov 5, 2019 2:57 AM]

7.
> 1. MOV r1, r1,LSR #32
> 2. MOV r1, r1,LSL #32
> 3. MOV r1, #0
> 4. ADD r1, #0, #0
> 
> [name=張聖岳][time=Tue, Nov 5, 2019 3:00 AM]

8.
> ```arm=
> ADD r1, r0, r0, ASR #31
> EOR r0, r1, r0, ASR #31
> MOV r1, r0
> ```
> [name=張聖岳][time=Tue, Nov 5, 2019 3:22 AM]


![](https://i.imgur.com/wCrFAbd.png)

9.
> (a.)
> ```arm=
>     CMP r0, r1
>     BGT METHOD1
>     CMP r2, r3
>     BEQ METHOD1
>     ADD r0, r0, r1
> METHOD1:
> ```
> (b.)
> ```arm=
> CMP r0, r1
> CMPGT r2, r3
> ADDEQ r0, r0, r1
> ```

10.
(1)
> | r0 | r1 | r2 | r5 |
> |:--:|:--:|:--:|:--:|
> |0x1C3620FE|0x9FC011AD|0xFF112233|0x10C|
> [name=張聖岳][time=Tue, Nov 5, 2019 10:36 AM] 

(2)
> | r0 | r1 | r2 | r5 |
> |:--:|:--:|:--:|:--:|
> |0xFE20361C|0xAD11C09F|0xFF112233|0x104|
> [name=張聖岳][time=Tue, Nov 5, 2019 10:41 AM]

(3)
> | r0 | r1 | r2 | r7 |
> |:--:|:--:|:--:|:--:|
> |0x20FE1F10|0x11AD1C36|0x53699FC0|0x104|
> [name=張聖岳][time=Tue, Nov 5, 2019 10:46 AM]

(4)
> |0x10C|0x108|0x105|0x101|
> |:--:|:--:|:--:|:--:|
> |0x10|0xFF|0x33|0x76|
> [name=張聖岳][time=Tue, Nov 5, 2019 10:51 AM]
