26
This chapter will discuss the whole arithmetic instruction in 8051 for the number of operations as well as the number of unmarked unmarked. Example is given to illustrate the application program of each order. SubBAB 6.1 we discuss the program and related instructional Addition (addition) and subtraction (decrease) in the number of unmarked, including data to BCD (Binary Coded Decimal). Multiplication (multiplication) and division (division) we discussed in SubBAB 6.2. Is the number of unmarked we discuss in subBAB 6.3 SubBAB 6.1 INCREASE AND DECREASE OF NOT MARKED Interpreted as the number of marked where all the bits of data is a representation of the data, and no bits exerted a positive sign or a minus.This means that the operand can be either bilnangn 00 s / d FFH (0- 255 decimal) of 8-bit data. Discussion on the topic we discuss the number marked on subBAB 6.3 Addition Number Not Signed In 8051, two additional process data, often involving accumulators. And ADD command format is ADD A, source: A = A + source ADD instruction is used to perform the addition of the two operand. And destination (where the result of the process) is always on A, sdang source operand can be a register, the data directly, or memory. Remember arithmetic operations from memory to memory are not permitted by the assembler 8051.This instruction can memperngaruhi bits in the PSW register as AC (auxiliry Carry), C (carry), and OV (overflow), depending on the operating Hail happen. Operations affecting bit ov we discuss in subBAB 6.3 in the discussion of the number marked. Given the current debate is an unsigned number, then we can temporarily ignore ov. See example 6-1 Example 6-1 Show how the flag register (PSW) could be influenced by the instructions below MOV A, # 0F5h; A = F5 hex

Aritmatika PLC

Embed Size (px)

DESCRIPTION

PLC

Citation preview

Page 1: Aritmatika PLC

This chapter will discuss the whole arithmetic instruction in 8051 for the number of

operations as well as the number of unmarked unmarked. Example is given to illustrate

the application program of each order. SubBAB 6.1 we discuss the program and related

instructional Addition (addition) and subtraction (decrease) in the number of unmarked,

including data to BCD (Binary Coded Decimal). Multiplication (multiplication) and division

(division) we discussed in SubBAB 6.2. Is the number of unmarked we discuss in subBAB

6.3

 

 

SubBAB 6.1 INCREASE AND DECREASE OF NOT MARKED

 

Interpreted as the number of marked where all the bits of data is a representation of the

data, and no bits exerted a positive sign or a minus.This means that the operand can be

either bilnangn 00 s / d FFH (0-255 decimal) of 8-bit data. Discussion on the topic we

discuss the number marked on subBAB 6.3

 

Addition Number Not Signed

 

In 8051, two additional process data, often involving accumulators. And ADD command

format is

 

      ADD A, source: A = A + source

 

ADD instruction is used to perform the addition of the two operand. And destination

(where the result of the process) is always on A, sdang source operand can be a register,

the data directly, or memory. Remember arithmetic operations from memory to memory

are not permitted by the assembler 8051.This instruction can memperngaruhi bits in the

PSW register as AC (auxiliry Carry), C (carry), and OV (overflow), depending on the

operating Hail happen. Operations affecting bit ov we discuss in subBAB 6.3 in the

discussion of the number marked. Given the current debate is an unsigned number, then

we can temporarily ignore ov. See example 6-1

 

Example 6-1

 

Show how the flag register (PSW) could be influenced by the instructions below

 

      MOV A, # 0F5h; A = F5 hex

      ADD A, # 0Bh; F5 + A = 0B = 0

 

Answer : 

Page 2: Aritmatika PLC

         F5h 1111 0101

        F5h +         1111 0101 +

        100H 1111 0101

 

After pejumlahan, register a destination) will contain 00 and bedera is as follows

 

CY = 1 since there Carry out from D7

PF = 1 because the number of 1s is REGARDING from 0 (zero). PF = 1

AC = 1 because there is carry from D3 to D4

 

 

 

Addition to Single Byte

 

In Chapter 2 there is an example program to perform data aggregation 5 bytes. Total at

least under the FFH, which is the maximum value that can ditangai by an 8-bit

register. To calculate the number of the number of operand, the Carry flag should always

be checked each completed a summation order. Example 6-2 uses the accumulators R7

 

Example 6-2

 

Think of RAM at location 40-44 memlliki value as follows. Write a program to find the

result of the summation of A diakhri program, register A to the low-byte and R7 as high-

byte.

 

         40 = (7D)

         41 = (EB)

         42 = (C5)

         43 = (5B)

         44 = (30)

 

Answer : 

         MOV R0, # 40H; fill pointer

         MOV R2, # 5; fill counter

         CLR A

         MOV R7, A; R7 Clear

