MPLAB X Project and MIPS Assembly Helps
Transcription
MPLAB X Project and MIPS Assembly Helps
MPLAB X Project and MIPS Assembly Helps How to Create a Project for CST 204 Follow the naming conventions presented here in order to organize your project accordingly. While naming and file organization can be done in other ways, consider this process a requirement. A. Folder and File naming 1) Create a z:\labs folder on the network drive. Work and deposit all of your lab work here. 2) Create a separate folder for each lab within the z:\labs folder and name them by the lab, i.e. lab1, lab2, etc. This means that the lab1 MPLAB X project will be created and have the default name z:\labs\lab1\lab1.X. 3) You will use a folder named source within the project folder to house all source files. As an example, this means that your source folder structure for the lab1 project will be z:\labs\lab1\lab1.X\source. This folder is created AFTER the Project is created, however. B. Creating the Project Using the Wizard 1) Open MPLAB X. 2) Use the File New Project… menu selection or use the 3) Make the following selections in the Wizard window: icon. 4) Make the following selections in the Wizard window: 5) Make the following selections in the Wizard window: 6) Select the latest version of the XC32 compiler in the Wizard window: 7) Enter the name of the lab, e.g. lab1, and Browse over to the z:\cst204\labs\lab1 folder. Let the Project Folder then default to the “.X” name: 8) If is suggested that you arrange the IDE windows as follows. The view includes the Project, Files, and Dashboard windows to the left, and the Output window to the lowerright. The Source file will eventually be displayed in the upper-right area where the Start Page is displayed by default. : C. Creating the “source” folder Once you have created the Project, you can use the Windows File Explorer to to create the source folder. Or, you can follow the process below. 1) Switch over to the Files window in the Project area. Right-click on the Project folder name, e.g. lab1, and make the following selection: 2) Make the following selections in the Wizard window: 3) Make the Folder Name source and let the Created Folder name default under the Project folder (.X) as shown: As mentioned above under “A. Folder and File naming”, this is where you will plave all of your source files. Memory Functions Warning: You must be aware of alignment when allocating and accessing memory. All LOADS and STORES must reference an address that is aligned to the reference type. That is, A WORD access must reference an address that is a multiple of 4 A HALFWORD access must reference an address that is a multiple of 2 A BYTE access is allowed at any address A typical error occurs when a WORD or HALFWORD access uses a label that is aligned to an ODD address. The following allocation statements are assumed to be in a .data section. 1) Create an uninitialized variable var_lab_4: var_lab_2: var_lab_1: 2) .space 4 .space 2 .space 1 // allocate 1 word this address // allocate 1 halfword at this address // allocate 1 byte at this address Create an initialized variable var_lab_4: var_lab_2: var_lab_1: .word 0x12345678 .half 0x1234 .byte 0x12 // initialize 0x12345678 at this address // initialize 0x1234 at this address // initialize 0x12 at this address The following fragments LOAD a register with an IMMEDIATE, constant value. li t0, 0x1234abcd // Load t0 with constant 0x1234abcd The following fragments perform LOADS (memory-to-register transfers) and STORES (registerto-memory transfers) in a .text section. 1) Load register t0 with a memory value using t9 (though any registers can be used) la lw 2) t9, var_label t0, 0(t9) // // // // load t9 with label address load a WORD value into t0 from address in t9. The “0” is a displacement and can be nonzero Store a register value to memory using register t9 (though any register can be used) la sw t9, var_label t0, 0(t9) // // // // load t9 store a address and can with label address WORD value in t0 into memory at in t9. The “0” is a displacement be nonzero In the fragments above, in addition to words, halfwords and bytes can also be transferred: lh lb sh sb t0, t0, t0, t0, 0(t9) 0(t9) 0(t9) 0(t9) // Or, lhu for an UNSIGNED, non-sign extended transfer // Or, lbu for an UNSIGNED, non-sign extended transfer