Checking Some Opcodes in Assembly Language

A program written in an assembly language that implements the following Java code look like the one:

int thomas = 3, sylvester = 7, cats;
cats = thomas + sylvester;

Symbol     Opcode    Operand
------------------------------
SAMPLE     START     FIRST     Line 1
THOMAS     WORD      3         Line 2
SYLVESTER  WORD      7         Line 3
CATS       WORD      ?         Line 4
FIRST      LOAD      THOMAS    Line 5
ADD        SYLVESTER           Line 6
STORE      CATS                Line 7
STOP                           Line 8
END                            Line 9

 

The program adds two numbers 3 and 7 that are in the variables THOMAS and SYLVESTER respectively, and stores the result 10 in the variable CATS. The column labels, the line below the column labels, and line numbers are not part of the program but included to show how the words line up. In order from left to right, the three fields of an instruction are the symbol, the operation code (opcode), and the operand. The first field is typically reserved for the names of variables or labels for instructions. The second field is typically used for opcodes that represent executable instructions and also assembler directives which tell the assembler what to do. The third field is used for operands.

The first line indicates the start of the program. The symbol SAMPLE is the name of the program, the opcode START tells the computer when the program starts, and operand FIRST indicates the location of the first instruction. The second through fourth lines are directives that tell the assembler to reserve the memory locations. Line 2 reserves a space for the symbol THOMAS which is initialized to 3. Similar to the second line, the third line initializes the variable SYLVESTER to 7. The fourth line reserves an uninitialized memory location called CATS. Line 5 fetches the contents from the memory location THOMAS and stores it into a register. A register is a memory location in the CPU where among other things arithmetic can be performed. Then the ADD operation in Line 6 gets the value from the variable SYLVESTER and adds it to the contents of the register. The next line stores the value in the register into the memory location CATS. The STOP instruction halts the
execution of the program. In the last line, the END directive indicates to the assembler the end of the program.

 

About Aliyar Güneş

I’am Aliyar Güneş, a learner and software developer from Istanbul, Turkey. I write C# and Java.
This entry was posted in General Concepts and tagged , , . Bookmark the permalink.

Leave a Reply