layout | titie |
---|---|
default |
Homework 07 - Programming on Bare Machine |
- Program with machine language according to the following c.
int_8 c = a + 3;
1. Write your assembly code & machine code.
Assembly Code:
```
LOD #1
STO A
LOD #3
ADD A
STO C
```
Machine Code:
```
00010100 00000001
00000101 10000000
00010100 00000011
00000000 10000000
00000101 10000001
```
2. Explain machine code execution with the fetch-decode-execute cycle
- Fetch: 首先 CPU 从内存中获取 Program Counter 对应的指令
- Decode:然后 Decoder 将指令进行解码,决定使用哪条路径来执行指令
- Execute:MUX 会根据指令内容(可选地)从内存获取数据,然后对应的电路执行指令
- 最后 Program Counter 自增
3. Explain functions about IR, PC, ACC registers in a CPU
- IR: 存放指令
- PC:存放下一条指令的地址
- ACC:存放 LOD、ADD 等指令的计算结果
4. Explain physical meaning about vars a & c in a machine
- 变量 a 与 c 通常是存放在内存中的一个数据
- 在需要使用时,通常需要先加载到 CPU 的寄存器中
-
Answer questions
-
What are stored in memory?
- Instructions & Data
-
Can a data or a instruction stored in the same place?
- It can.
-
Explain Instruction Format with example instructions.
ADD #1
- which equals to
00010000 00000001
- The first three 0 is preserved
- The fourth number
1
means the Operator is a number rather than an address of a data in memory - The 5th ~ 8th number represents the instruction: ADD
- The 9th ~ 16th number is the Operator, which is a number or an address of a data in memory
-
-
Assembly language
- An assembly (or assembler) language, often abbreviated asm, is any low-level programming language in which there is a very strong correspondence between the program's statements and the architecture's machine code instructions.
- 任何一种与某种计算机架构的机器码指令有强相关性的低级的编程语言,都可以称为汇编语言。
-
Compiler
- A compiler is computer software that primarily translates computer code from a high-level programming language to machine code to create an executable program. A compiler can also be used to convert computer code written in one programming language into another programming language. Technically compilers are a type of translator that support digital devices, primarily computers.
- 编译器是一种计算机软件,主要是将一种高级程序语言的代码翻译成机器码,以创建一个可执行程序。(有的)编译器也可以用于将一种高级程序语言的代码翻译成另外一种高级的语言的代码。从技术上而言,编译器是一种支持数字设备(尤其是计算机)的翻译器。
-
Imperative programming
- In computer science, imperative programming is a programming paradigm that uses statements that change a program's state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform. Imperative programming focuses on describing how a program operates.
- 在计算机科学中,命令式编程是一种“用语句改变一个程序的状态”的编程范式。就像自然语言表达祈使时的那种“祈使语气”一样,一个遵循命令式编程范式的程序是由一些交由计算机去执行的命令构成的。命令时编程注重于描述一个程序是如何运作的。
-
Functional programming
- In computer science, functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions or declarations instead of statements. In functional code, the output value of a function depends only on the arguments that are passed to the function, so calling a function f twice with the same value for an argument x produces the same result f(x) each time; this is in contrast to procedures depending on a local or global state, which may produce different results at different times when called with the same arguments but a different program state. Eliminating side effects, i.e., changes in state that do not depend on the function inputs, can make it much easier to understand and predict the behavior of a program, which is one of the key motivations for the development of functional programming.
- 在计算机科学中,函数式编程是一种编程范式,这种编程范式将计算视作数学函数的执行,并且力图避免改变状态与可变量的存在。在函数式代码中,一个函数的输出值只取决于被传入该函数的参数。所以以相同的参数 x 调用函数 f 两次,每次得到都的是相同的结果。这就区别于一些依赖于本地或者全局状态的过程,因为这些过程在不同时间被调用时,就算传入相同的参数,也可能会产生不同的结果。减少某些不依赖于函数输入的状态改变之类的边际效应,可以让程序的行为更容易被理解与预测。这就是函数式编程发展过程中的关键动力之一。
-
Procedural programming
- Procedural programming is a programming paradigm, derived from structured programming, based upon the concept of the procedure call. Procedures, also known as routines, subroutines, or functions, simply contain a series of computational steps to be carried out. Any given procedure might be called at any point during a program's execution, including by other procedures or itself. The first major procedural programming languages first appeared circa 1960, including Fortran, ALGOL, COBOL and BASIC. Pascal and C were published closer to the 1970s.
- 过程式编程是一种衍生于结构式编程、基于过程调用概念的编程范式。过程,通常也称作子程序、函数等,只包含一系列将被执行的计算操作。任何给定的过程可以在程序运行过程中的任何(时间)点被调用,包括被其他过程调用和被它本身调用。第一个主要的过程式编程语言大约在 1960 年出现,包括 Fortran, ALOGOL, COBOL 和 BASIC。Pascal 和 C 则在接近 1970 年代时被发布。