Download presentation
Presentation is loading. Please wait.
Published byDerek Goodman Modified over 9 years ago
1
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4 1
2
Agenda Lab Objectives Connecting to the board (review) About the board Assembly language structure and commands Assembler directives Compiling / downloading / running D-Bug12 commands 2
3
Board Setup Connect board to power supply Connect to the PC through USB 3
4
Connecting Open MiniIDE Compiler options (terminal options) COM(X) 9600 baud rate Ensure compiler is asm12.exe in assembler tab Terminal connected Ensure you have a terminal (terminal show terminal window) Press the reset button on the board You should see a D-Bug12 message 4
5
About the board CISC – many instructions (we will only go over a few, there are many outlined in the text or in the manual) A, B and D registers are the main registers for instructions X and Y registers can be used for instructions or addressing 5
6
About the Board D register is 16 bits A and B are 8-bit PARTS of the D register AB D 6
7
About the Board X and Y are both 16 bits X and Y can also be used for addressing Covered later in class when you talk about addressing modes 7
8
About the board Memory There are only certain areas in memory that you can use These areas can be used for data or code There are commands to load from and store to RAM 8
9
About the Board Other Functionality (covered as needed in later labs) I/O ports A/D ports Timers Interrupts Serial ports Etc. 9
10
Assembly Language Structure 4 fields Label Operation Operand Comment start ldaa #$03 ;load a reg 10
11
Assembly Language Structure Label Used to mark a certain part of the code Useful when doing branches / jumps Can use them almost like a GOTO You make them up, so can be any word you want Labels are optional, use where needed start ldaa #$03 ;load A reg 11
12
Assembly Language Structure Operation Describes the operation you want to do Many operations available because CISC Ex. Add, subtract, or, load, store, branch start ldaa #$03 ;load A reg 12
13
Assembly Language Structure Operand Describes what you want to do the operation to Manual will tell you what operands you need with what operations #$03 = immediate, $03 = direct $=hex, %=binary, nothing = decimal start ldaa #$03 ;load A reg 13
14
Assembly Language Structure Comment Start with a semi-colon for comment to end of line Very helpful in assembly code because it can be hard to understand start ldaa #$03 ;load A reg 14
15
Assembly Instructions - load LDAA, LDAB, LDD, LDX, LDY Load a register with a value Syntax: (label) LDAA value LDAA #$30 = load register A with the value $30 LDAA $30 = load register A with the value held in memory location $30 15
16
Assembly Instructions - store STAA, STAB, STD, STX, STY Store the value in a register to a memory location Syntax: (label) STAA memory_location STAA $30 = store the value in register A to memory location $30 16
17
Assembly Instructions - Add Ex. ADDA, ADDB, ADDD, ABA More in manual ADDA, ADDB = add 8-bit operand to register A or B (label) ADDA $30 = add the value in memory location $30 to A, and store in A (label) ADDA #$30 = add the value $30 to A and store in A ADDD = add 16-bit operand to register D ABA = add registers A and B and store in A 17
18
Assembly Instructions - SWI SWI stands for software interrupt Use it to end your programs and to get back out to the D-Bug12 prompt No operand 18
19
Compiler Directives Compiler directives give instructions to the compiler Reserve space, set memory locations etc. Not actually executed like an instruction 19
20
Compiler Directives - org Org is used to tell the compiler where to put the program in memory Unlike high level languages, where the program gets put anywhere it fits, in assembly you have to tell the compiler where to start putting the program You can have multiple orgs in a program, ex to separate space for data and for the program (try not to have too many though) 20
21
Compiler Directives – org con’t There are only certain areas on the board your can use for your program/data A memory map of the system shows where you can put your code/data See appendix You have from $1000 to $4000 $1000 is good for the program because it is big Ex. org $1000 21
22
Compiler Directives - RMB RMB stands for reserve memory byte Operand is the number of bytes to reserve You can then use these to store data If they are labelled you can refer to them by the label (label) RMB 2 22
23
Compiler Directives - EQU EQU = equate Like C #define Compiler will go through and substitute before the code is compiled Requires a label to use label EQU $30 23
24
Compiler Directives - other BSZ = block set zero Like RMB, but fills the blocks with 0’s FCB = form constant byte Stores values specified in memory (label) FCB $30 (label) FCB 30, $40, ‘a’ FDB = form double byte Same as FCB, but 16 bits FCC = form constant character (label) FCC ‘hello world’ 24
25
Example org $1000 val0RMB1 threeEQU$03 org$1100 startLDAA#three STAAval0 SWI 25
26
Compiling Save as “whatever.asm” you have to type the “.asm” part too Press the build button Check the output window for errors and warnings 26
27
Downloading and Running To load: Type “load” at the prompt Click the download button Select your s-record file (.s19) To run Figure out where your program starts (your probably used an ORG right before, so wherever you ORG’d to) ex. At $1100…type “g 1100” 27
28
D-Bug12 commands Once your program has exited, you can use D-Bug12 to analyze the output Important ones: load g md mm rd Others in Lab 0 28
29
D-Bug12 commands - md md = memory display Md ( ) Shows the contents of memory starting at the start address Ex, you ORG’d at $1000 and then used RMB to store some data. To see it, type: md 1000 29
30
D-Bug12 commands - mm To modify a memory location mm Ex, you load data from a certain memory location at 800, but you want to change it without recompiling mm 1100 40 30
31
D-Bug12 commands - RD rd = register display Use it to see the contents of all the user registers, flags, stack points and PC No operands, just “rd” 31
32
Academic Misconduct Reports and demos are submitted as a group, but it is a SINGLE group effort You may talk with other groups but sharing code or reports is NOT ALLOWED Copying code/reports from previous years is also NOT ALLOWED If we find copying we are REQUIRED to report it 32
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.