AGAIN: ADD A, @ R0; Add A with R0 inductee bytes

         JNC MORE: If DY = 0 jangann ditambhakan

         INC R7; keep carry as kelebiihan

MORE: INC R0; Increment pointer

         DJNZ R2, AGAIN; ulagi reach R2 = 0

 

 

Analysis of example 6-2

 

Page 3: Aritmatika PLC

There are three processes in the loop as shown pda picture above. Learning program

actually depends of how much we practice.

1.    7Dh (the contents of the memory 40H) added to A with carry = 0 and R7 = 0, and the

contents of the counter R2 = 04.

2.    Both. EBH (the contents of the memory 41H) ditambahakn turn on A, which make A == 68H

and CY = 1. because there Carry, now on-increment R7. And now Counter R2 = 3.

3.    then C5h (the contents of the memory 42H) is added to A. Which makes A = 2DH and again

there carry, on-increment R7. And now, R2 = 2.

 

By the time the loop ends. The result of the summation is on A and R7, where A is the

low byte, high byte is R7 is.

 

 

ADDC and the summation of the number of 16-bit

 

When we do the summation of two 16-bit numbers, we should pay attention to the status

of "hold" from Carry from lower-byte high-byte. Instruction ADDC (Add with Carry) can be

used to matter. For example, see the summation 3CE7h + 3B8Dh, as below.

 

       1

      3C E7

      8D 3B +

      78 74

 

When the first byte aggregated (E7 + 8D = 74, CY = 1). Carry is the status of "hold" for

the next byte, making the 3C + 3B + 1 = 78 (all in hex).Example 6-3 below shows the

steps above in the 8051 program.

 

Example 6-3

 

Write a program for addition of a 16-bit number. 3CE7h and 3B8Dh numerically. Place

the amount in R7 and R6, R6 as low-byte.

 

Answer : 

         CLR C; make CY = 1

         MOV A, # 0E7h; fill low-byte

         ADD A, # 8Dh: add, the result A = 74h and CY = 1

         MOV R6, A; keep low-bytes of the summation

         MOV A, # 3CH; fill with high-byte

         ADDC A, # 3BH; adding together carry

         MOV R7, A; store the result (high-byte) in R7

 

 

 

System number BCD (Binary Coded Decimal)

Page 4: Aritmatika PLC

 

BCD stands for Binary Coded Decimal. BCD is needed because in everyday life we often

use the digits 0 s / d 9 to mention the number, not binary or hexadecimal. Is a

representation of the number of binary digits 0 s / d 9 called BCD. See photos 6-1. In

books about computers, there are two important things in BCD number, namely (a)

Unpacked BCD, and (b) Packed BCD.

 

 

Digit     BCD0                            00001                            00012                            00103                            00114                            01005                            01016                            01107                            01118                            10009                            1001 

Photo 6-1 BCD Code

 

 

Unpacked BCD

 

In Unpacked BCD, 4-bit reprensentasi bottom is the number of 0 s / d 9, while others left

the 4-bit 0. Examples of "0000 1001" and "0000 0101" is unpacked BCD from number 9

and 5. Unpancked membutukan BCD 1 byte of memory or an 8-bit register for storing a

data / number of BCD.

 

 

Packed BCD

 

In Packed BCD, every byte it contains two BCD numbers in it, a 4-bit there at the bottom,

and the other a 4-bit there at the top. For example, "0101 1001" is packed BCD the

number 59H. Thus it takes a byte of memory enough to accommodate two BCD

number. Clear case made more efficient in the BCD data storage two times better.

Many questions that arise in the aggregation number is BCD, Corrections-Corrections

always needed so that the summation is as we expect. This is because the CPU add two

BCD data as usual summation, as an unsigned number, so it will make the results not the

number of BCD. See examples in this baah

 

      MOV A, # 17h

      ADD A, # 28H

 

Page 5: Aritmatika PLC

Summing two numbers will generate 0011 1111b (3Fh) where it is not the number of

BCD. Of course, since the number of BCD digits must have 0000 - 0101 (0-9). In other

words, ideally in total to the number of BCD BCD bilngan we would get

anyway. Necessarily yield is 17 + 28 = 45 (0100 0101).Well to correct the problems

above, programmers should add 6 (0110) at the bottom of a 4-bit, up to the previous

result that is 3F + 06 = 45. Well this is as we expect. The same thing can happen in 4-bit

up. For example, 52h + 87H = D9h. Again we improve the results by adding the figure 6

on the top 4-bits, D9h + 60H = 139h. See that 52 + 87 = 139. Note that the number of

4-bit or 4-bit down on the result, if greater than 9 should be increased by 6 to get the

correct results. But 8051 has been preventing us from hassles-these hassles. 8051 has

an instruction that can detect a nible (4-bit), what is greater than 9, and will increase by

