Difference between revisions of "Assembly Language Programming"
Marc Brown (talk | contribs) |
Marc Brown (talk | contribs) |
||
Line 6: | Line 6: | ||
Execution starts at the first line of the program and continues sequentially, except for “branch” instructions, until the “end” instruction is encountered. The result of each operation is stored in a special word of memory, called the “accumulator” (ACC). Each line of an assembly language program has the following fields (lower-case italics indicates optional components): | Execution starts at the first line of the program and continues sequentially, except for “branch” instructions, until the “end” instruction is encountered. The result of each operation is stored in a special word of memory, called the “accumulator” (ACC). Each line of an assembly language program has the following fields (lower-case italics indicates optional components): | ||
OP CODE | label OPCODE LOC comments | ||
DESCRIPTION | |||
* LOAD | The ''label'' is a character string beginning in the first column. Valid OPCODE’s are listed in the chart below. The LOC field is either a reference to a label or ''immediate data''. For example, “LOAD A” would put the contents referenced by the label “A” into the ACC; “LOAD =123” would store the value 123 in the ACC. Only those instructions that do not modify the LOC field can use the “immediate data” format. In the following chart, they are indicated by an asterisk in the first column. | ||
Contents of LOC are placed in the ACC. LOC is unchanged. | |||
STORE | {| class="wikitable" style="text-align: left"|- | ||
Contents of | |- | ||
!OP CODE | |||
!DESCRIPTION | |||
|- | |||
!*LOAD | |||
|Contents of LOC are placed in the ACC. LOC is unchanged. | |||
|- | |||
!*STORE | |||
|Contents of LOC are placed in the LOC. ACC is unchanged. | |||
|} | |||
* ADD | * ADD | ||
Contents of LOC are added to the contents of the ACC. The sum is stored in the ACC. LOC is unchanged. Addition is modulo 1,000,000. | Contents of LOC are added to the contents of the ACC. The sum is stored in the ACC. LOC is unchanged. Addition is modulo 1,000,000. | ||
Line 38: | Line 46: | ||
The value of the memory word defined by the LABEL field is defined to contain the specified constant. The LABEL field is mandatory for this opcode. The ACC is not modified. | The value of the memory word defined by the LABEL field is defined to contain the specified constant. The LABEL field is mandatory for this opcode. The ACC is not modified. | ||
END | END | ||
== Sample Problems == | == Sample Problems == |
Revision as of 16:50, 15 August 2018
Programs written in high-level languages such as Java and C++ are usually converted by compilers into assembly language (which in turn is translated into machine language programs - sequences of 1’s and 0’s – by an assembler). Even today, with very good quality compilers available, there is the need for programmers to understand assembly language. First, it provides programmers with a better understanding of the compiler and what are its constraints. Second, on occasion, programmers find themselves needing to program directly in assembly language in order to meet constraints in execution speed or space (for example, writing games for micros).
ACSL chose to define its own assembly language rather than use a “real” one in order to eliminate the many sticky details associated with real languages. The basic concepts of our ACSL topic description are common to all assembly languages.
Reference Manual
Execution starts at the first line of the program and continues sequentially, except for “branch” instructions, until the “end” instruction is encountered. The result of each operation is stored in a special word of memory, called the “accumulator” (ACC). Each line of an assembly language program has the following fields (lower-case italics indicates optional components):
label OPCODE LOC comments
The label is a character string beginning in the first column. Valid OPCODE’s are listed in the chart below. The LOC field is either a reference to a label or immediate data. For example, “LOAD A” would put the contents referenced by the label “A” into the ACC; “LOAD =123” would store the value 123 in the ACC. Only those instructions that do not modify the LOC field can use the “immediate data” format. In the following chart, they are indicated by an asterisk in the first column.
OP CODE | DESCRIPTION |
---|---|
*LOAD | Contents of LOC are placed in the ACC. LOC is unchanged. |
*STORE | Contents of LOC are placed in the LOC. ACC is unchanged. |
- ADD
Contents of LOC are added to the contents of the ACC. The sum is stored in the ACC. LOC is unchanged. Addition is modulo 1,000,000.
- SUB
Contents of LOC are subtracted from the contents of the ACC. The difference is stored in the ACC. LOC is unchanged. Subtraction is modulo 1,000,000.
- MULT
The contents of LOC are multiplied by the contents of the ACC. The product is stored in the ACC. LOC is unchanged. Multiplication is modulo 1,000,000.
- DIV
Contents of LOC are divided into the contents of the ACC. The signed integer part of the quotient is stored in the ACC. LOC is unchanged. BG Branch to instruction labeled with LOC if ACC>0. BE Branch to instruction labeled with LOC if ACC=0. BL Branch to instruction labeled with LOC if ACC<0. BU Program terminates. LOC field is ignored. READ Read a signed integer (modulo 1,000,000) into LOC. PRINT Print the contents of LOC. DC The value of the memory word defined by the LABEL field is defined to contain the specified constant. The LABEL field is mandatory for this opcode. The ACC is not modified. END
Sample Problems
Video Resources
The following YouTube videos show ACSL students and advisors working out some ACSL problems that have appeared in previous contests. Some of the videos contain ads; ACSL is not responsible for the ads and does not receive compensation in any form for those ads.
Intro to Assembly Language (CalculusNguyenify)
A general introduction into assembly language. In particular, covers how it fits into the source code to executable image pipeline. | |
Syntax of ACSL Assembly Language (CalculusNguyenify)
A very nice introduction to this ACSL category. | |
Examples (CalculusNguyenify)
Walks through a couple of ACSL Assembly language programs that have been used previous contests. |