Microcontroller Fundamentals: Simple THRSim11 Example with Assembly - Prof. V. Giurgiutiu, Study notes of Mechanical Engineering

A step-by-step guide on using the thrsim11 simulator to understand the basics of microcontrollers through a simple example written in assembly language. The example demonstrates loading numbers into accumulators, performing arithmetic operations, and interpreting the list (.lst) file. Users will learn about immediate and inherent addressing modes, opcodes, and microcontroller registers.

Typology: Study notes

Pre 2010

Uploaded on 10/01/2009

koofers-user-zxw-1
koofers-user-zxw-1 🇺🇸

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 1
EXAMPLE 1
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 the LDAA, LDAB and ABA operations
Introduce immediate addressing mode
Introduce inherent addressing mode
PROGRAM
Ex1.asm program is very simple. It performs the arithmetic operation 3 + 2 = 5 using the ABA 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 operand #3. The symbol #
signifies that the number 3 is used immediately. For this reason, this mode of operation is called
immediate mode).
Load the number 2 into accB using the opcode mnemonic LDAB with operand #2, i.e., using
immediate mode
Add the number in accA (i.e., 3) with the number in accB (i.e., 2) using the opcode mnemonic
ABA and no operand. This mode, which uses no operant, is called inherent mode.
The symbolic representation of this process is:
3 A (immediate mode)
2 B (immediate mode)
A + B A (inherent mode)
This signifies that number 3 is loaded into accA, number 2 is loaded into accB, and the content of accA
is added to the content of accB with the result being put back into accA.
EXECUTION
1. Open THRSim11.
2. Maximize THRSim11 window.
3. Close the Commands window.
4. Open file Ex1.asm.
Dr. Victor Giurgiutiu Page 1 11/30/2020
pf3
pf4
pf5

Partial preview of the text

Download Microcontroller Fundamentals: Simple THRSim11 Example with Assembly - Prof. V. Giurgiutiu and more Study notes Mechanical Engineering in PDF only on Docsity!

EXAMPLE 1

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 the LDAA, LDAB and ABA operations  Introduce immediate addressing mode  Introduce inherent addressing mode

PROGRAM

Ex1.asm program is very simple. It performs the arithmetic operation 3 + 2 = 5 using the ABA 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 operand #3. The symbol # signifies that the number 3 is used immediately. For this reason, this mode of operation is called immediate mode ).  Load the number 2 into accB using the opcode mnemonic LDAB with operand #2, i.e., using immediate mode  Add the number in accA (i.e., 3) with the number in accB (i.e., 2) using the opcode mnemonic ABA and no operand. This mode, which uses no operant, is called inherent mode. The symbolic representation of this process is: 3  A (immediate mode) 2  B (immediate mode) A + B  A (inherent mode) This signifies that number 3 is loaded into accA, number 2 is loaded into accB, and the content of accA is added to the content of accB with the result being put back into accA.

EXECUTION

  1. Open THRSim11.
  2. Maximize THRSim11 window.
  3. Close the Commands window.
  4. Open file Ex1.asm.
  1. Assemble file by pressing the Assemble button. During assembly, you must have inserted in the A: floppy disk drive the floppy disk 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.
  2. Tile windows by pressing the ‘Tile button’.
  3. 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.
  4. 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’.
  5. 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 .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.
  6. 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.

The green highlight has moved to the next line, starting at address $c003. It has jumped by 2 counts because the line that has just been executed had to Opcodes (i.e., machine instructions) in it, 86 and 03. Each Opcode takes up one memory address, hence the program has move forward by 2 locations. The current value of the program counter is PC $c003, as can be readily verified in the CPU registers window. The result of executing the previous instruction is now apparent. The number 3 has been loaded into accA. You can verify this by noting that, in the CPU registers window, you see A 3.

  1. Press the Step button again. The screen looks like this: The execution of the previous instruction has loaded the number 2 into accB, just as the number 3 was loaded into accA. The result of this operation is apparent in the CPU registers window where now we can see B 2.
  2. 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 contents of accB (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 $c006. (In the CPU registers window, the program counter indicates PC $c006.) The move of the program counter was only by one memory location because the operation ABA just executed does not have operand (inherent mode), and only requires one Opcode. The line $c006 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.)

  1. 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, LDAB, and ABA.  Meaning of immediate mode and how to invoke it by using the symbol #  Meaning of inherent mode.