174 Computer Architecture and Organization
8051). The details of this selection process are indicated in the table at the right side of Figure 6.16 . Instruc-
tions like ADD A, R3, DEC R7 and such kind, use this format.
Unlike in the previous three cases, the fourth one [Figure 6.16 (d)] is used in only two instructions,
namely ACALL and AJMP. These are two byte instructions and the second byte contains least signi -
cant eight bits (A0–A7) of the target address. Bits A8–A10 of the target address are accommodated
within the rst byte of the instruction, placed in most signi cant three bits. During execution, this trun-
cated target address is placed within the program counter, without modifying its most signi cant ve
bits. Therefore, these two instructions offer a jumping range of 2K within program memory.
6.8.2 Discussions
8051 offers a total of 255 instructions of 49 types, as indicated in Table 6.7 . However, its instruction
set is well-designed as compared to that of 8085 as there was no restraint of maintaining the backward
compatibility in the case of 8051’s architectural design. It was already mentioned that the design of
8051 resembles the RISC-type architecture. Let us discuss a few attributes to elaborate this matter.
To start with, just compare instruction format of 8086 (Figure 6.13 ) with that of 8051 (Figure 6.16 ).
We may immediately understand that the uniformity in the instruction elds for the latter is non-existent
in the former. We have already discussed that the uniformity in the instruction elds allows faster and
more ef cient instruction decoding, ensuring an enhanced performance of any processor.
As the next item of comparison, we may take up the addressing modes offered in both cases. The
addressing modes of 8051 are minimum in number and memory related operations are limited, which
is not so in the case of 8086. In this context, we should not forget that 8051 instructions are designed
basically for its internal memory units. As far as its optional external memory is concerned, only data
move type instructions are provided in 8051.
The number of general purpose registers of 8051 is 32, which is wisely divided into four register
banks to make the register addressing a simpler one and, at the same time, by register bank switching,
a larger set of data available within the register set may be accessed to speed up its processing. The
register set of 8086 may not be taken as so ef cient.
To conclude our discussions on 8051 instruction set, it may be pointed out that the majority of fea-
tures available in RISC architecture are also present in 8051. Its instruction set was well-planned and
well-designed to cater to the demands of most programmers and system designers.
6.9 ASSEMBLY LANGUAGE PROGRAMMING
The fundamental difference between high level language and assembly language is that the latter’s
processor-dependency. Every processor has its own assembly language instruction set, tailor-made for
that processor only. In other words, assembly language program, written for one processor would not
normally run on any other processor. Here, the term ‘any other indicates any other series of processor,
leaving aside processors of the same family. For example, assembly language program written with
8085 assembly language instruction set would not be properly executed with, e.g., Motorola 6800 pro-
cessor. Note that there are certain exceptional cases, like Intel 8085 and Zilog Z80. However, programs
developed in high level language are machine independent. Why is it so? This is because high level
language programs are translated (compiled) to the corresponding assembly language programs of the
concerned processor by a suitable compiler, before its execution. This compiler is tailor-made for that
high level language and the concerned processor.
M06_GHOS1557_01_SE_C06.indd 174M06_GHOS1557_01_SE_C06.indd 174 4/29/11 5:09 PM4/29/11 5:09 PM
Instruction Set and Assembly Language Programming 175
Programs, developed in assembly language, are also to be translated (assembled) to the machine
language of the respective, processor. This is achieved by an assembler ( Figure 6.17 ). Its duty is to
translate each assembly language instruction to the corresponding machine code of the processor. Note
that compiler cannot translate each high level language instruction to its corresponding machine code
in this way as there is no one-to-one correlation between these two. In general, multiple machine lan-
guage instructions are necessary to implement one high level language instruction. We shall discuss
about assembler in Section 6.9.1. At present, we shall try to nd out the disadvantages and advantages
of assembly language programming.
Figure 6.17 Transformations of a high level language program
6.9.1 Why Assembly Language Programming?
It is a well-known fact that assembly language programming is dif cult with respect to high level
language programming. It is so, because the assembly language programmer must have the clear idea
about the processors architecture and its instruction set details. A high level language programmer, on
the other hand, need not worry about all these details during program development. As a matter of fact,
it is not known to the programmer (and not required to be known either) which processor would be
executing the high level language program. This type of duty is passed to the compiler designer. There-
fore, it is preferable to discuss the points regarding bene ts of assembly language programming before
explaining its other details.
The most important point related with de ciency of high level language is, in certain cases of real-
time systems , programs written in high level languages are unable to deliver the result on time . This is
especially true for hard real-time systems, where any delay of the result (or output) makes the software
unacceptable . As we know, real-time systems might be of two types, hard and soft . For soft real-time
system, slight delay in output may be acceptable, but not in the case of hard category. For example, dur-
ing a railway ticket booking through credit cards, using internet, only a few micro-seconds of time slot
is allowed to get a nod from the concerned bank. Using the user ID, the validation of password must
be done for this, followed by checking the relevant account for allowable credit limit and so on. As a
very large database to be searched for this purpose, the program must be ef cient enough to complete it
within a stipulated time frame. Otherwise, the time slot would expire and the booking has to be started
fresh. Therefore, this becomes an example case, where assembly language must be implemented.
At this stage, the reader may ask the question that, what is the shortcoming of any high level lan-
guage in such a situation? As a matter of fact, the machine code generated by compilers from high
M06_GHOS1557_01_SE_C06.indd 175M06_GHOS1557_01_SE_C06.indd 175 4/29/11 5:09 PM4/29/11 5:09 PM
176 Computer Architecture and Organization
level language to machine language is not optimum and tailor-made for the purpose. High level lan-
guage instructions are of general purpose type, and to maintain its applicability in all types of situa-
tions, the compiler has to take a broader view at the time of changing it to assembly language code.
For example, a compiler would always assign 4 bytes of space to accommodate an integer, while in
certain situations it might be accommodated within a byte by the assembly language programmer.
Therefore, every time one integer has to be compared with another integer, the compiler generated
machine language program (for high level language) has to compare four bytes of data, while one
byte comparison might solve the problem for its assembly language counterpart. Evidently, this
reduces the execution time of the assembly language program and makes it more ef cient (works
faster).
The second advantage of assembly language programming is that it makes the programmers concept
clear about the architecture of the processor. It is as if talking with someone with her(his) own language.
All advantages and utility of the processor become available to the assembly language programmer to
generate ef cient program codes. Therefore, the best way to understand the architecture of any proces-
sor is to develop a few assembly language programs by using it.
6.9.2 Assembly Language Program Format
Similar to every other language, assembly language also has its own format, which is a simple one. To
start with, assembly language programs are translated to machine language by the assembler, one line
after another . We shall discuss in details about assembler in Section 6.9.4. At present, we should keep
in mind that in assembly language programming, every line of the program listing is taken as a new and
complete statement. Therefore, every line of any assembly language program must be self-suf cient
and continuation of any line to the next line is not permitted in assembly language programming (in
general).
The general format for any line is shown in Figure 6.18 . As it may be observed, there are a total of
four elds, one each for ‘label, ‘mnemonic’, ‘operand’ and ‘comments’. Out of these four, comment
statements are non-executable statements and ignored by assembler during its assembly process.
They are included to improve the readability of the program and for general descriptions. Gener-
ally, they are indicated by a semicolon (;) at the beginning. A complete line may also be devoted by
comment statement, as shown. However, if any comment statement needs additional line(s), then
at the start of every line, there should be a semicolon, to indicate that the line contains a comment
statement.
As far as the instructions are concerned, its mnemonic eld is a compulsory one. An instruction may
or may not have any operand(s). For example, the mnemonic ‘NOP’ does not have any operand. If it
needs any, like ‘MOV A, B’, they have to be placed within the operand eld, which is generally sepa-
rated from the mnemonic eld by a space. If more than one operand to be placed, comma (,) has to be
used to separate them from each other.
The leftmost eld is reserved to accommodate labels. Labels are indications of various important
locations of the program body, referred within some instructions for branching or calling purpose. In
our example case (Figure 6.18 ), the rst instruction’s location is indicated by the label START, which
was referred in the second instruction. Labels are not only used to indicate some special locations
within the program body, they may also be used to improve the readability of any program. Note that
no reserved words may be used for label. These reserved words include mnemonics and assembler
directives (Section 6.9.4).
M06_GHOS1557_01_SE_C06.indd 176M06_GHOS1557_01_SE_C06.indd 176 4/29/11 5:09 PM4/29/11 5:09 PM
Instruction Set and Assembly Language Programming 177
As a general rule, label, mnemonic and comment are optional for any line within the program body.
It means, a line may have only a label, or only a mnemonic, or only a comment, or any combination of
these. However, only operands are not allowed and they must follow some mnemonic.
6.9.3 Assembler Directives
Apart from label, mnemonic, operand and comments, an assembly language program generally contains
some other type of notations, known as assembler directives. These are necessary only for the internal
usage of the assembler and are not executable instructions that form part of the program. For Intel pro-
cessors, some of these assembler directives are
R EQU
R ORG
R END
R DB
R DW
R MACRO
The rst one, EQU, indicating equate with, is used to de ne the location (address) of any variable or the
value of some constant. For example,
COUNT EQU 002BH ; to store COUNT value
informs the assembler to reserve the memory location with address 002BH for storing the value of the
variable COUNT. Similarly,
ULMT EQU 33H ; upper limit is 33H
tells the assembler to replace the constant ULMT by 33H whenever it appears within the program body.
The second one, ORG, indicating originate from, is used to inform the assembler the starting address
of the following program segment or a subroutine. For example,
ORG 002BH
SERL: PUSH PSW ; save status
informs the assembler that the machine code of the instruction PUSH PSW must start from the address
002BH within the program memory.
Figure 6.18 General format of assembly language program
M06_GHOS1557_01_SE_C06.indd 177M06_GHOS1557_01_SE_C06.indd 177 4/29/11 5:09 PM4/29/11 5:09 PM
178 Computer Architecture and Organization
The third one, END, is used to denote the end of the program. This must be the last statement of a
program body. Any instruction after this would not be considered by the assembler or would generate
an error code during program assembly.
The next two directives, DB and DW, stand for de ned byte and de ned word, for the assembler.
They have to be used to denote any constant data within the program segment. If the data is a byte, DB
has to be used before it. If it is a word, then DW has to be used.
The last one, MACRO, denotes a macro, which we shall discuss in details in Section 6.10.4. At rst,
we shall discuss the four major techniques of assembly language programming. They are
R Data transfer and manipulations
R Loops and loop control
R Program branching
R Subroutine calls
6.9.4 Data Transfer and Manipulations
As we have already discussed, every processor offers suf cient number of instruction for data transfer
and manipulations. The data transfer may be within the processor, e.g., between accumulator and a reg-
ister. Or it may be between external memory and the processor (some registers). Data transfer may also
be necessary between the processor and some I/O device.
Any CISC processor would offer suf cient number of addressing modes for data transfer operations.
For RISC processors, the number of available addressing modes might be limited, especially for data
transactions with external memory, in exchange for a larger register set within the processor itself.
Arithmetic and logical instructions are used for data manipulations. Their variety also depends upon
the processor. For example, Intel 8085 does not offer any single instruction for multiplication or divi-
sion, which is offered by Intel 8086 or Intel 8051.
Depending upon the processor, data manipulation instructions, i.e., arithmetic and logical instruc-
tions, may be of one, two or three register type . In three register type instruction format, the result regis-
ter is also indicated in the instruction apart from mentioning two source registers holding two operands.
In two-register format, one of the two indicated register would be holding the result of arithmetic or
logical operation. For one register instructions, generally, the accumulator holds the other operand as
well as the result after completion of the operation.
6.9.5 Loops and Loop Control
Iterative procedures or program loops play a vital role in almost every program. As a matter of fact,
computers are famous to perform repeated execution of boring instructions. In general, for high level
languages, three main types of iterations are implemented. They are
R For–Next loop
R Repeat–Until loop, and
R While–Do loop.
In the case of repeat–until loops, branching conditions are checked at the end of the loop. On the
other hand, they are checked at the very beginning by while–do loops. In other words, repeat–until loop
would be executed at least once, which is not so in case of while–do loops.
M06_GHOS1557_01_SE_C06.indd 178M06_GHOS1557_01_SE_C06.indd 178 4/29/11 5:09 PM4/29/11 5:09 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.10.32