Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
LiPtP0000 committed Oct 30, 2024
1 parent fc8eae9 commit 0a8e325
Showing 1 changed file with 80 additions and 3 deletions.
83 changes: 80 additions & 3 deletions _posts/2024-10-30-coa-three.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,17 @@ LOAD A <-> AC <- A

### 0-address instructions

Use a stack to find the operands. See the example of c=a+b below:
Use a stack to find the operands. See the example of c=a-b below:

```
```asm
push a
push b
add // pop a and b from stack and add them, push the result to stack
sub ; pop a and b from stack and add them, push the result to stack
pop c
```

The operation command find the operands from the top of the stack. And the first operand is below the second operand.

## Instruction set design

## Reverse Polish Notes
Expand All @@ -147,6 +149,81 @@ pop c

**Answer:**

- For zero address instructions:

```asm
PUSH B
PUSH C
MUL
PUSH A
ADD
PUSH D
PUSH E
PUSH F
MUL
SUB
DIV
```

- For one address instructions:

```asm
LOAD B ; Load B into register
MUL C
STORE TEMP1 ; Store the result of multiplication in TEMP1 register
LOAD A
ADD TEMP1
STORE TEMP2
LOAD E
MUL F
STORE TEMP3
LOAD D
SUB TEMP3
STORE TEMP4
LOAD TEMP2
DIV TEMP4
STORE RESULT
```

- For two address instructions:

```asm
MOVE R1, B ; Load B into reg R1
MUL R1, C ; R1 = B * C
MOV R2, A ; Load A into reg R2
ADD R2, R1 ; R2 = A + (B * C)
MOVE R3, E
MUL R3, F ; R3 = E * F
MOVE R4, D
SUB R4, R3 ; R4 = D - (E * F)
DIV R2, R4 ; R2 = (A + B * C) / (D - E * F)
MOVE RESULT, R2
```

- For three address instructions:

```asm
MUL R1, B, C ; R1 = B * C
ADD R2, A, R1 ; R2 = A + (B * C)
MUL R3, E, F ; R3 = E * F
SUB R4, D, R3 ; R4 = D - (E * F)
DIV RESULT, R2, R4 ; RESULT = (A + B * C) / (D - E * F)
```

**Question 12.18:**
<br/>
![Question 12.18 ](/assets/img/COA-images/homework/12-18.png){: .mx-auto.d-block :}
Expand Down

0 comments on commit 0a8e325

Please sign in to comment.