Intel mcs-48 manual Our machine language program then becomes, Step Hex Code, MOV R2, #05, A, P1

Models: mcs-48

1 478
Download 478 pages 26.88 Kb
Page 20
Image 20

INTRODUCTION

Decimal

Hex

Binary

0

0

0000

1

1

0001

2

2

0010

3

3

0011

4

4

0100

5

5

0101

6

6

0110

7

7

0111

8

8

1000

9

9

1001

10

A

1010

11

B

1011

12

C

1100

13

0

1101

14

E

1110

15

F

1111

step 8 would have to be changed to refer to the new address of step 4.

1.2.2 Assembly Language Programming Assembly language overcomes the dis- advantages of machine language by allowing the use of alphanumeric symbols to repre- sent machine operation codes, branch addresses, and other operands. For example, the instruction to increment the contents of register 0 becomes INC RO instead of the hex 18, giving the user at a glance the meaning of the instruction. Our example program can be written in assembly language as follows:

Step No. Hex Code

Assembly Code

o

88

MOV RO, #32

Our machine language program then becomes:

Step Hex Code

o B8

120

2BA

305

409

5FO

618

7EA

804

This coding is now quite efficient to write and read and coding errors are much easier to detect. Hex coding is usually very efficient for small programs (a few hundred lines of code). However, it does have two major limitations in larger programs:

1.Hex coding is not self-documenting, that is, the code itself does not give any indication in human terms of the operation to be performed. The user must learn each code or constantly use a Program Reference Card to convert.

2.Hex coding is absolute, that is, the program will work only when stored in a specific location in program memory. This is because the branch or jump instructions in the program reference specific addresses elsewhere in the program. In the example above steps 7 and 8 reference step (or address) 4. If the program were to be moved,

1

20

 

2

8A

MOV R2, #05

305

4

09

INP:

IN A, P1

5

AO

 

MOV @RO, A

6

18

 

INC RO

7

EA

 

DJNZ R2, INP

804

The first statement can be verbalized as follows: Move to Register 0 the decimal number 32. Move instructions are always structured such that the destination is first and the source is second. The pound sign "#" indicates that the source is "immediate" data (data contained in the following byte of program memory). In this case data was specified as a decimal 32, however, this could have been written as a hex 20H or a binary 0010 00008 since the assembler will accept either form. Notice also that in this instance two lines of hex code are represented by one line of assemlJly code.

The input instruction IN A, P1 has the same form as a MOV instruction indicating that the contents of Port 1 are to be transferred to the accumulator. In front of the input instruction is an address label which is delineated by a colon. This label allows the program to be written in a form independent of its final location in program memory since the branch instruction at the end of the program can refer to this label rather than a specific address. This is a very important advantage of assembly language programs since it

1·11

Page 20
Image 20
Intel mcs-48 Our machine language program then becomes, Step No. Hex Code Assembly Code MOV RO, #32, Step Hex Code, A, P1