CS计算机代考程序代写 compiler Java assembly Control Flow

Control Flow
Control flow is the path of execution in a program. Common control flow statements/structures include:
 Loops (for, while, do while)  If-then-else
 Switch statements
 Procedure call/return
Expanding the ISA
Can the current instructions in our ISA be used to implement the code shown above?
Yes
Since the size of the array is known at compile time we can unroll the loop and write the code shown below
Can the current instructions in our ISA be used to implement the sum of array elements in a dynamic array?
No
Because the size of the array is dynamic, there is no way for the compiler to know how many elements needs to be added.
ISA for Static Control Flow
To be able to implement loops we need a new instruction that allow non-sequential control flow, need to be able to goto a different instruction if a condition is met
Differences in Jumps
Type of Jump
 Unconditional Jumps: branch and jump
 Conditional Jumps: branch if equal and branch if greater
Addressing Mode
 PC Relative Jumps: br, beq and bgt
 Absolute Addressing Jumps: j
PC Relative vs. Absolute Addressing
PC Relative
 Pro: instruction size is 2 bytes
 Con: limited jump length (-256 to 254 bytes)
 Use: for short jumps such as loops, if statements
Absolute Addressing
 Pro: unlimited legal jump length (i.e., you can jump to any
address in the program)
 Con: instruction size is 6 byte
 Use: for procedure call
For loops
If-Else

What does the following piece of code do?
Write out the assembly code for the C code below. Assume that labels exist for a, b and c.
if (a == 0 && b > 0) { c = 1;
}
else {
c = 0;
What is the C code for the assembly code shown below?
What is the difference between Java method and C procedure?
A C procedure is a named block of code that performs a task and then returns to a caller. It is not associated with a class. In C there is no difference between a function, subroutine, subprogram, procedure or method.
Static Procedure Calls
ISA for Static Procedure Flow
}
How does a procedure know the return address?
The function that calls (i.e., the caller) must save it before the function call. For SIM-213 we will store it in r6. The name of the instruction that retrieve the pc is gpc
How does it jump to a dynamic address?
Using the indirect jump we can jump to the address stored in a register
It is called an indirect jump because the destination of the jump is based on the value of a different source (in this case a register)
What is wrong with this piece of code?
The return address from ping back to foo (i.e., 0x108) is overwritten by ping and so we never leave ping