Unformatted text preview:

Example 9Objectiveprogramcoding and executionSection: $0d - $06 = $07 (hex) using the opcode mnemonics LDAA, LDAB, SBASection: $00 - $05 = $fb (hex) using the opcode mnemonics LDAA, LDAB, SBASection: 0 - 5 = 251 (decimal equivalent of 8-bit hex arithmetic) using the opcode mnemonics LDAA, LDAB, SBASection: $0e - $3a = $d4 (hex) using the opcode mnemonics LDAA, LDAB, SBASection: 14 - 58 = 212 (decimal equivalent of 8-bit hex arithmetic) using the opcode mnemonics LDAA, LDAB, SBAWhat you have learnedEMCH 367 Fundamentals of Microcontrollers Example 9EXAMPLE 9OBJECTIVEThis exercise has the following objectives:- Introduce hex subtraction- Introduce hex subtraction with negative results using the free borrow concept.- Show the decimal equivalent of hex subtraction with negative results using free borrow.Note: To facilitate understanding, the same numbers are used in both decimal and the hex cases.PROGRAMThe program ex9.asm performs the following arithmetic operations:I. $0d - $06 = $07 (hex) using the opcode mnemonics LDAA, LDAB, SBAII. $00 - $05 = $fb (hex) using the opcode mnemonics LDAA, LDAB, SBAIII. 0 - 5 = 251 (decimal equivalent of 8-bit hex arithmetic) using the opcode mnemonics LDAA,LDAB, SBAIV. $0e - $3a = $d4 (hex) using the opcode mnemonics LDAA, LDAB, SBAV. 14 - 58 = 212 (decimal equivalent of 8-bit hex arithmetic) using the opcode mnemonics LDAA,LDAB, SBADr. Victor Giurgiutiu Page 1 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 9CODING AND EXECUTIONOpen THRSim11. Maximize THRSim11 window. Close the Commands window. Open ex9.asm.Assemble, tile the windows, set the breakpoint, and reset the registers. Your screen looks like this:Dr. Victor Giurgiutiu Page 2 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 9SECTION: $0D - $06 = $07 (HEX) USING THE OPCODE MNEMONICS LDAA, LDAB, SBALoad and assemble ex9.asm. Set accA display to hex. Step through section vii) of the code. At the endof this section, your screen looks like this:During the execution of this section, hex number $0d was loaded into accA, hex number $06 wasloaded into accB, and then accB was subtracted from accA. The result of the arithmetic operationremained in accA. The result was $07. A hex borrow did not happen, since the number in accB wasless than the number in accA, and the LSD of the number in accB was also less than the LSD of thenumber in accA.Dr. Victor Giurgiutiu Page 3 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 9SECTION: $00 - $05 = $FB (HEX) USING THE OPCODE MNEMONICS LDAA, LDAB, SBASet accA accB displays to hex. Step through section viii) of the code. At the end of this section, yourscreen looks like this:During the execution of this section, hex number $00 was loaded into accA, hex number $05 wasloaded into accB, and then accB was subtracted from accA. The result of the arithmetic operationremained in accA. The result was $fb. This is equivalent to the hex operation $000+$100-$005=$0fb,and indicates that a hex free borrow happened.Dr. Victor Giurgiutiu Page 4 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 9SECTION: 0 - 5 = 251 (DECIMAL EQUIVALENT OF 8-BIT HEX ARITHMETIC) USING THE OPCODE MNEMONICS LDAA, LDAB, SBASet accA and accB displays to decimal. Step through section ix) of the code. At the end of this section,your screen looks like this:During the execution of this section, decimal number 0 was loaded into accA, and decimal number 5into accB. Then, accB was subtracted from accA. The result of the subtraction remained in accA. Theresult was 251. We notice that the following decimal arithmetic operation happened 0-5=251. Thisoperation is equivalent to 0+256-1=255. This indicates that, although the operation was displayed indecimal, a hex free borrow actually happened since 256=$100.Dr. Victor Giurgiutiu Page 5 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 9SECTION: $0E - $3A = $D4 (HEX) USING THE OPCODE MNEMONICS LDAA, LDAB, SBASet accA accB displays to hex. Step through section x) of the code. At the end of this section, yourscreen looks like this:During the execution of this section, hex number $0e was loaded into accA, hex number $3a wasloaded into accB, and then accB was subtracted from accA. The result of the arithmetic operationremained in accA. The result was $d4. This is equivalent to the hex operation $00e+$100-$03a=$0d4,and indicates that a hex free borrow happened.Dr. Victor Giurgiutiu Page 6 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 9SECTION: 14 - 58 = 212 (DECIMAL EQUIVALENT OF 8-BIT HEX ARITHMETIC) USING THE OPCODE MNEMONICS LDAA, LDAB, SBASet accA and accB displays to decimal. Step through section xi) of the code. At the end of this section,your screen looks like this:During the execution of this section, decimal number 14 was loaded into accA, and decimal number 58into accB. Then, accB was subtracted from accA. The result of the subtraction remained in accA. Theresult was 212. We notice that the following decimal arithmetic operation happened 14-58=212. Thisoperation is equivalent to 14+256-58=212. This indicates that, although the operation was displayed indecimal, a hex free borrow actually happened since 256=$100.Dr. Victor Giurgiutiu Page 7 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 9WHAT YOU HAVE LEARNEDIn this exercise, you have learned:- Subtraction using SBA opcode mnemonic happened as expected, in both decimal and hexarithmetic, as long as the minuend is greater than the subtrahend (e.g., 13-6=7, $0d-$06=$07). - When the minuend is less than the subtrahend, the result of the subtraction operation iscalculated using a free borrow (e.g., $0e-$3a=$00e+$100-$03a=$0d4=$d4). - Even if decimal display of numbers is used, the calculations and the free borrow still happen inhex (e.g., 14-58=14+256-58=212, where 256=$100).- New words and notations: subtraction, minuend, subtrahend.Dr. Victor Giurgiutiu Page 8 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 9Dr. Victor Giurgiutiu Page 1


View Full Document

SC EMCH 367 - EMCH 367 Study Notes

Download EMCH 367 Study Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view EMCH 367 Study Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view EMCH 367 Study Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?