6 if it is true. The order is "DA" The Decimal Adjustment. DA's instruction has only one

syntax only, ie ..

 

A DA

 

, Which serve to question the summation Corrections BCD number as we know it on.

 

 

Instruction DA

 

Instruction DA (Decimal Adjust for Addition) in 8051 is able to be used to correct the

problems that arise in connection Denga summation BCD number.And this

commandment have only operand accumulator "A". This instruction will add 6 under or

nible nible on if needed, but if not, will not be revamped nible. The example below will

explain.

 

      MOV A, # 47h, A = 47h first BCD

      MOV B, # 25H; B = 25H second BCD

      ADD A, B, the result is 6CH

      DA A; improve to be 72h

 

Once the program is implemented, a current register contains 72h (47 + 25 = 72). DA

instruction works only on A. In other words, if they want to correct the number of

register-register BCD on the other we have to move in a first.And also please understand,

that in order to be used after the DA Instruction orders summation BCD number, which is

not needed revenue to more than 9 digit number, such as A s / d F. The most important

one is the status of CY and AC DA seconds before instruction executed.

Sometimes we want Meng-increment or decrement the number of instructions in

BCD. Prohibit booklet we use the INC or DEC before the DA, to do just that.This recall INC

and DEC instructions do not affect the flags so it is possible the results into one

operation. Handbook recommends that we use the " ADD A, # 01h "as the successor

INC., and" ADD A, # 99h "as the successor DEC.

 

 

A summary of the DA

Page 6: Aritmatika PLC

 

Instruction is done after the order of ADD or ADDC and ..

1.    if nible under greater than 9, or if AC = 1, nible is added under 6.

2.    above if nible greater than 9, or if CY = 1, nible above is added 6.

 

We can know that we never use AC except for menjumlahan and management's

corrected BCD number. For example, adding 18h 29H and 41H will make there, which is

clearly not the desired result as the summation of the number of BCD.

 

      Hex BCD

      29 0010 1001

      18 +        0001 1000 +

      41 0100 0001 AC = 1

      6 +                0110  +

      47 0010 1001

 

because AC = 1, after summation " DA A "will add 6 to nible under. The result then is

that as the number of BCD format we expect.

 

DA instruction so this is very useful and very important for us to process data BCD

format.

 

Example 6-4

 

Suppose there are a number of BCD data stored in RAM from location 40H like this. Write

a program to find the sum of all the numbers. The result should also BCD.

 

         40 = (71)

         41 = (11)

         42 = (65)

         43 = (59)

         44 = (37)

 

Answer : 

         MOV R0, # 40H; fill pointer

         MOV R2, # 5; fill counter

         CLR A

         MOV R7, A; R7 Clear

AGAIN: ADD A, @ R0; Add A with R0 inductee bytes

         DA A; Adjust for BCD

         JNC MORE: If DY = 0 do not add

         INC R7; keep carry bargain edge (the 100H)

MORE: INC R0; Increment pointer

         DJNZ R2, AGAIN; ulagi reach R2 = 0

 

Page 7: Aritmatika PLC

 

 

 

Reduction in the number of unmarked

 

      SUBB A, source: A = A - source - CY

 

In many processors there are two differences order reduction and SUBB SUB (Subtraction

with borrow). In 8051 we provided only SUBB. But do not be disappointed because we

could SUBB functioned as SUB. Namely to create / make sure CY = 0 before order SUBB

implemented. Thus there are two things in SUBB namely (a) the previous CY = 0, and (b)

the previous CY-1. First we will discuss before SUBB CY = 0.

 

 

SUBB (SUBSTRACT with borrow) when CY = 0

 

SUBB with previous CY = 0, can also be regarded SUB. This is because the previous

Borrow considered null, or no. Up to SUBB be SUB, we previously recommended to

download the CY clear-huh.

 

In mitigation, 8051 microprosessor like other modern CPU using 2's complement

method. That's because each CPU is using too many y transistor in it for Adder

(enhancer), will be far more than any CPU also features separate transistor network to

decrease. Therefore modern CPUs use the same adder used by aggregation of orders,

with little additional modification. As for the process of SUBB end is as follows

 

1.    For the 2's complement of the subtrahend (source).

2.    Add (ADD) on a reduced number of (A).

3.    Refund status of CY

 

But we can calm, all is done by the hardware in order SUBB 8051's. Until SUBB order to

be able to be easily used by us, such as using lainnnya orders. Despite the fact it is a

complicated process. We just enough to know where the reduced, which reduces, and

the status of CY, plus the results must be where.

 

Example 6-5

 

Show 3 step process as described previously, for under this program.

 

            CLR C; make CY = 0

            MOV A, # 3Fh; fill 3Fh in A (A = 3Fh)

            MOV R3, # 23h; 23h fill in R3 (R3 = 23h)

            SUBB A, R3; reduction in A-R3, resulting in a

 

