Unformatted text preview:

Example 1ObjectiveprogramexecutionWhat you have learnedEMCH 367 Fundamentals of Microcontrollers Example 1EXAMPLE 1OBJECTIVEThis 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 modePROGRAMEx1.asm program is very simple. It performs the arithmetic operation 3 + 2 = 5 using the ABA operationin 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 calledimmediate mode).- Load the number 2 into accB using the opcode mnemonic LDAB with operand #2, i.e., usingimmediate mode- Add the number in accA (i.e., 3) with the number in accB (i.e., 2) using the opcode mnemonicABA 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 accAis added to the content of accB with the result being put back into accA.EXECUTION1. Open THRSim11.2. Maximize THRSim11 window.3. Close the Commands window.4. Open file Ex1.asm.Dr. Victor Giurgiutiu Page 1 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 15. Assemble file by pressing the Assemble button. During assembly, you must have inserted in the A: floppy disk drive the floppy disk with the fileVAR_DEF.ASM. In this way, the assembler will find the file path A:\VAR_DEF.ASM whenexecuting the Assembly directive #INCLUDE. Else, you get error.6. Tile windows by pressing the ‘Tile button’. 7. 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.8. Change to decimal the display mode of registers A, B in the ‘CPU Registers’ window. Toachieve this, right click on the line and select ‘Decimal’.9. 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, thevalue will not take effect. (A and B get automatically reset by resetting D, since A and B are thetwo 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 meansthat 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. 10. 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 .LSTwindow, if you have not done so already.Dr. Victor Giurgiutiu Page 2 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 1Press the Step button once. Your screen should look like this: The green highlight moves to the next line, which starts at address $c001. The program counterin the CPU registers window is PC $c001.The line $c001 performs the loading of number 3 into accA. This line has not been executed yet.It will be executed next when the Step button is pressed. 11. Press the Step button again. Your screen should look like this: Dr. Victor Giurgiutiu Page 3 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 1The green highlight has moved to the next line, starting at address $c003. It has jumped by 2counts 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 moveforward by 2 locations. The current value of the program counter is PC $c003, as can be readilyverified in the CPU registers window. The result of executing the previous instruction is now apparent. The number 3 has been loadedinto accA. You can verify this by noting that, in the CPU registers window, you see A 3.12. 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 number3 was loaded into accA. The result of this operation is apparent in the CPU registers windowwhere now we can see B 2.13. Press the Step button again. The screen looks like this:Dr. Victor Giurgiutiu Page 4 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example 1The execution of the previous instruction has performed the addition between the contents ofaccA (i.e., 3) and the contents of accB (i.e., 2). The result of the operation has been put backinto accA. This means that the arithmetic operation 3 + 2 = 5 has been executed. The result ofthe 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 theCPU registers window, the program counter indicates PC $c006.) The move of the programcounter was only by one memory location because the operation ABA just executed does nothave operand (inherent mode), and only requires one Opcode.The line $c006 contains the opcode mnemonic SWI which signifies the end of the program. Youare done! (Do not press the ‘Step’ again, because it will throw you out of the program area.)14. To rerun the program, you have to place the program counter again at the beginning of theprogram. Select the line $c001, i.e., where the meaningful part of the program starts. Right clickand select ‘Place program counter on …’. The line that was selected becomes greenhighlighted. You can now step again through the program and see how it operates. You can alsopress the ‘Run’ button , and the program will automatically execute up to the nextbreakpoint. In our case, the program will run all the way to the SWI instruction where thebreakpoint is placed.WHAT YOU HAVE


View Full Document

SC EMCH 367 - EMCH 367 Example 1

Download EMCH 367 Example 1
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 Example 1 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 Example 1 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?