homework07
1、Program with machine language according to the following c.
int_8 a = 1;
int_8 c = a + 3;
1)Write your assembly code & machine code
LOD #1
STO X
LOD X
ADD #3
STO Y
HLT
2)Explain machine code execution with the fetch-decode-execute cycle
• Fetch the next instruction
• Decode the instruction
• Get data if needed
• Execute the instruction
3)Explain functions about IR, PC, ACC registers in a CPU
IR:指令寄存器, 用来储存执行中指令的暂存器
PC:程序计数器, 用于指示计算机在其程序序列中的位置
ACC:累加寄存器, 专门存放算术或逻辑运算的一个操作数和运算结果
4)Explain physical meaning about vars a & c in a machine
具有类型的内存单元。
2、简答题
1)What are stored in memory?
指令和数据
2)Can a data or a instruction stored in the same place?
Yes.
3) Explain Instruction Format with example instructions.
Example: ADD X:00000000 00000001
前八位为命令指示,第四位为寻址模式,1表示操作数是数值,0表示操作数是该地址的内容,例子中为地址,后四位为操作码;
后八位为操作数,表示一个数值,或者一个内存地址,例子中为内存地址1;
该例子表示加上地址1中的数。
3、解释以下词汇
1)汇编语言(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.
2)编译(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.
3)命令式语言(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.
4)函数编程语言(Functional programming)
In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—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.
5)过程式编程(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.