https://hackmd.io/@IMOK/Lab5
講師: 賴昱有
通常組成形式為
LOAD R0, [0x60]
LOAD R1, [0x61]
ADDI R2, R0, R1
STORE R2, [0x62]
HALT
將記憶體 60 中的值 load 到 Register R0 中
將記憶體 61 中的值 load 到 Register R1 中
將 Register R0 及 R1 整數相加後存到 Register R2 中
將 Register R2 的值存回記憶體 62 中
停止
address of next instruction
current instruction
指令表
僅限於今天會使用到的模擬軟體
實際上的組合語言會有多種不同指令集
R, S, T 皆代表 Register
指令 | 解釋 |
---|---|
LOAD R, [0xXY] | 將記憶體 XY 中的值填入 Register R |
LOAD R, XY | 將值 XY 填入 Register R |
STORE R, [0xXY] | 將 Register R 的值存入記憶體 XY 中 |
MOVE S, R | 將 Register R 的值存入 Register S 中 |
ADDI R, S, T | 將 Register S 及 T 整數相加後存到 Register R 中 |
ADDF R, S, T | 將 Register S 及 T 浮點數相加後存到 Register R 中 |
OR R, S, T | 將 Register S 及 T 做 OR 後存到 Register R 中 |
AND R, S, T | 將 Register S 及 T 做 AND 後存到 Register R 中 |
XOR R, S, T | 將 Register S 及 T 做 XOR 後存到 Register R 中 |
ROR R, X | 將 Register R 中的值 Rotate X 次 |
指令 | 解釋 |
---|---|
JMPEQ R=R0, F | 若 Register R 等於 Register R0 將程式跳到 Flag F |
HALT | 停止 |
LOAD R, [S] | 將 Register S 中的值作為記憶體位址並將其中的值填入 Register R e.g. S 中值為 65 就將記憶體 65 中的值填入 R |
STORE R, [S] | 將 Register S 中的值作為記憶體位址並將 Register R 的值填入其中 e.g. S 中值為 65 就將 R 中的值填入記憶體 65 |
JMPLE R<=R0, XY | 若 Register R 小於等於 Register R0 將程式跳到 Flag F |
JMP F | 將程式跳到 Flag F |
DB F | Define Byte |
if(...)
do something
else
do another thing
main:
LOAD R0, [0x60]
LOAD R1, [0x61]
JMPEQ R1=R0, equal
JMP noteq
equal:
LOAD R2, [0x62]
ADDI R3, R1, R2
STORE R3, [0x70]
HALT
noteq:
LOAD R2, [0x63]
ADDI R3, R1, R2
STORE R3, [0x70]
HALT
for(int a = 0; a < 10; a++)
do something
main:
LOAD R0, [0x60]
LOAD R1, 1
LOAD R2, 1
JMP loop
loop:
ADDI R1, R1, R2
JMPLE R1<=R0, loop
JMP out
out:
HALT
作業做完請上傳到 http://140.121.197.13/tutorial
並且注意上傳時間限制、檔名、其他規範
上課時提前做完可以直接給助教 demo 登記
就不需要上傳 demo 過的部分
Write a program to swap the values of memory location of
Fill in the values
load R5, [0x6C]; Load the value of memory address 0x6C into R5
load R6, [0x6D]; Load the value of memory address 0x6D into R6
addi R0, R5, R6; Adds the value of R5 and R6 and store i t in R0
store R0, [0x6E]; Stores the value of R0 to memory address 0x6E
halt
hint : bubble sort
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing