mechatronics engineering basis, Lecture notes of Mechatronics

arthematic operations subtaction and relative features

Typology: Lecture notes

2018/2019

Uploaded on 06/22/2019

sohail2210
sohail2210 ๐Ÿ‡ต๐Ÿ‡ฐ

1 document

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Arithmetic Operations (Subtraction):
The 8085 microprocessor performs subtraction by using the method of
2โ€™s compliment.
o
(1)
The 8085 performs the following steps internally when executing the
instruction SUB/SUI
๏‚งConverts subtrahend into its 1โ€™s complement.
๏‚งAdds 1 to 1โ€™s complement to obtain 2โ€™s complement of the
subtrahend.
๏‚งAdd 2โ€™s complement to the minuend
๏‚งComplement the Carry Flag.
Example: Register B has 65H & the accumulator has 97H. Subtract the
contents of register B from the contents of accumulator.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download mechatronics engineering basis and more Lecture notes Mechatronics in PDF only on Docsity!

Arithmetic Operations (Subtraction):

The 8085 microprocessor performs subtraction by using the method of 2โ€™s compliment.

o

(1)

The 8085 performs the following steps internally when executing the instruction SUB/SUI ๏‚ง Converts subtrahend into its 1โ€™s complement. ๏‚ง Adds 1 to 1โ€™s complement to obtain 2โ€™s complement of the subtrahend. ๏‚ง Add 2โ€™s complement to the minuend ๏‚ง Complement the Carry Flag.

Example: (^) Register B has 65H & the accumulator has 97H. Subtract the contents of register B from the contents of accumulator.

Instruction: SUB B ๐‘ซ๐Ÿ• ๐‘ซ๐Ÿ” ๐‘ซ๐Ÿ“ ๐‘ซ๐Ÿ’ ๐‘ซ๐Ÿ‘ ๐‘ซ๐Ÿ ๐‘ซ๐Ÿ ๐‘ซ๐ŸŽ Subtrahend (B) : 65H = 0 1 1 0 0 1 0 1 Step1: 1โ€™s Complement of 65H = 1 0 0 1 1 0 1 0 Step2: + Add 01 to obtain 0 0 0 0 0 0 0 1 2โ€™s Complement of 65H 1 0 0 1 1 0 1 1 To subtract: 97H โ€“ 65H +

Add 97H to 2โ€™s complement 1 0 0 1 0 1 1 1 of 65H 1 1 1 1 1 Carry Step3: CY: 1 0 0 1 1 0 0 1 0 Step4: Complement Carry CY: 0 Result (A) : 32H Flags Status: S = 0, Z = 0, CY = 0

Note: If the answer is โ€“tive, it will be shown in 2โ€™s complement of the actual magnitude with the Carry (Borrow) flag set.

To execute the instruction SUB C, the microprocessor performs the following steps internally: ๐‘ซ๐Ÿ• ๐‘ซ๐Ÿ” ๐‘ซ๐Ÿ“ ๐‘ซ๐Ÿ’ ๐‘ซ๐Ÿ‘ ๐‘ซ๐Ÿ ๐‘ซ๐Ÿ ๐‘ซ๐ŸŽ Subtrahend (C) : 39H = 0 0 1 1 1 0 0 1 Step1: 1โ€™s Complement of 39H = 1 1 0 0 0 1 1 0 Step2: + Add 01 to obtain 0 0 0 0 0 0 0 1 2โ€™s Complement of 39H 1 1 0 0 0 1 1 1 To subtract: 30H โ€“ 39H + Step3: Add 30H to 2โ€™s complement 0 0 1 1 0 0 0 0 of 39H Carry CY: 0 1 1 1 1 0 1 1 1 Step4: Complement Carry CY: 1 Result (A) : F7H Flags Status: S = 1, Z = 0, CY = 1

Note: F7H is a 2โ€™s complement of the magnitude (39H-30H=09H)

Logic Operations:

The 8085 microprocessor is basically a programmable logic chip. It can perform all the logic functions of the hard-wired logic through its instruction set.

(2)

o The 8085 opcodes of the above said operations are as follows: ๏‚ง ANA: AND Logically AND the contents of a register. ๏‚ง ANI: AND Immediate Logically AND 8-bit data. ๏‚ง ORA: OR Logically OR the contents of a register. ๏‚ง ORI: OR Immediate Logically OR 8-bit data. ๏‚ง XRA: X-OR Exclusive-OR the contents of a register. ๏‚ง XRI: X-OR Immediate Exclusive-OR 8-bit data.

(3)

Logic AND:

The process of performing logic operations through the software instructions is slightly different from the hardware logic.

(4)

The AND gate in Fig (a) above has two inputs and one output, while the instruction ANA simulates 08 AND gates as shown in Fig (b) above. Each bit of register B is independently ANDed with each bit of the accumulator. Thus, simulating 08 2-input AND gates.

Illustrative Program: Data Masking with Logical AND

Problem Statement: Write a program to perform the following: ๏‚ง Turn ON the A/C if switch ๐‘† 7 of the input port 00H is ON. ๏‚ง Ignore all other switches of the input port even if someone attempts to turn ON other appliances.

