lec 10 microprocessor and microcontroller.pptx

11
MICROPROCESSOR AND MICROCONTROLLER SPRING 2013 Lecture 10: Arithmetic Instructions Muhammad Saqib Bhatti

Upload: syed-haleem

Post on 18-Dec-2015

218 views

Category:

Documents


3 download

TRANSCRIPT

Microcontroller: Interfacing & Programming

Microprocessor and MicrocontrollerSpring 2013Lecture 10: Arithmetic Instructions

Muhammad Saqib BhattiAgendaAddition of unsigned numbersAddition of 16-bit numbersAddition of BCD numbersSubtraction of unsigned numbers

2Adding unsigned numbers ADD A, operandAddressing mode for OperandImmediateADD A,#25HRegisterADD A,R3DirectADD A,30HRegister IndirectADD A,@R0CY is set if result exceeds FF H

Lecture 1033Adding a set of unsigned bytes Add 4 numbers which are saved in memory at following addressesAddress: 40H = Data: 7DAddress: 41 = Data: EBAddress: 42 = Data: C5Address: 43 = Data: 5BMOV R0, #40HMOV R2, #4CLR AMOV R7, AAGAIN: ADD A, @R0; A has lower byteJNC NEXTINC R7 ; R7 has upper byteNEXT: INC R0DJNZ R2, AGAIN

Lecture 1044Adding 16-bit Unsigned numbers ADDC A, operand Addressing mode for OperandImmediateADD A,#25HRegisterADD A,R3DirectADD A,30HRegister IndirectADD A,@R0Add 3CE7 and 3B8DCLR CMOV A, #0E7HADD A, #8DHMOV R6, AMOV A, #3CHADDC A, #3BHMOV R7, A

Lecture 1055Adding BCD NumbersUnpacked BCDLower 4-bits represent BCD numberUpper 4-bits all zerosBCD 5 is 00000101Packed BCDSingle Byte has two BCD numbersBCD 56 is 01010110Lecture 1066Adding BCD NumbersAdding packed BCD numbers results in errorBCD 56 + BCD 37 should be BCD 93BCD 56 + BCD 37 is 8DDA A instruction adds 6 to correct BCD.Why 6???8D + 6 = 93MOV A, #56HADD A, #37HDA ADA instruction works after ADD instructionDA instruction does not work after INC

Lecture 1077Subtraction of Unsigned NumbersSUBB A, operand A = A source CYAddressing mode for OperandImmediateSUBB A,#25HRegisterSUBB A,R3DirectSUBB A,30HRegister IndirectSUBB A,@R0SUBB instruction performs takes 2s complement of operandadds 2s complement to AInverts CYLecture 1088Subtraction of Unsigned NumbersCLR CMOV A, #4CHMOV R3, #6EHSUBB A, R3

A = 0100 11000100 1100R3 = 0110 1110 C1001 0010 2s com 1101 1110 0 1101 1110 1Lecture 1099Subtraction of Unsigned NumbersSubtract 1296 from 2762CLR CMOV A, #62HSUBB A, #96H; 62H 96H = CCH CY=1MOV R7, AMOV A, #27HSUBB A, #12H; 27H 12H 1 = 14HMOV R6, A

Lecture 101010Special Thanks to Dr. Waseem Ikram for the lectures11