所屬科目:研究所、轉學考(插大)、學士後-計算機概論
1. Consider a simple imperative language called Bare Bones. It uses only the following four statements.
while name not 0 do; … end; While the value of name is not zero do … where name stands for a variable name. As an example, the following routine copies the value of X to Y with the side effect of destroying the value of X. Please write a Bare Bones routine that copies the value of X to Y without destroying X’s value. You are allowed to use an auxiliary variable Z (20%)
2. Show that the if-then-else structure can be simulated using Bare Bones. That is, write a program sequence in Bare Bones that simulates the action of the statement if X not 0 then S1 else S2; where S1 and S2 represent arbitrary statement sequences. You are allowed to use an auxiliary variable Y. (20%)
3. Show the correct order of the following activities that may arise in instruction execution cycle. (a) Fetch operands (b) Fetch (c) Execute (d) Store Result (e) Decode. (10%)
(a) How many negative integers can be represented by n bits using 2’s complement representation?
(b) Convert decimal number 522 to a 3-digit hexadecimal number. (10%)
5. Assume that C function power_of_two(n) returns 1 if n is a power of two and 0 otherwise. What is the return value when calling w(6,3), where function w is defined as follows. (20%)
6. AND, OR, NOT, and XOR are four logical operations that can be used to modify a bit pattern. Let X be a byte. (a) Show how to set (force to 1) the four rightmost bits of X by performing one of these operations on X and a specific bit pattern. (10%) (b) Show how to flip the three rightmost and the two leftmost bits of X by performing one of these operations on X and a specific bit pattern. (10%)