View
220
Download
1
Category
Tags:
Preview:
Citation preview
Lab 1 – Assembly Language and Interfacing
Start date: Week 3Due date: Week 4
1
Agenda
Lab ObjectivesConnecting to the board (review)About the boardAssembly language structure and commandsAssembler directivesCompiling / downloading / runningD-Bug12 commands
2
Board Setup
Connect board to power supplyConnect to the PC through USB
3
Connecting
Open MiniIDECompiler options (terminal options) COM(X) 9600 baud rate Ensure compiler is asm12.exe in assembler tab
Terminal connectedEnsure you have a terminal (terminal show terminal window)Press the reset button on the boardYou should see a D-Bug12 message
4
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 instructionsX and Y registers can be used for instructions or addressing
5
About the Board
D register is 16 bitsA and B are 8-bit PARTS of the D register
A B
D
6
About the Board
X and Y are both 16 bitsX and Y can also be used for addressing Covered later in class when you talk
about addressing modes
7
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
About the Board
Other Functionality (covered as needed in later labs) I/O ports A/D ports Timers Interrupts Serial ports Etc.
9
Assembly Language Structure
4 fields Label Operation Operand Comment
start ldaa #$03 ;load a reg
10
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
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
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
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
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
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
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 DABA = add registers A and B and store in A
17
Assembly Instructions - SWI
SWI stands for software interruptUse it to end your programs and to get back out to the D-Bug12 promptNo operand
18
Compiler Directives
Compiler directives give instructions to the compilerReserve space, set memory locations etc.Not actually executed like an instruction
19
Compiler Directives - org
Org is used to tell the compiler where to put the program in memoryUnlike high level languages, where the program gets put anywhere it fits, in assembly you have to tell the compiler where to start putting the programYou 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
Compiler Directives – org con’t
There are only certain areas on the board your can use for your program/dataA 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
Compiler Directives - RMB
RMB stands for reserve memory byteOperand is the number of bytes to reserveYou can then use these to store dataIf they are labelled you can refer to them by the label(label) RMB 2
22
Compiler Directives - EQU
EQU = equateLike C #defineCompiler will go through and substitute before the code is compiledRequires a label to uselabel EQU $30
23
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
Example
org $1000
val0 RMB 1
three EQU $03
org $1100
start LDAA #three
STAA val0
SWI
25
Compiling
Save as “whatever.asm” you have to type the “.asm” part too
Press the build buttonCheck the output window for errors and warnings
26
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
D-Bug12 commands
Once your program has exited, you can use D-Bug12 to analyze the outputImportant ones: load g md mm rd
Others in Lab 0
28
D-Bug12 commands - md
md = memory displayMd <start address> (<end address>)Shows the contents of memory starting at the start addressEx, you ORG’d at $1000 and then used RMB to store some data. To see it, type:md 1000
29
D-Bug12 commands - mm
To modify a memory locationmm <address> <value>
Ex, you load data from a certain memory location at 800, but you want to change it without recompilingmm 1100 40
30
D-Bug12 commands - RD
rd = register displayUse it to see the contents of all the user registers, flags, stack points and PCNo operands, just “rd”
31
Academic Misconduct
Reports and demos are submitted as a group, but it is a SINGLE group effortYou may talk with other groups but sharing code or reports is NOT ALLOWEDCopying code/reports from previous years is also NOT ALLOWEDIf we find copying we are REQUIRED to report it
32
Recommended