340 likes | 537 Views
This lab session focuses on assembly language fundamentals and interfacing with the board. Participants will learn to connect to the board, understand its architecture, and explore assembly language structure and commands. Key topics include assembler directives, compiling, and using D-Bug12 commands. We will also cover register functions, memory allocation, input/output operations, and essential assembly instructions. By the end of this session, you’ll be equipped to write and run your first assembly program.
E N D
Lab 1 – Assembly Language and Interfacing Start date: Week 3 Due date: Week 4
Agenda • Lab Objectives • Connecting to the board (review) • About the board • Assembly language structure and commands • Assembler directives • Compiling / downloading / running • D-Bug12 commands
Board Setup • Connect board to power supply • Connect to the PC through USB
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
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
About the Board • D register is 16 bits • A and B are 8-bit PARTS of the D register A B D
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
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
About the Board • Other Functionality (covered as needed in later labs) • I/O ports • A/D ports • Timers • Interrupts • Serial ports • Etc.
Assembly Language Structure • 4 fields • Label • Operation • Operand • Comment • startldaa#$03 ;load a reg
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
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
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
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
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
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
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
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
Compiler Directives • Compiler directives give instructions to the compiler • Reserve space, set memory locations etc. • Not actually executed like an instruction
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)
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
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
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
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’
Example org $1000 val0 RMB 1 three EQU $03 org $1100 start LDAA #three STAA val0 SWI
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
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”
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
D-Bug12 commands - md • md = memory display • Md <start address> (<end address>) • 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
D-Bug12 commands - mm • To modify a memory location • mm <address> <value> • Ex, you load data from a certain memory location at 800, but you want to change it without recompiling • mm 1100 40
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”
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