Docsity

Fundamentals of Microcontrollers: Decrease Operations with SUBA in Hex and Decimal - Prof., Study notes of Mechanical Engineering

Toggle sidebar
bg1
EMCH 367 Fundamentals of Microcontrollers Example 8
EXAMPLE 8
OBJECTIVE
This exercise has the following objectives:
Introduce decrease (SUBA)
Review decimal borrow concepts using decrease
Introduce hex borrow using decrease
Introduce 2’s complement negative hex numbers as decrease of zero with free borrow
Show the 2-digit 2's complement negative hex numbers
Show the decimal equivalent of the 2-digit hex decrease of zero and of
2-digit 2's complement negative hex numbers
Note: To facilitate understanding, the same numbers are used in both decimal and the hex cases.
PROGRAM
The program ex8.asm performs the following arithmetic operations:
i) 7 – 1 = 6 (decimal) using the opcode mnemonics LDAA, SUBA
ii) $07 - $01 = $06 (hex) using the opcode mnemonics LDAA, SUBA
iii) 10 - 1 = 9 (decimal) using the opcode mnemonics LDAA, SUBA
iv) $10 - $01 = $0f (hex) using the opcode mnemonics LDAA, SUBA
v) $00 - $01 = $ff (hex) using the opcode mnemonics LDAA, SUBA
vi) 0 - 1 = 255 (decimal equivalent of 2-digit hex arithmetic) using the opcode mnemonics LDAA,
SUBA
CODING AND EXECUTION
Open THRSim11. Maximize THRSim11 window. Close the Commands window. Open ex8.asm.
Assemble, tile the windows, set the breakpoint, and reset the registers. Your screen looks like this:
Dr. Victor Giurgiutiu Page 1 11/30/2020
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Fundamentals of Microcontrollers: Decrease Operations with SUBA in Hex and Decimal - Prof. and more Study notes Mechanical Engineering in PDF only on Docsity!

EXAMPLE 8

OBJECTIVE

This exercise has the following objectives:  Introduce decrease (SUBA)  Review decimal borrow concepts using decrease  Introduce hex borrow using decrease  Introduce 2’s complement negative hex numbers as decrease of zero with free borrow  Show the 2-digit 2's complement negative hex numbers  Show the decimal equivalent of the 2-digit hex decrease of zero and of 2-digit 2's complement negative hex numbers Note: To facilitate understanding, the same numbers are used in both decimal and the hex cases.

PROGRAM

The program ex8.asm performs the following arithmetic operations: i) 7 – 1 = 6 (decimal) using the opcode mnemonics LDAA, SUBA ii) $07 - $01 = $06 (hex) using the opcode mnemonics LDAA, SUBA iii) 10 - 1 = 9 (decimal) using the opcode mnemonics LDAA, SUBA iv) $10 - $01 = $0f (hex) using the opcode mnemonics LDAA, SUBA v) $00 - $01 = $ff (hex) using the opcode mnemonics LDAA, SUBA vi) 0 - 1 = 255 (decimal equivalent of 2-digit hex arithmetic) using the opcode mnemonics LDAA, SUBA

CODING AND EXECUTION

Open THRSim11. Maximize THRSim11 window. Close the Commands window. Open ex8.asm. Assemble, tile the windows, set the breakpoint, and reset the registers. Your screen looks like this:

SECTION: $07 - $01 = $06 (HEX) USING THE OPCODE MNEMONICS LDAA, SUBA

Set accA display to hex. Step through section ii) of the code. At the end of this section, your screen looks like this: During the execution of this section, hex number $07 was loaded into accA, and decreased by 1 to become $06. During the decrease, hex borrow did not need to happen.

SECTION: 10 - 1 = 9 (DECIMAL) USING THE OPCODE MNEMONICS LDAA, SUBA

Set accA display to decimal. Step through section iii) of the code. At the end of this section, your screen looks like this: During the execution of this section, decimal number 10 was loaded into accA, and decreased by 1 to become 9. During the decrease, decimal borrow happened because the LSD was 0.

SECTION: $00 - $01 = $FF (HEX) USING THE OPCODE MNEMONICS LDAA, SUBA

Set accA display to hex. Step through section v) of the code. At the end of this section, your screen looks like this: During the execution of this section, hex number $00 was loaded into accA, and decreased by 1 to become $ff. During the decrease, hex borrow happened because the LSD was 0. Since MSD was also 0, a ‘free borrow’ beyond the MSD happened. Hence, the result of $00-$01 is the same as the result of $000+$100-$001=$0ff, i.e. $ff.

SECTION: 0 - 1 = 255 (DECIMAL EQUIVALENT OF 8-BIT HEX ARITHMETIC) USING THE OPCODE

MNEMONICS LDAA, SUBA

Set accA display to decimal. Step through section vi) 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 decreased by 1 to become 255. We notice that the operation is equivalent to 0+256-1=255. This indicates that, although the operation was displayed in decimal, a hex free borrow actually happened, since 256=$100.

USING CALCULATOR TO OBTAIN HEX NEGATIVE NUMBERS FOR –

Use your calculator to find the HEX equivalent of negative decimal number –100. Type –100 into your calculator, and convert to hex. After you have done this, you will see hex number F…FFF9C in your screen. (The number of F depends on the maximum display length of your calculator.) The last two digits, 9C, are the hex negative number of –100.

(This page is left intentionally blank)

EMCH 367 Fundamentals of Microcontrollers qkd5nb-825823-3288337-h-20example8-doc.doc