Answer :            A = 3F 0011 1111 0011 1111

Page 8: Aritmatika PLC

            R3 = 23     0010 0011 +  1101 0011   2's Complement

                 1C 1 0001 1100

                                     0 CY = 0 (step 3)

 

Flags will be .. CY = 0, AC = 0, and we have to check the condition of the Carry to find

positive or negative result.

 

 

If after SUBB, CY = 0 means the result is a positive number, but if CY = 1 then the result

is negative. Negative result is in 2's complement form. The scale of the negative number

we can get by using CPL (complement) and INC (Increment) of the findings. For example,

if we get -22, then using two instructional way we will get 22 of the number -22.  See

example 6-6

 

Example 6-6

 

You give the following program.

 

            CLR C; make CY = 0

            MOV A, # 62H; fill 62H in A (A = 3Fh)

            SUBB A, # 6Eh; reduction A - 6Eh

            MORE JNC, if CY = 0 then jump

            A CPL, if CY = 1 for 1's Complement

            INC A; Then for 2's Complement

MORE: MOV R1, A; Save A on the R1

 

Answer : 

Here are the steps to " SUBB A, 6Eh ".

        4C 0100 1100 0100 1100

        6E          0110 1110 2's Complement =   1001 0010  +

       -22 0 1101 1110

 

CY = 1, the result is negative, the 2's Complement.

 

 

 

SUBB (SUBSTRACT with borrow) when CY = 1

 

SUBB instruction can be used to perform multibyte reduction, with attention to the

borrow flag (remember the SUBB, also named Borrow flag CY). Meaning borrow is means

" borrow "from the smaller operand storey. See example 6-7

 

Example 6-7

 

Page 9: Aritmatika PLC

You give the following program.

 

            CLR C; make CY = 0

            MOV A, # 62H; fill 62H in A (A = 3Fh)

            SUBB A, # 96h; reduction A - 96h = CCH with CY = 1

            MOV R7, A; store the result in R7

            MOV A, # 27H; A = 27H

            SUBB A, # 12h, A = 27H - 12h - 1 = 14h (remember the status of CY)

            MOV R6, A; keep other results

 

Answer : 

After SUBB, A = 62 -96 = CCH, and CY to 1, which indicates the number of borrow. Given

CY = 1, and when SUBB dilakasanakn second time. A = 27H - 12h = 14h -1. Until the

urge to firmly results are 2762h - 14CC = 14CCh

 

 

Bab ini akan membahas instruksi aritmatika keseluruhan dalam 8051 untuk jumlah operasi serta

jumlah ditandai ditandai . Contoh diberikan untuk menggambarkan program aplikasi dari setiap

pesanan . SubBAB 6.1 kita membahas program dan Penambahan instruksional terkait

( penambahan ) dan pengurangan ( penurunan) jumlah bertanda , termasuk data ke BCD ( Kode

Biner Desimal ) . Perkalian ( multiplikasi ) dan pembagian ( divisi ) kita bahas dalam SubBAB

6.2 . Apakah jumlah bertanda kita bahas dalam subBAB 6.3

 

________________________________________

 

SubBAB 6.1 KENAIKAN DAN PENURUNAN TIDAK ditandai

Page 10: Aritmatika PLC

 

Diartikan sebagai jumlah ditandai di mana semua bit data adalah representasi dari data , dan

tidak ada bit diberikan tanda positif atau minus.This berarti bahwa operan dapat berupa bilnangn

00 s / d FFH ( 0-255 desimal ) data 8 - bit . Pembahasan topik kita membahas jumlah yang

tertera pada subBAB 6.3

 

Penambahan Nomor Tidak Terdaftar

 

Pada 8051 , kedua data proses tambahan , sering melibatkan akumulator . Dan format perintah

ADD

 

      ADD A , sumber : A = A + sumber

 

ADD instruksi digunakan untuk melakukan penambahan dua operan . Dan tujuan ( di mana hasil

dari proses) selalu pada A , sdang operand source dapat register, data langsung , atau memori .

Ingat operasi aritmatika dari memori ke memori tidak diizinkan oleh 8051.This instruksi

assembler dapat memperngaruhi bit dalam register PSW sebagai AC ( auxiliry Carry ) , C (carry )

, dan OV ( overflow) , tergantung dari Hujan es operasi terjadi. Operasi mempengaruhi bit ov kita

bahas dalam subBAB 6.3 dalam pembahasan nomor ditandai . Mengingat perdebatan saat ini

adalah nomor unsigned , maka kita dapat sementara mengabaikan ov . Lihat contoh 6-1

 

contoh 6-1

 

