E&CE 222
Lab Tutorial 1
Hand Assembling
Prepared by: Peter Tysowski, T.A.
E-mail:
[email protected] May 18, 2010
Spring 2010 term
1
Lab 1 Tutorial Outline
Objectives of Lab 1
Program Operation and Loading
Explanation of I/O Subroutines
Modifying the Code
Hand Assembling Operation
Post Lab Subroutines
Deliverables and Marking Scheme
2
Objectives of Lab 1
Familiarize yourself with hand assembly of
Motorola 68000 instructions (ISA_A)
Familiarize with simple instructions
e.g. and, bsr, cmp, jmp, jsr, lea, move, rts, suba, trap
Use different Effective Addressing modes
Absolute, Immediate, Register Direct, Register Indirect
Perform offset calculations
e.g. beq, bne, bra
3
Objectives of Lab 1
Use common assembler directives
e.g. equ, org, dc
Handle monitor operations
Trap #15 vectors
Familiarize with input/output operations
4
Program Operation
Print message asking for input
Call “Read String” subroutine
Read input characters into buffer
Allocate a second buffer
Reverse the string into the second buffer
Call “Output String” subroutine
Exit to the Monitor
5
I/O Subroutines
Out-Character
Store parameter D0 on the stack
Output the register D1 (in ASCII)
Restore D0 from the stack
In-Character
Store parameter D0 on the stack
Capture the input into D1 (in ASCII)
Select the first byte
Display the character
Restore D0 from the stack 6
Modify the Program
lea BUFFER,A1 ;point to start of buffer
bsr.w in_string ;read string and
bsr.w out_crlf ;go to next line
* Scan for end of string.
move.l #BUFFER,A0 ;point to start of buffer
bloop1 tst.b (A0)+ ;see if we found the NULL yet.
bne bloop1 ;nope, keep looping
suba.l #1,A0 ;ignore the NULL
Hand assemble
movea.l #BUFFER+1024,A2 ;set up another buffer for result
Insert the necessary instructions
here - approximately 5 lines.
bsr.w out_string ;print the string
bsr.w out_crlf ;and go to new line
* Exit
move.l #$0000,d0
TRAP #15 7
end ;optional, marking end of assembly
Program Operation
Reverse string order Buffer L A1
Determines end of the string A
B
Defines new buffer
1
Stores the reversed string in new buffer
A0 NULL
Displays the reversed string
Buffer + 1024
1 A2
B
8
Program Loading
Using Motorola S-record Format
Produced by assemblers and compilers
Encapsulates opcodes with addresses and checksums
Using Text File (for Lab 1)
Load the program through the terminal using text files
(OPCODES.txt)
9
OPCODES.TXT
mm 10210000
5468
6973
2070
726f
6772
616d
2077
696c
6c20
7072
696e
7420
6f75
7420
6120
7374
7269
6e67
2069
6e20
7468
6520 10
…etc
Hand Assembling of “Move”
Move.L #100,D2
0 0 1 0 0 1 0 0 0 0 1 1 1 1 0 0
Size Field
– 00 Byte Operation
– 01 Word Operation
– 10 Long Word Operation
– 11 Reserved
11
Hand Assembling (Move)
Translate: Move.L #100,D2
0010 0100 0011 1100 0000 0064
2 4 3 C 0000 0064
Enter code:
mm.w
10200000
243c
0
64 12
During Your Lab
Download the codes to the board
Manually add on the rest of the program
Enter your hand-assembled program
(including the new instructions required to complete it)
Run the program
Debugging techniques: breakpoint, trace, disassemble
Test the program
Print out the reverse of the input string
Finish assembly and test before demo day
13
Post Lab Subroutines
DEC2BIN
Converts a decimal ASCII string to a binary number
Reads null-terminated string from A1 (doesn’t modify A1)
Converts ASCII bytes to decimal using Horner’s equation
Decimal: 3210 = (((3) * 10 + 2) * 10 + 1) * 10 + 0
Store result in D1
Write as subroutine (save registers to stack, use rts)
Hint: use a loop, multiply instruction, and accumulator
Hint: use data registers to hold temporary values
14
No error checking on input required
Post Lab Subroutines
BIN2DEC
Converts binary number to decimal ASCII string
Reads word-sized binary number from D1 (doesn’t modify it)
Writes null-terminated string at location in A2
Horner’s equation requires a divide subroutine
Hex: 3210 = (((3) * A + 2) * A + 1) * A + 0
Size is 16-bit positive number (one word)
No error checking on input required
Hint: use division and remainder instructions in loop 1
15
Hint: output the decimal string then reverse it in loop 2
Post Lab Subroutines
Decimal ASCII String Binary Number
(stored in Big Endian)
6980 0x36
0x39 0x1B44
0x38
0x30
16 bit positive number ranges from 0x0000 to 0xFFFF
or
0 to 65535
16
Deliverables
The Grade Form
Access from ACE and print it for the lab
Code for string-reverse program
Full machine code listing (original program + additions)
Lines added in assembly code, with comments
Post-lab: DEC2BIN and BIN2DEC subroutines
In assembly language, with comments
No hand assembly required
17
Marking Scheme
LAB demo
3 marks – Lab completion (program must work 100%)
2 marks – Questions answered during lab demo
Individual mark
May be asked about the program and/or asked to hand assemble
Post lab
2 marks per subroutine (DEC2BIN & BIN2DEC)
Final Reports due 48 hours after demo, on ACE
20% late penalty per day
18
Marking Scheme
19
20
21
22
23