Digit Decimal Arithmetic - Example #5 | EMCH 367, Study notes of Mechanical Engineering

Material Type: Notes; Professor: Giurgiutiu; Class: MICROCNTROLLRS MECH ENGR; Subject: Mechanical Engineering; University: University of South Carolina - Columbia; Term: Fall 2009;

Typology: Study notes

Pre 2010

Uploaded on 10/01/2009

koofers-user-idg-1
koofers-user-idg-1 🇺🇸

5

(1)

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EMCH 367 Fundamentals of Microcontrollers Example 5
EXAMPLE 5
OBJECTIVE
This simple example has the following objectives:
Review 2-digit decimal arithmetic with carry to prepare the ground for 2-digit hex arithmetic with
carry.
PROGRAM
Ex5.asm program is similar to ex3.asm, but uses numbers outside the 0 9 range. It performs the
arithmetic operation 9 + 8 = 17. To achieve this, the program does the following:
Load 9 into accA using LDAA, i.e., 9 A
Load 8 into accB using LDAB, i.e., 8 B
Add accA (i.e., 9) with accB (i.e., 8) A + B A A 17
EXECUTION
Open THRSim11. Maximize THRSim11 window. Close the Commands window. Open file Ex5.asm.
Assemble file. Tile windows. Set break point at the line containing SWI. Set the display of A, B registers
to ‘Decimal’. Reset registers D, X, Y. Your screen should look like this:
Dr. Victor Giurgiutiu Page 1 12/1/2020
pf3

Partial preview of the text

Download Digit Decimal Arithmetic - Example #5 | EMCH 367 and more Study notes Mechanical Engineering in PDF only on Docsity!

EXAMPLE 5

OBJECTIVE

This simple example has the following objectives:  Review 2-digit decimal arithmetic with carry to prepare the ground for 2-digit hex arithmetic with carry.

PROGRAM

Ex5.asm program is similar to ex3.asm, but uses numbers outside the 0 – 9 range. It performs the arithmetic operation 9 + 8 = 17. To achieve this, the program does the following:  Load 9 into accA using LDAA, i.e., 9  A  Load 8 into accB using LDAB, i.e., 8  B  Add accA (i.e., 9) with accB (i.e., 8) A + B  A A 17

EXECUTION

Open THRSim11. Maximize THRSim11 window. Close the Commands window. Open file Ex5.asm. Assemble file. Tile windows. Set break point at the line containing SWI. Set the display of A, B registers to ‘Decimal’. Reset registers D, X, Y. Your screen should look like this:

Use the ‘Step’ button to step through the program. Press the Step button once. The registers do not change. Press again. Number 9 is loaded into accA. Press again. Number 8 is loaded into accB. Press again. AccA and AccB are added together. The result, 17, appears in accA. The number 8 is still preserved in AccB. Your screen should look like this: During the addition 9 + 8 = 17, decimal arithmetic with carry has been performed. The numbers nine and eight, when added, give the number seventeen, which is greater than nine. Since the greatest number that can be represented with just one decimal digit is nine, a carry to the next level, tens, had to be enacted. In words: “nine plus eight makes seven carry one”. In symbols: 9 + 8 = 17.

WHAT YOU HAVE LEARNED

In this simple exercise, you have reviewing decimal arithmetic with carry to prepare the ground for understanding hex arithmetic with carry. The things that you have reviewed are:  The greatest number that can be represented with a single decimal digit is nine.  Numbers greater than nine are represented with two or more digits. For example, number seventeen is represented as 17, i.e. with two digits.  When the result of adding two decimal numbers is greater than nine, a carry takes place.  New words and notations: addition with carry.