Tunjukkan bagaimana register bendera ( PSW ) dapat dipengaruhi oleh petunjuk di bawah ini

 

      MOV A , # 0F5h , A = F5 hex

      ADD A , # 0Bh , F5 + A = 0B = 0

Page 11: Aritmatika PLC

 

Jawaban :

 

         F5h 1111 0101

        F5h + 1111 + 0101

        100H 1111 0101

 

Setelah pejumlahan , daftar tujuan ) akan berisi 00 dan bedera adalah sebagai berikut

 

CY = 1 karena ada Melaksanakan dari D7

PF = 1 karena jumlah 1s adalah TENTANG dari 0 ( nol ) . PF = 1

AC = 1 karena ada carry dari D3 ke D4

 

 

 

Penambahan Byte Tunggal

 

Dalam Bab 2 ada contoh program untuk melakukan agregasi data 5 byte . Jumlah setidaknya

bawah FFH , yang merupakan nilai maksimum yang dapat ditangai oleh register 8 - bit . Untuk

menghitung jumlah jumlah operan , bendera Carry harus selalu diperiksa setiap selesai urutan

penjumlahan . Contoh 6-2 menggunakan akumulator R7

 

contoh 6-2

Page 12: Aritmatika PLC

 

Pikirkan RAM di lokasi 40-44 memlliki nilai sebagai berikut . Menulis sebuah program untuk

menemukan hasil penjumlahan Sebuah program diakhri , daftar A ke rendah - byte dan R7

setinggi - byte .

 

         40 = ( 7D )

         41 = ( EB )

         42 = ( C5 )

         43 = ( 5B )

         44 = ( 30 )

 

Jawaban :

 

         MOV R0 , # 40H ; pointer mengisi

         MOV R2 , # 5 ; mengisi konter

         CLR A

         MOV R7 , A; R7 Batal

LAGI : ADD A , @ R0 ; Tambahkan A dengan R0 dilantik byte

         JNC LEBIH : Jika DY = 0 jangann ditambhakan

         INC R7 , tetap membawa sebagai kelebiihan

LEBIH : INC R0 ; pointer Kenaikan

         DJNZ R2 , LAGI ; ulagi mencapai R2 = 0

 

Page 13: Aritmatika PLC

 

Analisis contoh 6-2

 

Ada tiga proses dalam lingkaran seperti yang ditunjukkan gambar pda atas. Program

pembelajaran sebenarnya tergantung dari berapa banyak kita berlatih .

1 . 7DH ( isi memori 40H ) ditambahkan ke A dengan membawa = 0 dan R7 = 0 , dan isi counter

R2 = 04 .

2 . Keduanya. EBH ( isi memori 41H ) ditambahakn menyalakan A , yang membuat A == 68H

dan CY = 1 . karena ada Carry , sekarang -kenaikan R7 . Dan sekarang Kontra R2 = 3 .

3 . kemudian C5h ( isi memori 42h ) ditambahkan ke A. Yang membuat A = 2DH dan lagi ada

membawa, di -increment R7 . Dan sekarang , R2 = 2 .

 

Pada saat loop berakhir . Hasil penjumlahan pada A dan R7 , dimana A adalah byte rendah ,

byte tinggi R7 adalah .

 

 

ADDC dan penjumlahan dari jumlah 16 - bit

 

Ketika kita melakukan penjumlahan dua angka 16 - bit , kita harus memperhatikan status " hold "

dari Carry dari rendah - byte -byte tinggi . Instruksi ADDC ( Add dengan Carry ) dapat digunakan

untuk peduli . Sebagai contoh, lihat penjumlahan 3CE7h + 3B8Dh , seperti di bawah ini .

 

       1

      3C E7

      8D 3B +

Page 14: Aritmatika PLC

      78 74

 

Ketika byte pertama dikumpulkan ( E7 + 8D = 74 , CY = 1 ) . Carry adalah status " hold" untuk

byte berikutnya , membuat + 3B + 1 = 78 ( semua dalam hex ) . Contoh 3C 6-3 di bawah ini

menunjukkan langkah-langkah di atas dalam program 8051 .

 

contoh 6-3

 

Menulis sebuah program untuk penambahan sejumlah 16 - bit . 3CE7h dan 3B8Dh numerik .

Tempatkan jumlah dalam R7 dan R6 , R6 serendah - byte .

 

Jawaban :

 

         CLR C ; membuat CY = 1

         MOV A , # 0E7h , mengisi rendah - byte

         ADD A , # 8DH : add , hasilnya A = 74h dan CY = 1

         MOV R6 , A; tetap rendah byte penjumlahan

         MOV A , # 3CH , isi dengan tinggi byte

         ADDC A , # 3BH , menambahkan bersama-sama melakukan

         MOV R7 , A; toko hasilnya ( high- byte ) di R7

 

 

 

