View on GitHub

Homework Space

Homework Space for Introduction to Software Engineering

我的第七次作业

第一部分-解答

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
(X86):
a db 0
c db 0
mov al, 1
mov a, al //a = 1
add al, 3
mov c, al //c = a+3

(PL/0):
LOD #1
STO X
LOD X
ADD #3
STO Y
HLT

(机器语言):
00010100 00000001
00000101 10000001
00010100 10000001
00010000 00000011
00000100 10000002
00001111 00000000

2)Explain machine code execution with the fetch-decode-execute cycle
Main memory–>fetch instruction–>Decode instruction–>Registers –>Get data–>Execute the instruction–> Main memory
3)Explain functions about IR, PC, ACC registers in a CPU
IR: 指令寄存器,临时放置从内存里面取得的代码数据(也就是指令)
PC:程序计数器,用来指示下一条指令的地址(逻辑地址即偏移量)
ACC: 累加器A的缩写,累加器A是一个具有特殊用途的二进制8位寄存器,专门用来存放操作数或运算结果。在CPU执行某种运算前,两个操作数中的一个通常应放在累加器A中,运算完成后累加器A中便可得到运算结果。
4)Explain physical meaning about vars a & c in a machine
在内存中申请一块内存作为a和c的空间

第二部分-简答

1)What are stored in memory?
指令和数据
2)Can a data or a instruction stored in the same place?
可以
3) Explain Instruction Format with example instructions.
ADD X: 0000000 bbbbbbbb
前八位是命令指示,后八位是操作数,其中第四位为寻址方式,五到八为为操作码

第三部分-名词解释

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. 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.