Microcontroller Fundamentals: Assembly & Arithmetic with THRSim11 Simulator & Ex2.asm - Pr, Study notes of Mechanical Engineering

Instructions on how to use the thrsim11 simulator to understand the fundamentals of microcontrollers, specifically focusing on assembly language and arithmetic operations. An explanation of the objectives, program, and execution process of a simple example (ex2.asm) that performs the arithmetic operation 3 + 2 = 5 using the adda operation in immediate mode. It also covers how to open and customize the thrsim11 environment, assemble an .asm file, interpret an .lst file, set breakpoints, and step through the program simulation.

Typology: Study notes

Pre 2010

Uploaded on 10/01/2009

koofers-user-wlp
koofers-user-wlp 🇺🇸

10 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
EMCH 367 Fundamentals of Microcontrollers Example 2
EXAMPLE 2
OBJECTIVE
This simple example has the following objectives:
Familiarize the user with the THRSim11 simulator environment
Introduce the user to the syntax and concepts of Assembly (.asm) language
Familiarize the user the way arithmetic operations are handled by the microcontroller
Instruct the user to interpret the List (.LST) file.
Teach the user to perform the simulation and follow the step-by-step results.
Introduce ADDA operation
PROGRAM
Ex2.asm program is very simple. It performs the arithmetic operation 3 + 2 = 5 using the ADDA
operation in immediate mode. To achieve this, the program does the following operations:
Load the number 3 into accA using the opcode mnemonic LDAA with the operand #3, i.e., using
immediate mode.
Add the number in accA (which is 3) with the number 2 using the opcode mnemonic ADDA with
the operand #2. (Note that the immediate mode is again used.)
The symbolic representation of this process is:
3 A (immediate mode)
A + 2 A (immediate mode)
This signifies that number 3 is loaded into accA, number 2 is loaded into immediate memory, and the
content of accA is added to of memory with the result being put back into accA.
EXECUTION
1. Open THRSim11.
2. Maximize THRSim11 window.
3. Close the Commands window.
4. Open file Ex2.asm.
5. Assemble file by pressing the Assemble button.
During assembly, you must have inserted in the A: floppy disk drive with the file
VAR_DEF.ASM. In this way, the assembler will find the file path A:\VAR_DEF.ASM when
executing the Assembly directive #INCLUDE. Else, you get error.
Dr. Victor Giurgiutiu Page 1 11/30/2020
pf3
pf4
pf5

Partial preview of the text

Download Microcontroller Fundamentals: Assembly & Arithmetic with THRSim11 Simulator & Ex2.asm - Pr and more Study notes Mechanical Engineering in PDF only on Docsity!

EXAMPLE 2

OBJECTIVE

This simple example has the following objectives:  Familiarize the user with the THRSim11 simulator environment  Introduce the user to the syntax and concepts of Assembly (.asm) language  Familiarize the user the way arithmetic operations are handled by the microcontroller  Instruct the user to interpret the List (.LST) file.  Teach the user to perform the simulation and follow the step-by-step results.  Introduce ADDA operation

PROGRAM

Ex2.asm program is very simple. It performs the arithmetic operation 3 + 2 = 5 using the ADDA operation in immediate mode. To achieve this, the program does the following operations:  Load the number 3 into accA using the opcode mnemonic LDAA with the operand #3, i.e., using immediate mode.  Add the number in accA (which is 3) with the number 2 using the opcode mnemonic ADDA with the operand #2. (Note that the immediate mode is again used.) The symbolic representation of this process is: 3  A (immediate mode) A + 2  A (immediate mode) This signifies that number 3 is loaded into accA, number 2 is loaded into immediate memory, and the content of accA is added to of memory with the result being put back into accA.

EXECUTION

  1. Open THRSim11.
  2. Maximize THRSim11 window.
  3. Close the Commands window.
  4. Open file Ex2.asm.
  5. Assemble file by pressing the Assemble button. During assembly, you must have inserted in the A: floppy disk drive with the file VAR_DEF.ASM. In this way, the assembler will find the file path A:\VAR_DEF.ASM when executing the Assembly directive #INCLUDE. Else, you get error.
  1. Tile windows by pressing the ‘Tile button’.
  2. Set a break point to the line containing the opcode mnemonic SWI. To do so, select the line, right click, and chose ‘Set Breakpoint’. The line becomes amber.
  3. Change to decimal the display mode of registers A, B in the ‘CPU Registers’ window. To achieve this, right click on the line and select ‘Decimal’.
  4. Put zeros in (i.e. reset) registers D, X, Y. To achieve this, highlight the line, type in the values, and hit Enter. Unless you hit enter, the value will not take effect. (A and B get automatically reset by resetting D, since A and B are the two halves of D). Your screen should look like this: The green highlight in the A:\Ex2.LST window indicates which line of program is to be executed next. The memory address of the highlighted line, as given in the first column, is $c000. This means that the program counter (PC) at $c000. Indeed, in the CPU registers window, you can see PC $c000. The PC value indicates the memory address of the instruction to be executed next.
  5. Use the ‘Step’ button to step through the program. For the Step button to be active, you need to be in the .LST window. Hence, select the .LST window, if you have not done so already.
  1. Press the Step button again. The screen looks like this: The execution of the previous instruction has performed the addition between the contents of accA (i.e., 3) and the number kept in the immediate memory (i.e., 2). The result of the operation has been put back into accA. This means that the arithmetic operation 3 + 2 = 5 has been executed. The result of the addition is shown in the CPU registers window: the accA has become A 5, as expected. The green highlight has moved to the next line which starts at memory address $c005. (In the CPU registers window, the program counter indicates PC $c005.) The line $c005 contains the opcode mnemonic SWI which signifies the end of the program. You are done! (Do not press the ‘Step’ again, because it will throw you out of the program area.)
  2. To rerun the program, you have to place the program counter again at the beginning of the program. Select the line $c001, i.e., where the meaningful part of the program starts. Right click and select ‘Place program counter on …’. The line that was selected becomes green highlighted. You can now step again through the program and see how it operates. You can also press the ‘Run’ button , and the program will automatically execute up to the next breakpoint. In our case, the program will run all the way to the SWI instruction where the breakpoint is placed.

WHAT YOU HAVE LEARNED

In this simple exercise, you have learned quite a few things:  New words and concepts: Opcode, opcode mnemonic, immediate mode, Assembly language (.asm), list file (.LST), reset, program counter (PC), break point, registers,.  Microprocessor opcode mnemonics LDAA and ADDA  Meaning of immediate mode and how to invoke it by using the symbol #  Symbolic representation of the operations and their meaning  Open and customize THRSim11 environment  Assemble an .asm file  Interpret an .LST file

 Tile the THRSim11 windows (remember that the tiling sequence follows the sequence in which you accessed the files, with the most recently accessed window tiled in the left upper corner!)  Put a value in a memory address, e.g. when you put zeros in the registers  Set a break point  Step through the program simulation and follow the changes taking place in the ‘CPU registers’ window.  See how program execution is affecting accA. Identify the results of the calculation, i.e. 3 + 2 = 5 makes accA to show A 5.

EMCH 367 Fundamentals of Microcontrollers qkd4qd-821023-3288331-b-20example2-doc.doc