Page 15: Aritmatika PLC

Sistem nomor BCD ( Kode Biner Desimal )

 

BCD singkatan Kode Biner Desimal . BCD dibutuhkan karena dalam kehidupan sehari-hari kita

sering menggunakan digit 0 s / d 9 menyebutkan nomor , tidak biner atau heksadesimal . Adalah

representasi dari jumlah digit biner 0 s / d 9 disebut BCD . Lihat foto 6-1 . Dalam buku-buku

tentang komputer , ada dua hal penting dalam jumlah BCD , yaitu (a ) Membongkar BCD , dan

( b ) BCD Dikemas .

 

 

BCD digit

0 0000

1 0001

2 0010

3 0011

4 0100

5 0101

6 0110

7 0111

8 1000

9 1001

 

Foto 6-1 BCD Kode

 

 

Page 16: Aritmatika PLC

BCD membongkar

 

Dalam BCD Membongkar , 4 - bit reprensentasi bawah adalah jumlah 0 s / d 9 , sementara yang

lain meninggalkan 4 - bit 0 . Contoh " 0000 1001 " dan " 0000 0101 " yang membongkar BCD

dari nomor 9 dan 5 . Unpancked membutukan BCD 1 byte memori atau register 8 - bit untuk

menyimpan data / jumlah BCD .

 

 

BCD dikemas

 

Dalam BCD Kemasan, setiap byte mengandung dua angka BCD di dalamnya , 4- bit ada di

bagian bawah , dan yang lain 4 - bit ada di bagian atas. Misalnya, " 0101 1001 " dikemas BCD

59H nomor. Dengan demikian dibutuhkan byte memori yang cukup untuk menampung dua

nomor BCD . Jelas kasus yang dibuat lebih efisien dalam penyimpanan data BCD dua kali lebih

baik .

Banyak pertanyaan yang muncul dalam jumlah agregasi adalah BCD , koreksi - koreksi selalu

dibutuhkan sehingga penjumlahan adalah seperti yang kita harapkan . Hal ini karena CPU

menambahkan dua Data BCD seperti penjumlahan biasa, sebagai nomor unsigned , sehingga

akan membuat hasil tidak jumlah BCD . Lihat contoh di baah ini

 

      MOV A , # 17h

      ADD A , # 28H

 

Menjumlahkan dua angka akan menghasilkan 0011 1111b ( 3Fh ) di mana itu bukan jumlah BCD

. Tentu saja, karena jumlah digit BCD harus memiliki 0000 - 0101 ( 0-9 ) . Dengan kata lain ,

idealnya total untuk jumlah BCD BCD bilngan kita akan mendapatkan pula . Seharusnya hasil

adalah 17 + 28 = 45 ( 0100 0101 ) . Nah untuk memperbaiki masalah di atas , programmer harus

menambahkan 6 ( 0110 ) di bagian bawah 4- bit , hingga hasil sebelumnya yaitu 3F + 06 = 45 .

Nah ini seperti yang kita harapkan . Hal yang sama bisa terjadi dalam 4 -bit up . Misalnya, 52H +

87H = D9h . Sekali lagi kami meningkatkan hasil dengan menambahkan angka 6 di atas 4 - bit ,

D9h + 60H = 139h . Melihat bahwa 52 + 87 = 139 . Perhatikan bahwa jumlah 4 - bit atau 4 -bit di

Page 17: Aritmatika PLC

atas hasilnya , jika lebih besar dari 9 harus meningkat sebesar 6 untuk mendapatkan hasil yang

benar . Tapi 8051 telah mencegah kita dari gangguan - gangguan tersebut . 8051 memiliki

instruksi yang dapat mendeteksi nible ( 4 -bit ) , apa yang lebih besar dari 9 , dan akan

meningkat 6 jika itu benar . Perintah " DA " The Decimal Penyesuaian . Instruksi DA memiliki

hanya satu sintaks saja, yaitu ..

 

A DA

 

, Yang berfungsi untuk mempertanyakan penjumlahan Koreksi nomor BCD seperti yang kita

kenal di .

 

 

instruksi DA

 

Instruksi DA ( Decimal Adjust for Penambahan ) di 8051 adalah dapat digunakan untuk

memperbaiki masalah yang timbul sehubungan denga penjumlahan BCD number.And perintah

ini hanya operan akumulator " A " . Instruksi ini akan menambah 6 di bawah atau nible nible

pada jika diperlukan , tetapi jika tidak , tidak akan dirubah nible . Contoh di bawah ini akan

menjelaskan .

 

      MOV A , # 47h , A = 47h pertama BCD

      MOV B , # 25H , B = 25H kedua BCD

      ADD A , B , hasilnya adalah 6CH

      DA A; meningkatkan menjadi 72h

 

