第4章アルゴリズムの言語による実現:低水準プログラミング言語
Conceptual Questions概念を考える問題
1. Why are low-level languages like assembly language not portable?
1. アセンブリ言語のような低水準言語に、移植性がないのはなぜか。
2. Why do multiple computational models exist? Why don’t we just use one model for everything?
2. なぜ複数の計算モデルがあるのか。あらゆることに1つのモデルだけを使わないのはなぜか。
3. What are some disadvantages with structured programming languages like C?
3. Cのような構造化プログラミング言語には、どのような欠点があるか。
4. Why does the execution speed of software matter? Describe a scenario where slow execution speed would impact a computer user negatively.
英語のヒント
4. ソフトウェアの実行速度が重要なのはなぜか。実行速度の遅さがコンピューターユーザーに悪影響を与える場面を説明しなさい。
5. What is an advantage of low-level programming over high-level programming?
5. 高水準プログラミングと比べた、低水準プログラミングの利点は何か。
6. What is the best way to use GOTO in the structured paradigm?
6. 構造化のパラダイムで、GOTOを使う最善の方法は何か。
7. For each of the following programming languages: investigate the language. Is the language low-level, middle-level, or high-level? Which of the paradigms covered in this section apply to the language (imperative, declarative, functional, structured, procedural, object-oriented)? Cite your sources.
英語のヒント
7. 次の各プログラミング言語を調べなさい。その言語は低水準、中水準、高水準のどれか。この節で扱ったパラダイム(命令型、宣言型、関数型、構造化、手続き型、オブジェクト指向)のうち、どれが当てはまるか。出典を示しなさい。
◦ Fortran
◦ Fortran
◦ Haskell
◦ Haskell
◦ Smalltalk
◦ Smalltalk
8. What is the output of the following C program, and what is the program’s purpose here?
8. 次のCプログラムは何を出力し、ここでの目的は何か。
#include <stdio.h>
int main() {
int a=10;
int *b=&a;
printf("%d", b);
printf("\n");
printf("%d", &a);
printf("\n");
printf("%d",*b);
return 0;
}9. What is the output of the following C program, and what is the program’s purpose here?
9. 次のCプログラムは何を出力し、ここでの目的は何か。
#include <stdio.h>
int main() {
int arr[2][3] = { 10, 20, 30, 40, 50, 60 };
printf("Array:\n");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ",arr[i][j]);
}
printf("\n");
}
return 0;
}10. Compare and contrast static linking of a program with dynamic load-time linking. What are the advantages and challenges of each?
英語のヒント
10. プログラムの静的リンクと、ロード時の動的リンクを比較し、共通点と相違点を示しなさい。それぞれの利点と課題は何か。
11. Compare and contrast dynamic load-time linking of a program with dynamic run-time linking. What are the advantages and challenges of each?
11. プログラムのロード時の動的リンクと、実行時の動的リンクを比較し、共通点と相違点を示しなさい。それぞれの利点と課題は何か。
12. Non-parallel programs work, and parallel programming can be difficult. Why is it important for programmers to make the effort to make their programs parallel? Why not stick with non-parallel programming?
英語のヒント
12. 並列でないプログラムでも動作し、並列プログラミングは難しい場合がある。プログラマーが努力してプログラムを並列化することは、なぜ重要なのか。並列でないプログラミングを続けるだけではいけないのはなぜか。
13. Why is it difficult for developers to use the multi-threaded programming paradigm in order to fully utilize the capabilities of today’s available multicore processors?
13. 現在利用できるマルチコアプロセッサーの能力を十分に活用するために、開発者がマルチスレッドのプログラミングパラダイムを使うのは、なぜ難しいのか。
14. Do you need to know how to assemble hardware and draw schematics to implement firmware for embedded systems?
英語のヒント
14. 組込みシステムのファームウェアを実装するためには、ハードウェアの組立て方や回路図の描き方を知る必要があるか。
Practice Exercises練習問題
Exercises 1–5練習問題 1–5
1. List three pros or cons about each level of language in terms of execution time, complexity, readability, abstraction, and speed of development.
英語のヒント
1. 実行時間、複雑さ、可読性、抽象化、開発速度の観点から、各水準の言語について、長所または短所を3つ挙げなさい。
2. Write 8086 assembly code to add the values 1 and 3 together. The registers
abx and cdx are available to use for this operation and the result should be stored in abx.2. 値1と3を足す8086アセンブリコードを書きなさい。この操作にはレジスターabxとcdxを使え、結果はabxに格納するものとする。
3. Write a main function in C that calls another function to add the numbers 1 and 3 together and return the sum as an output parameter. Finally, print out the answer to the console.
英語のヒント
3. 別の関数を呼んで数1と3を加え、その和を出力パラメーターとして返す、Cのmain関数を書きなさい。最後に、答えをコンソールへ表示しなさい。
4. Write a main method in Java that calls another method to add the numbers 1 and 3 together and then print out the answer to the console.
4. 別のメソッドを呼んで数1と3を加え、その後答えをコンソールへ表示する、Javaのmainメソッドを書きなさい。
5. Write the GCC commands to compile file1.c, file2.c and file3.c and then link the object files to create a static library titled myLib.
5. file1.c、file2.c、file3.cをコンパイルし、その後オブジェクトファイルをリンクしてmyLibという静的ライブラリーを作る、GCCコマンドを書きなさい。
Exercises 6–10練習問題 6–10
6. Write a main function in C that calls a public function titled
PrintList() in a module titled listOperations.6. listOperationsというモジュール内の、PrintList()という公開関数を呼ぶ、Cのmain関数を書きなさい。
7. Write a C module that includes 2 global integer variables declared in the file titled
variables.h and then print the global variables in a main function that exists in main.c.7. variables.hというファイルで宣言した、整数のグローバル変数2つを含むCモジュールを書き、main.cにあるmain関数で、そのグローバル変数を表示しなさい。
8. Write a Git command to pull changes from a repository on your local host machine with the URL “https://localhost/MyRepository” into your working repository checkout.
8. ローカルのホストマシン上にある、URLが「https://localhost/MyRepository」のリポジトリーから、自分の作業用リポジトリーのチェックアウトへ変更を取得する、Gitコマンドを書きなさい。
9. Write a GCC command to compile a C file titled
main.c that includes a static library titled myStaticLib.9. myStaticLibという静的ライブラリーを含むmain.cというCファイルをコンパイルする、GCCコマンドを書きなさい。
10. Trace the following C code and list the contents of the array after the iteration.
英語のヒント
10. 次のCコードの動作を追い、反復後の配列の内容を列挙しなさい。
int main() {
int List[5];
int a = 10;
for (int i = 0; i < 5; i++)
{
List[i] = a + i;
}
return 0;
}Exercises 11–12練習問題 11–12
11. The following is a C “hello world” program that uses OpenMP. How many lines of messages will this program generate at runtime?
11. 次はOpenMPを使う、Cの「hello world」プログラムである。このプログラムは、実行時に何行のメッセージを生成するか。
#include
int main() {
int x = 1;
int y = x + 2;
#pragma omp parallel num_threads(y * 3)
{
printf("https://helloacm.com\n");
}
return 0;
}12. Write a C module that creates four threads to call a function that prints the thread number out.
12. スレッドを4つ作り、スレッド番号を表示する関数を呼び出すCモジュールを書きなさい。