Problem Analysis: ๏‚ง We are interested in only one switch i.e. switch ๐‘† 7 If some other switches are also ON such as: the radio (๐‘† 4 ), the lights (๐‘†3,๐‘†2,๐‘†1,๐‘† 0 ). ๏‚ง The microprocessor can read the input port 00H as IN 00H, then accumulator will have the data byte as 9FH. This can be simulated by using the instruction as: MVI A, 9FH ๏‚ง If we only want to know whether switch ๐‘† 7 is ON, bits ๐ท 6 to ๐ท 0 have been masked by ANDing the input data with a byte as follows: ๐‘ซ๐Ÿ• ๐‘ซ๐Ÿ” ๐‘ซ๐Ÿ“ ๐‘ซ๐Ÿ’ ๐‘ซ๐Ÿ‘ ๐‘ซ๐Ÿ ๐‘ซ๐Ÿ ๐‘ซ๐ŸŽ 1 0 0 0 0 0 0 0 = 80H The remaining byte can be sent to the output port to simulate turning ON the A/C unit.

Program Output: The instruction ANI 80H ANDs the accumulator data as follows: ๐‘ซ๐Ÿ• ๐‘ซ๐Ÿ” ๐‘ซ๐Ÿ“ ๐‘ซ๐Ÿ’ ๐‘ซ๐Ÿ‘ ๐‘ซ๐Ÿ ๐‘ซ๐Ÿ ๐‘ซ๐ŸŽ (A) = 1 0 0 1 1 1 1 1 (9FH) AND (Masking Byte) 1 0 0 0 0 0 0 0 (80H) (A) = 1 0 0 0 0 0 0 0 (80H) Flags Status: S = 1, Z = 0, CY = 0

Note: The AND ing operation always resets the CY flag. The result is sent to output port, and logic 1 of data bit ๐ท 7 turns ON the A/C.

OR, Exclusive-OR, and NOT: The instruction ORA (and ORI) simulates logic ORing with 08 2-input OR gates. The instruction XRA (XRI) performs Exclusive-ORing of eight bits, and the instruction CMA inverts the bits of the accumulator. o (5)

1. The instruction ORA B will perform the following operation: (B) : 93H = 1 0 0 1 0 0 1 1 OR (A) : 15H = 0 0 0 1 0 1 0 1 (A) : 97H 1 0 0 1 0 1 1 1 Flags Status: S = 1, Z = 0, CY = 0

  1. The instruction XRA B will perform the following operation: (B) : 93H = 1 0 0 1 0 0 1 1 X-OR (A) : 15H = 0 0 0 1 0 1 0 1 (A) : 86H 1 0 0 0 0 1 1 0 Flags Status: S = 1, Z = 0, CY = 0

Note: The result 97H will be in the accumulator and the CY flag will be reset. And the other will be modified according to data conditions in the accumulator.

Example: Assume register B has 93H & the accumulator has 15H. Illustrate the results of instructions ORA B, XRA B, and CMA.

Example: Assuming its winter, and turn off the A/C without affecting the functions of other appliances, as shown in Fig. above Problem Analysis: To turn off the A/C, reset bit ๐ท 7 by ANDing the reading of the input port with the data byte 7FH as follows: IN 00H : (A) = ๐ท 7 ๐ท 6 ๐ท 5 ๐ท 4 ๐ท 3 ๐ท 2 ๐ท 1 ๐ท 0 ANI 7FH: = 0 1 1 1 1 1 1 1 (A) = 0 ๐ท 6 ๐ท 5 ๐ท 4 ๐ท 3 ๐ท 2 ๐ท 1 ๐ท 0

Flags Status: CY = 0; others will depend on the data condition. The instruction ANI resets bit ๐ท 7 without affecting other bits.

Illustrative Program: ORing Data from Two Input Ports. Problem Statement: Write a program to turn ON the devices from any of the two input ports attached to the microcomputer such as 00H (located in Kitchen) and 01H (located in Bedroom), each has eight switches as shown in Fig. Problem Analysis: To turn the appliances from any one of the input ports, the microprocessor needs to read the switches at both ports

Program Output: Logically ORing the data bytes in registers B and C: ๐‘ซ๐Ÿ• ๐‘ซ๐Ÿ” ๐‘ซ๐Ÿ“ ๐‘ซ๐Ÿ’ ๐‘ซ๐Ÿ‘ ๐‘ซ๐Ÿ ๐‘ซ๐Ÿ ๐‘ซ๐ŸŽ (B) โ†’ (A) = 1 0 0 1 0 0 0 1 (91H) (C) = 1 0 1 0 1 0 0 0 (A8H) (A) = 1 0 1 1 1 0 0 1 (B9H) Flags Status: S = 1, Z = 0, CY = 0

Note: The byte B9H is placed in the accumulator that turns on the A/C, radio, coffee pot, bedroom light, and kitchen light.

Important:

โ˜ž Logic operations are performed in relation to the contents of

accumulator, and thereby answer (result) is placed in accumulator.

โ˜ž Logic operations simulates eight 2-input logic gates (or inverters).

โ˜ž The Carry flag is reset; and the sign, Zero, and Parity flags are

modified according to the data condition of accumulator.

โ˜ž NOT operations does not affect any flag.

โ˜ž Logic operations canโ€™t be performed directly with the contents of

two registers.

(6)