Setelah program ini dilaksanakan , register saat ini berisi 72h ( 47 + 25 = 72 ) . Instruksi DA

bekerja hanya pada A. Dengan kata lain , jika mereka ingin memperbaiki jumlah mendaftar

Page 18: Aritmatika PLC

mendaftar BCD di sisi lain kita harus bergerak di first.and juga harap dipahami , bahwa untuk

digunakan setelah Instruksi perintah DA nomor BCD penjumlahan , yang tidak diperlukan

pendapatan lebih dari 9 digit angka , seperti A s / d F. yang paling penting adalah status CY dan

AC DA detik sebelum instruksi dieksekusi .

Terkadang kita ingin Meng -kenaikan atau penurunan jumlah instruksi dalam BCD . Melarang

buku kita menggunakan INC atau Desember sebelum DA , untuk melakukan yang.Ini ingat INC

dan instruksi Desember tidak mempengaruhi bendera sehingga mungkin hasilnya ke dalam satu

operasi . Handbook menyarankan agar kita menggunakan " ADD A , # 01h " sebagai penerus

INC , dan " ADD A , # 99h " sebagai penggantinya Desember .

 

 

Ringkasan dari DA

 

Instruksi ini dilakukan setelah perintah ADD atau ADDC dan ..

1 . jika nible bawah lebih besar dari 9 , atau jika AC = 1 , nible ditambahkan di bawah 6 .

2 . nible atas jika lebih besar dari 9 , atau jika CY = 1 , nible tersebut ditambahkan 6 .

 

Kita bisa tahu bahwa kita tidak pernah menggunakan AC kecuali menjumlahan dan nomor BCD

dikoreksi manajemen . Misalnya, menambahkan 18h 29h dan 41H akan membuat di sana, yang

jelas bukan hasil yang diinginkan sebagai penjumlahan dari jumlah BCD .

 

      hex BCD

      29 0010 1001

      18 + 1000 + 0001

      41 0100 0001 AC = 1

      6 + 0110 +

Page 19: Aritmatika PLC

      47 0010 1001

 

karena AC = 1 , setelah penjumlahan " DA A " akan menambah 6 sampai nible bawah . Hasilnya

kemudian adalah bahwa jumlah format BCD kita harapkan .

 

Instruksi DA jadi ini sangat berguna dan sangat penting bagi kita untuk memproses Format BCD

data.

 

contoh 6-4

 

Misalkan ada sejumlah data BCD disimpan dalam RAM dari lokasi 40H seperti ini. Tulis program

untuk menemukan jumlah semua nomor . Hasilnya juga harus BCD .

 

         40 = ( 71 )

         41 = ( 11 )

         42 = ( 65 )

         43 = ( 59 )

         44 = ( 37 )

 

Jawaban :

 

         MOV R0 , # 40H ; pointer mengisi

         MOV R2 , # 5 ; mengisi konter

Page 20: Aritmatika PLC

         CLR A

         MOV R7 , A; R7 Batal

LAGI : ADD A , @ R0 ; Tambahkan A dengan R0 dilantik byte

         DA A; Adjust for BCD

         JNC LEBIH : Jika DY = 0 tidak menambahkan

         INC R7 ; tetap membawa tepi murah ( yang 100H )

LEBIH : INC R0 ; pointer Kenaikan

         DJNZ R2 , LAGI ; ulagi mencapai R2 = 0

 

 

 

 

Pengurangan jumlah bertanda

 

      SUBB A , sumber : A = A - Sumber - CY

 

Dalam banyak prosesor ada dua perbedaan pengurangan ketertiban dan SUBB SUB

( Pengurangan dengan meminjam ) . Pada 8051 kami disediakan hanya Subb . Tapi jangan

kecewa karena kita bisa Subb difungsikan sebagai SUB . Yaitu untuk membuat / pastikan CY = 0

sebelum pesanan Subb diimplementasikan . Jadi ada dua hal dalam SUBB yaitu ( a) CY

sebelumnya = 0 , dan ( b ) sebelumnya CY - 1 . Pertama kita akan membahas sebelum SUBB

CY = 0 .

 

 

Page 21: Aritmatika PLC

SUBB ( kurangi dengan meminjam ) ketika CY = 0

 

SUBB dengan CY sebelumnya = 0 , juga dapat dianggap SUB . Hal ini karena sebelumnya

Pinjam dianggap batal , atau tidak ada . Sampai SUBB menjadi SUB , kami sebelumnya

dianjurkan untuk men-download CY jelas ya .

 

Dalam mitigasi , 8051 microprosessor seperti CPU modern lainnya menggunakan metode

