# aritmatika plc

of 26 /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

Author: ikhtiardwi

Post on 25-Oct-2015

53 views

Category:

## Documents

Tags:

• #### mov r7

Embed Size (px)

DESCRIPTION

PLC

TRANSCRIPT

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 MARKEDInterpreted 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.3Addition Number Not SignedIn 8051, two additional process data, often involving accumulators.And ADD command format isADD A, source: A = A + sourceADD 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-1Example 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 = 0Answer: F5h 1111 0101F5h+1111 0101+ 100H 1111 0101After pejumlahan, register a destination) will contain 00 and bedera is as followsCY = 1 since there Carry out from D7PF = 1 because the number of 1s is REGARDING from 0 (zero).PF = 1AC = 1 because there is carry from D3 to D4

Addition to Single ByteIn 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 R7Example 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 ClearAGAIN: ADD A, @ R0; Add A with R0 inductee bytes JNC MORE: If DY = 0 jangann ditambhakan INC R7; keep carry as kelebiihanMORE: INC R0; Increment pointer DJNZ R2, AGAIN; ulagi reach R2 = 0

Analysis of example 6-2There 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-bitWhen 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 E78D 3B+ 78 74When 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)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.DigitBCD00000100012001030011401005010160110701118100091001

Photo 6-1 BCD CodeUnpacked BCDIn 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 BCDIn 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, # 28HSumming 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 DAInstruction 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 72hOnce 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 DAInstruction 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 100118+0001 1000+ 41 0100 0001 AC = 16+ 0110+ 47 0010 1001because 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 ClearAGAIN: 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

Reduction in the number of unmarked SUBB A, source: A = A - source - CYIn 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 = 0SUBB 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 follows1.For the 2's complement of the subtrahend (source).2.Add (ADD) on a reduced number of (A).3.Refund status of CYBut 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 aAnswer: A = 3F 0011 1111 0011 1111 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-6Example 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 ComplementMORE: MOV R1, A; Save A on the R1Answer:Here are the steps to "SUBB A, 6Eh". 4C 0100 1100 0100 11006E 0110 1110 2's Complement = 1001 0010+ -22 0 1101 1110CY = 1, the result is negative, the 2's Complement.

SUBB (SUBSTRACT with borrow) when CY = 1SUBB 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-7Example 6-7

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 resultsAnswer: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