CPSC 213 – Assignment 6
Static Control Flow
Due: Monday, February 20, 2017 at 11:59pm (with grace period, Tuesday 9am)
After an 9-hour, no-penalty, grace period, no late assignments accepted.
Goal
This assignment ha
...
CPSC 213 – Assignment 6
Static Control Flow
Due: Monday, February 20, 2017 at 11:59pm (with grace period, Tuesday 9am)
After an 9-hour, no-penalty, grace period, no late assignments accepted.
Goal
This assignment has three parts.
First, you will extend the SM213 implementation to add the instructions we have discussed in
class that support static control flow, including static procedure calls and procedure return (which
is dynamic, actually).
Second, you’ll examine the assembly code for for-loops and if-statements using snippet files in the
simulator and then translate a simple C file containing these control-follow statements into
assembly.
Finally, you will write a fairly substantial assembly-language program that uses all of the language
concepts we have discussed so far.
Question 1: Extending the ISA [20%]
Implement the following six control-flow instructions in CPU.java. The code provided with this
assignment in www.ugrad.cs.ubc.ca/~cs213/cur/assignments/a6/code.zip includes the file
CPU.java that you can use as the starting point for this assignment. Alternatively you can use the
version you implemented yourself for Assignment 2.
Note that in the “Format” column below, capital letters are hex digit literals and lower-case letters
represent hex values referenced in the “Assembly” and “Semantics” columns.
Instruction Assembly Format Semantics
branch br A 8-pp pc ← (A = pc + pp*2)
branch if equal beq rc, A 9cpp pc ← (A = pc + pp*2) if r[c]==0
branch if greater bgt rc, A Acpp pc ← (A = pc + pp*2) if r[c]>0
jump j A B--- AAAAAAAA pc ← A
get pc gpc $o, rd 6Fpd r[d] ← pc + (o == p*2)
indirect jump j o(rt) Ctpp pc ← r[t] + (o == pp*2)
This study source was downloaded by 100000904123021 from CourseHero.com on 03-01-2026 04:59:23 GMT -06:00
https://www.coursehero.com/file/21020242/a6-3/
Note that the indirect-jump offset is unsigned and so for indirect jump, pp ranges from 0 to 255.
On the other hand, the branch pc-relative value is signed and so for branches, pp ranges from
-128 to 127.
Test your implementation by creating a file named test.s that contains tests for each of the new
instructions.
Question 2: Assembly code of if and loops [10%]
Example the Execution of Assembly Snippets
[Show More]