Programming of CPU Assembly
It is the instruction system that reflects the CPU function, and the instruction system is not well designed, it is usually reflected in the program written with these instructions. If more problems can be handled with a program written by a CPU instruction set, this CPU is powerful, and the other is the lack of CPU function.
To detect whether the CPU we have designed has reached the desired target, we need to write a number of assembler programs to test it. When testing, the assembler must also be converted to a machine instruction program, otherwise the CPU will not be recognized. From this perspective, to learn computer CPU design, we must learn to assemble the programming, but also to be able to translate the assembly program into machine instruction program. In the process of translating the assembler into a machine instruction program, it is necessary to know the variables that occur in the program, where the data memory needs to be arranged, and to identify the first address of the program, and then determine the location of each program designator. Therefore, it is not only the problem of translation, but also the planning and arrangement of translating the assembler program into the machine instruction program. So the process of translating all kinds of computer languages into machine languages is called compiling, which means that even the choreography is translated.
Here we use the 15 CPU instruction system designed above to write a program that can find out the 64*53 results. Take this program as an example to illustrate the basic methods of assembly programming and compiling. As an exercise, we deliberately use addition to do multiplication, in order to use more instructions to program, so as to practice compiling programming and compiling methods.
Example 3-1 programming calculation 64x53.
According to the requirements stated in the 64*53 question, we have compiled the following assembly procedures:
1Start:sdal1; send 1 to da2 3 Str one; put in one unit4 5 Sub one; da position 06 7 Str result; result is put in 08 9Sdal -; send 64 to DaTen One Str x; da value deposited in X unit A -Sdal -; send 53 to Da - the Str y; da value is stored in Y unit - - Loop:lda y, y value send da - + Jz exit; DA is 0 go to exit execution - +Sub one; da-1 A at Str y; da value is stored in Y unit - - Lda result; da takes the value of result - -ADD x; result+x - in Str result; - to Jmp loop; go to loop execution + - exit:out result; output result content the *STP; stop.
Assembler is the basic unit of the statement, a statement can have a label, the habit of marking after the colon to show the difference with the instructions. In the assembler, both the label and the instruction object are used to denote the identifier. The assembler's statement is a space as a terminator, a semicolon is a comment symbol, the text behind it is not the program's valid content. In assembler programming, it is customary to call the manipulated object of the assembly instruction a variable.
Let the CPU run the program (iii)