komplemen 2 itu . Itu karena setiap CPU menggunakan terlalu banyak y transistor di dalamnya

untuk Adder ( penambah ) , akan jauh lebih dari setiap CPU juga dilengkapi jaringan transistor

terpisah menurun. Oleh karena CPU modern menggunakan penambah sama yang digunakan

oleh agregasi pesanan , dengan sedikit modifikasi tambahan . Adapun proses Subb akhirnya

adalah sebagai berikut

 

1 . Untuk komplemen 2 tentang pengurang ( source) .

2 . Tambahkan (ADD ) pada berkurangnya jumlah ( A ) .

3 . Status Pengembalian CY

 

Tapi kita bisa tenang , semua dilakukan oleh perangkat keras dalam rangka Subb 8051 . Sampai

rangka Subb dapat dengan mudah digunakan oleh kami , seperti menggunakan perintah

lainnnya . Terlepas dari kenyataan itu adalah proses yang rumit . Kami hanya cukup untuk tahu

di mana berkurang , yang mengurangi , dan status CY , ditambah hasil harus di mana .

 

contoh 6-5

 

Tampilkan 3 langkah proses seperti yang dijelaskan sebelumnya , untuk di bawah program ini .

 

            CLR C ; membuat CY = 0

Page 22: Aritmatika PLC

            MOV A , # 3Fh , mengisi 3Fh dalam A ( A = 3Fh )

            MOV R3 , # 23h ; 23h mengisi di R3 ( R3 = 23h )

            SUBB A , R3 , pengurangan A - R3 , menghasilkan

 

Jawaban :

            A = 3F 0011 1111 0011 1111

            R3 = 23 0010 0011 + 1101 0011 2 ini Komplemen

                 1C 1 0001 1100

                                     0 CY = 0 ( langkah 3 )

 

Flags akan .. CY = 0 , AC = 0 , dan kita harus memeriksa kondisi Carry untuk menemukan hasil

yang positif atau negatif .

 

 

Jika setelah SUBB , CY = 0 berarti hasilnya adalah angka positif , tetapi jika CY = 1 maka

hasilnya adalah negatif. Hasil negatif dalam bentuk komplemen 2 itu. Skala angka negatif bisa

kita dapatkan dengan menggunakan CPL ( pelengkap ) dan INC ( Increment ) dari temuan .

Sebagai contoh, jika kita mendapatkan -22 , kemudian menggunakan dua arah instruksional kita

akan mendapatkan 22 dari nomor -22 . Lihat contoh 6-6

 

contoh 6-6

 

Anda memberikan program berikut .

 

Page 23: Aritmatika PLC

            CLR C ; membuat CY = 0

            MOV A , # 62H ; mengisi 62H A ( A = 3Fh )

            SUBB A , # 6EH , pengurangan A - 6EH

            LEBIH JNC , jika CY = 0 kemudian melompat

            CPL A , jika CY = 1 untuk Komplemen 1 yang

            INC A; Kemudian untuk Komplemen 2 ini

LEBIH : MOV R1 , A; Save A pada R1

 

Jawaban :

 

Berikut adalah langkah-langkah untuk " SUBB A , 6EH " .

        4C 0100 1100 0100 1100

        Pelengkap 6E 0110 1110 2 ini = 1001 0010 +

       -22 0 1101 1110

 

CY = 1 , hasilnya negatif , Komplemen 2 itu .

 

 

 

SUBB ( kurangi dengan meminjam ) ketika CY = 1

 

Page 24: Aritmatika PLC

Instruksi SUBB dapat digunakan untuk melakukan pengurangan multibyte , dengan

memperhatikan meminjam bendera ( ingat Subb , yang juga bernama Pinjam bendera CY ) .

Artinya meminjam adalah berarti " meminjam " dari kecil operan lantai . Lihat contoh 6-7

 

contoh 6-7

 

Anda memberikan program berikut .

 

            CLR C ; membuat CY = 0

            MOV A , # 62H ; mengisi 62H A ( A = 3Fh )

            SUBB A , # 96h , pengurangan A - 96h = CCH dengan CY = 1

            MOV R7 , A; toko menghasilkan R7

            MOV A , # 27H ; A = 27H

            SUBB A , # 12h , A = 27H - 12h - 1 = 14h (ingat status CY )

            MOV R6 , A; menjaga hasil lain

 

Jawaban :

 

Setelah SUBB , A = 62 -96 = CCH , dan CY ke 1, yang menunjukkan jumlah meminjam .

Mengingat CY = 1 , dan ketika Subb dilakasanakn kedua kalinya . A = 27H - 12h = 14h -1 .

Sampai dorongan untuk tegas hasilnya 2762h - 14CC = 14CCh

 

 

 

Page 25: Aritmatika PLC